Skip to content

Commit b37840a

Browse files
authored
Code hilite (#84)
* Remove limitation Let's blindly trust the directory as images ;) * All site urls for sitemap. Closes #58 - Icon repository - Not found bug fix for article * Fixes code hilite. - Add markdown hilite extension. - Add pymdownx.superfences for nested code blocks. - Updated hello_world.md - Updated missed-articles - Closes #76 * Update snapshots
1 parent ba04574 commit b37840a

File tree

8 files changed

+100
-7
lines changed

8 files changed

+100
-7
lines changed

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Pillow==9.2.0
1818
pluggy==1.0.0
1919
py==1.11.0
2020
pycparser==2.21
21+
Pygments==2.13.0
22+
pymdown-extensions==9.5
2123
pyparsing==3.0.9
2224
pypugjs==5.9.11
2325
pytest==7.1.2

tests/snapshots/goodbye-cruel-world.snapshot.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ <h2 id="heroic-engineering">
593593
</del>
594594
stakeholders.
595595
</p>
596-
<pre><code>Hello Mr. Fancy Manager,
596+
<div class="highlight">
597+
<pre><span></span><code>Hello Mr. Fancy Manager,
597598

598599
I am pleased to supply you with features maintained in the new version of the site.
599600

@@ -603,6 +604,7 @@ <h2 id="heroic-engineering">
603604

604605
The engineer
605606
</code></pre>
607+
</div>
606608
<p>
607609
The engineer's written proof reassured the
608610
<del>

tests/snapshots/hello-world.snapshot.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,23 @@ <h2 id="first-program">
8888
</code>
8989
:
9090
</p>
91-
<pre><code class="language-python">print('Hello World!')
91+
<div class="codehilite highlight">
92+
<table class="highlighttable">
93+
<tr>
94+
<td class="linenos">
95+
<div class="linenodiv">
96+
<pre><span></span><span class="normal">1</span></pre>
97+
</div>
98+
</td>
99+
<td class="code">
100+
<div>
101+
<pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="s1">'Hello World!'</span><span class="p">)</span>
92102
</code></pre>
103+
</div>
104+
</td>
105+
</tr>
106+
</table>
107+
</div>
93108
<p>
94109
Save your work, and close the text editor. Open up a terminal application like Powershell on Windows or bash on Ubuntu. If you're on Windows, it is as easy as hitting your Windows Key and searching for
95110
<code>

website/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def article(year: int, month: int, day: int, description: str) -> str:
161161
date=post.date.strftime('%d %B %Y'),
162162
content=markdown.markdown(
163163
post.content,
164-
extensions=['fenced_code', 'toc', 'tables'],
164+
extensions=['pymdownx.superfences', 'toc', 'tables', 'codehilite'],
165165
)
166166
)
167167

