Skip to content

Commit 887cf22

Browse files
committed
added code highlighting
1 parent e92b57f commit 887cf22

File tree

6 files changed

+72
-23
lines changed

6 files changed

+72
-23
lines changed

assets/css/ascetic.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
3+
Original style from softwaremaniacs.org (c) Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
4+
5+
*/
6+
7+
.hljs {
8+
display: block;
9+
overflow-x: auto;
10+
padding: 0.5em;
11+
background: white;
12+
color: black;
13+
}
14+
15+
.hljs-string,
16+
.hljs-variable,
17+
.hljs-template-variable,
18+
.hljs-symbol,
19+
.hljs-bullet,
20+
.hljs-section,
21+
.hljs-addition,
22+
.hljs-attribute,
23+
.hljs-link {
24+
color: #555;
25+
}
26+
27+
.hljs-comment,
28+
.hljs-quote,
29+
.hljs-meta,
30+
.hljs-deletion {
31+
color: #999;
32+
}
33+
34+
.hljs-keyword,
35+
.hljs-selector-tag,
36+
.hljs-section,
37+
.hljs-name,
38+
.hljs-type,
39+
.hljs-strong {
40+
font-weight: bold;
41+
}
42+
43+
.hljs-emphasis {
44+
font-style: italic;
45+
}

assets/css/style.css

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ h2, h3, h4, h5, h6 {
125125
font-size: 1rem;
126126
display: block;
127127
margin-top: 2rem;
128+
margin-bottom: 1rem;
128129
}
129130

130131
hr {
@@ -143,14 +144,23 @@ pre {
143144
pre code {
144145
counter-increment: line;
145146
display: block;
147+
background-color: rgb(238, 238, 238) !important
146148
}
147-
pre code:before {
148-
margin-right: 0.5rem;
149-
min-width: 18px;
150-
display: inline-block;
151-
text-align: left;
152-
content: counter(line);
149+
150+
.hljs-ln-numbers {
151+
-webkit-touch-callout: none;
152+
-webkit-user-select: none;
153+
-khtml-user-select: none;
154+
-moz-user-select: none;
155+
-ms-user-select: none;
156+
user-select: none;
157+
158+
text-align: center;
159+
color: #999;
160+
vertical-align: top;
161+
padding-right: 1rem !important;
153162
}
163+
154164
code, pre {
155165
font-family: 'Iosevka Web', monospace;
156166
}

assets/js/highlight.pack.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/highlightjs-line-numbers.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/script.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
function main() {
22
// code
3-
document.querySelectorAll('pre').forEach(pre => {
4-
const code = pre.querySelector('code')
5-
if (code) {
6-
const frag = document.createDocumentFragment()
7-
const lines = code.innerHTML.trim().split('\n')
8-
lines.forEach(line => {
9-
const el = document.createElement('code')
10-
el.innerHTML = line
11-
frag.append(el)
12-
})
13-
pre.removeChild(code)
14-
pre.appendChild(frag)
15-
}
3+
document.querySelectorAll('pre code').forEach(block => {
4+
hljs.highlightBlock(block)
5+
hljs.lineNumbersBlock(block)
166
})
177

188
// math
19-
renderMathInElement(document.body);
9+
renderMathInElement(document.body)
2010
}
2111

2212
if (document.readyState === "loading") {

src/Lib/Server/Template.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ instance ToHtml a => ToHtml (Template a) where
3232
let description = case descriptionM of
3333
Nothing -> "unsafePerformIO is the blog and personal website of Wilfred Denton."
3434
Just description' -> description'
35-
assetVer = "2"
35+
assetVer = "3"
3636
title_ $ toHtml title
3737
meta_ [charset_ "utf-8"]
3838
meta_ [name_ "description", content_ description]
@@ -55,8 +55,11 @@ instance ToHtml a => ToHtml (Template a) where
5555
link_ [rel_ "stylesheet", type_ "text/css", href_ $ "/static/css/style.css?=" <> assetVer]
5656
link_ [rel_ "stylesheet", type_ "text/css", href_ "/static/css/bootstrap-grid.min.css"]
5757
link_ [rel_ "stylesheet", type_ "text/css", href_ "/static/katex/katex.min.css"]
58+
link_ [rel_ "stylesheet", type_ "text/css", href_ "/static/css/ascetic.css"]
5859
script_ [src_ "/static/katex/katex.min.js"] ("" :: Text)
5960
script_ [src_ "/static/katex/auto-render.min.js"] ("" :: Text)
61+
script_ [src_ "/static/js/highlight.pack.js"] ("" :: Text)
62+
script_ [src_ "/static/js/highlightjs-line-numbers.min.js"] ("" :: Text)
6063
script_ [src_ $ "/static/js/script.js?=" <> assetVer, async_ "true"] ("" :: Text)
6164
script_ [src_ "https://www.googletagmanager.com/gtag/js?id=UA-131857401-1", async_ "true"] ("" :: Text)
6265
script_ "window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-131857401-1');"

0 commit comments

Comments
 (0)