Skip to content

Commit 5ac491d

Browse files
committed
Revert "Merge pull request #12 from Syrup/fix/clean-urls-and-code-labels"
This reverts commit b5bf95d, reversing changes made to 122d323.
1 parent b5bf95d commit 5ac491d

5 files changed

Lines changed: 23 additions & 61 deletions

File tree

cli/build.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,30 @@ import { readFileSync, writeFileSync, readdirSync, existsSync, rmSync, mkdirSync
22
import { join, dirname } from 'node:path';
33
import { glob } from 'glob';
44
import frontMatter from 'front-matter';
5+
import hljs from 'highlight.js';
56
import Handlebars from 'handlebars';
67
import ejs from 'ejs';
78
import MarkdownIt from 'markdown-it';
89
import markdownItTaskLists from 'markdown-it-task-lists';
910
import markdownItEmoji from 'markdown-it-emoji/light.js';
1011
import markdownItAlerts from '../helpers/markdown-it-alerts.js';
11-
import { highlightCode } from '../helpers/highlight.js';
1212
import { parse as parseToml } from 'toml';
1313
import '../helpers/index.js';
1414

1515
const configFile = readFileSync(join(process.cwd(), 'config.toml'), 'utf8');
1616
const config = parseToml(configFile);
1717

1818
const md = new MarkdownIt({
19-
highlight: highlightCode,
19+
highlight: function (str, lang) {
20+
if (lang && hljs.getLanguage(lang)) {
21+
try {
22+
return '<pre class="hljs"><code>' +
23+
hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
24+
'</code></pre>';
25+
} catch (__) {}
26+
}
27+
return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
28+
},
2029
html: true
2130
});
2231

helpers/highlight.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { readFileSync } from 'node:fs';
33
import { join } from 'node:path';
44
import { glob } from 'glob';
55
import frontMatter from 'front-matter';
6+
import hljs from 'highlight.js';
67
import express from 'express';
78
import Handlebars from 'handlebars';
89
import MarkdownIt from 'markdown-it';
910
import markdownItTaskLists from 'markdown-it-task-lists';
1011
import markdownItEmoji from 'markdown-it-emoji/light.js';
1112
import markdownItAlerts from './helpers/markdown-it-alerts.js';
12-
import { highlightCode } from './helpers/highlight.js';
1313
import { parse as parseToml } from 'toml';
1414
import './helpers/index.js';
1515

@@ -24,7 +24,16 @@ const config = parseToml(configFile);
2424

2525
// Setup markdown-it
2626
const md = new MarkdownIt({
27-
highlight: highlightCode,
27+
highlight: function (str, lang) {
28+
if (lang && hljs.getLanguage(lang)) {
29+
try {
30+
return '<pre class="hljs"><code>' +
31+
hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
32+
'</code></pre>';
33+
} catch (__) {}
34+
}
35+
return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
36+
},
2837
html: true
2938
});
3039

public/style.css

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,6 @@ pre.hljs {
5151
position: relative;
5252
}
5353

54-
pre.hljs code {
55-
display: block;
56-
position: relative;
57-
}
58-
59-
pre.hljs .code-lang {
60-
position: sticky;
61-
top: 0;
62-
left: 0;
63-
float: left;
64-
background-color: transparent;
65-
color: #888;
66-
padding: 2px 6px;
67-
font-size: 9px;
68-
font-family: 'Courier New', monospace;
69-
font-weight: 600;
70-
line-height: 1;
71-
text-transform: none;
72-
border-top-left-radius: 2px;
73-
border-bottom-right-radius: 3px;
74-
user-select: none;
75-
pointer-events: none;
76-
margin: 0;
77-
margin-bottom: -14px;
78-
display: inline-block;
79-
z-index: 1;
80-
}
81-
8254
.code-wrapper {
8355
position: relative;
8456
display: inline-block;
@@ -292,11 +264,6 @@ blockquote.alert p:last-child {
292264
margin-bottom: 0;
293265
}
294266

295-
:root.dark .code-lang {
296-
background-color: transparent !important;
297-
color: #666 !important;
298-
}
299-
300267
@media screen and (max-width: 600px) {
301268
pre.hljs,
302269
.code-wrapper {

vercel.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,5 @@
22
"buildCommand": "npm run build",
33
"outputDirectory": "dist",
44
"devCommand": "npm run dev",
5-
"installCommand": "npm install",
6-
"cleanUrls": true,
7-
"trailingSlash": false,
8-
"rewrites": [
9-
{ "source": "/((?!.*\\.).*)", "destination": "/$1.html" }
10-
]
5+
"installCommand": "npm install"
116
}

0 commit comments

Comments
 (0)