website/blog/2020/hello_world.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This example will be using the programming language [Python](https://www.python.
1616

1717
Writing and executing a simple "Hello World" program is fairly simple. Most languages require you to tell the computer using a specific command that you would like to output some characters, in this case, "Hello World," to the screen. The ```print``` command allows us to output some text to the screen. Please note that we don't always output the screen (the terminal), and in the past, we've output to a physical printer or similar device. Using your preferred text editor, write the following in a new file named ```hello_world.py```:
1818

19-
```python
19+
```{.python .codehilite linenums="1"}
2020
print('Hello World!')
2121
```
2222

website/blog/2022/missed-article-titles.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ Blocks, such as the title, can be overridden in the layout. The `block` tag acce
2020

2121
The default looks like this:
2222

23-
```pugjs
23+
```{.pugjs .codehilite linenums="1"}
2424
block title
2525
title Engineer, Researcher, Entrepreneur - Johnathan Irvin
2626
```
2727

2828
The layout contains the default title. I overrode the block in the `article.pug` file.
2929

30-
```
31-
pugjs
30+
```{.pugjs .codehilite linenums="1"}
3231
block title
3332
title {{ title }} - Johnathan Irvin
3433
```

website/static/css/hilite.css

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
pre { line-height: 125%; }
2+
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
3+
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
4+
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
5+
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
6+
.codehilite .hll { background-color: #ffffcc }
7+
.codehilite { background: #f8f8f8; }
8+
.codehilite .c { color: #3D7B7B; font-style: italic } /* Comment */
9+
.codehilite .err { border: 1px solid #FF0000 } /* Error */
10+
.codehilite .k { color: #008000; font-weight: bold } /* Keyword */
11+
.codehilite .o { color: #666666 } /* Operator */
12+
.codehilite .ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */
13+
.codehilite .cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */
14+
.codehilite .cp { color: #9C6500 } /* Comment.Preproc */
15+
.codehilite .cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */
16+
.codehilite .c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */
17+
.codehilite .cs { color: #3D7B7B; font-style: italic } /* Comment.Special */
18+
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
19+
.codehilite .ge { font-style: italic } /* Generic.Emph */
20+
.codehilite .gr { color: #E40000 } /* Generic.Error */
21+
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
22+
.codehilite .gi { color: #008400 } /* Generic.Inserted */
23+
.codehilite .go { color: #717171 } /* Generic.Output */
24+
.codehilite .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
25+
.codehilite .gs { font-weight: bold } /* Generic.Strong */
26+
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
27+
.codehilite .gt { color: #0044DD } /* Generic.Traceback */
28+
.codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
29+
.codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
30+
.codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
31+
.codehilite .kp { color: #008000 } /* Keyword.Pseudo */
32+
.codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
33+
.codehilite .kt { color: #B00040 } /* Keyword.Type */
34+
.codehilite .m { color: #666666 } /* Literal.Number */
35+
.codehilite .s { color: #BA2121 } /* Literal.String */
36+
.codehilite .na { color: #687822 } /* Name.Attribute */
37+
.codehilite .nb { color: #008000 } /* Name.Builtin */
38+
.codehilite .nc { color: #0000FF; font-weight: bold } /* Name.Class */
39+
.codehilite .no { color: #880000 } /* Name.Constant */
40+
.codehilite .nd { color: #AA22FF } /* Name.Decorator */
41+
.codehilite .ni { color: #717171; font-weight: bold } /* Name.Entity */
42+
.codehilite .ne { color: #CB3F38; font-weight: bold } /* Name.Exception */
43+
.codehilite .nf { color: #0000FF } /* Name.Function */
44+
.codehilite .nl { color: #767600 } /* Name.Label */
45+
.codehilite .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
46+
.codehilite .nt { color: #008000; font-weight: bold } /* Name.Tag */
47+
.codehilite .nv { color: #19177C } /* Name.Variable */
48+
.codehilite .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
49+
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
50+
.codehilite .mb { color: #666666 } /* Literal.Number.Bin */
51+
.codehilite .mf { color: #666666 } /* Literal.Number.Float */
52+
.codehilite .mh { color: #666666 } /* Literal.Number.Hex */
53+
.codehilite .mi { color: #666666 } /* Literal.Number.Integer */
54+
.codehilite .mo { color: #666666 } /* Literal.Number.Oct */
55+
.codehilite .sa { color: #BA2121 } /* Literal.String.Affix */
56+
.codehilite .sb { color: #BA2121 } /* Literal.String.Backtick */
57+
.codehilite .sc { color: #BA2121 } /* Literal.String.Char */
58+
.codehilite .dl { color: #BA2121 } /* Literal.String.Delimiter */
59+
.codehilite .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
60+
.codehilite .s2 { color: #BA2121 } /* Literal.String.Double */
61+
.codehilite .se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */
62+
.codehilite .sh { color: #BA2121 } /* Literal.String.Heredoc */
63+
.codehilite .si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */
64+
.codehilite .sx { color: #008000 } /* Literal.String.Other */
65+
.codehilite .sr { color: #A45A77 } /* Literal.String.Regex */
66+
.codehilite .s1 { color: #BA2121 } /* Literal.String.Single */
67+
.codehilite .ss { color: #19177C } /* Literal.String.Symbol */
68+
.codehilite .bp { color: #008000 } /* Name.Builtin.Pseudo */
69+
.codehilite .fm { color: #0000FF } /* Name.Function.Magic */
70+
.codehilite .vc { color: #19177C } /* Name.Variable.Class */
71+
.codehilite .vg { color: #19177C } /* Name.Variable.Global */
72+
.codehilite .vi { color: #19177C } /* Name.Variable.Instance */
73+
.codehilite .vm { color: #19177C } /* Name.Variable.Magic */
74+
.codehilite .il { color: #666666 } /* Literal.Number.Integer.Long */

website/templates/article.pug

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ block title
55

66
block styles
77
link(href="{{ url_for('static', filename='css/article.css') }}", rel="stylesheet")
8+
link(href="{{ url_for('static', filename='css/hilite.css') }}", rel="stylesheet")
89

910
block content
1011
h1.post-title.h1 {{title}}

0 commit comments

Comments
 (0)