Skip to content

Commit 2836dfc

Browse files
committed
fix highlighting
1 parent f9ecf8e commit 2836dfc

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

data/lesson.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@ import path from "path";
22
import fs from "fs/promises";
33
import matter from "gray-matter";
44
import { titleCase } from "title-case";
5-
import { marked } from "marked";
5+
import { Marked } from "marked";
6+
import { markedHighlight } from "marked-highlight";
67
import hljs from "highlight.js";
78

89
const DEFAULT_ICON = "info-circle";
910
const lessonsPath = path.join(process.cwd(), "lessons");
1011

12+
const marked = new Marked(
13+
markedHighlight({
14+
baseUrl: process.env.BASE_URL ? process.env.BASE_URL + "/" : "/",
15+
highlight: function (code, lang) {
16+
const language = hljs.getLanguage(lang) ? lang : "plaintext";
17+
return hljs.highlight(code, { language }).value;
18+
},
19+
langPrefix: "hljs language-",
20+
})
21+
);
22+
1123
function getTitle(slug, override) {
1224
let title = override;
1325
if (!title) {
@@ -43,15 +55,6 @@ function slugify(inputPath) {
4355
}
4456

4557
export async function getLessons() {
46-
marked.setOptions({
47-
baseUrl: process.env.BASE_URL ? process.env.BASE_URL + "/" : "/",
48-
highlight: function (code, lang) {
49-
const language = hljs.getLanguage(lang) ? lang : "plaintext";
50-
return hljs.highlight(code, { language }).value;
51-
},
52-
langPrefix: "hljs language-",
53-
});
54-
5558
const dir = await fs.readdir(lessonsPath);
5659
const sections = [];
5760

@@ -137,7 +140,7 @@ export async function getLesson(targetDir, targetFile) {
137140
const filePath = path.join(lessonsPath, dirPath, slugPath);
138141
const file = await fs.readFile(filePath);
139142
const { data, content } = matter(file.toString());
140-
const html = marked(content);
143+
const html = marked.parse(content);
141144
const title = getTitle(targetFile, data.title);
142145
const meta = await getMeta(dirPath);
143146

0 commit comments

Comments
 (0)