Skip to content

Commit 51c7a9c

Browse files
committed
update: .eleventy.js — support for highlightjs-diff
1 parent 285d166 commit 51c7a9c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

.eleventy.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import fs from "fs"
22
import path from "path"
33
import dotenv from "dotenv"
44
import { DateTime } from "luxon"
5-
import hljs from "highlight.js"
5+
import highlight from "highlight.js"
6+
import highlightDiff from "highlightjs-code-diff"
67
import markdownIt from "markdown-it"
78
import anchor from "markdown-it-anchor"
89
import bracketedSpans from "markdown-it-bracketed-spans"
@@ -16,14 +17,17 @@ dotenv.config()
1617

1718
export default function (eleventyConfig) {
1819
const isDevelopment = process.env.NODE_ENV === "development"
20+
const hljs = highlightDiff(highlight)
1921
const markdownItConfig = markdownIt({
2022
html: true,
2123
linkify: true,
2224
typographer: true,
2325
highlight: function (str, lang) {
24-
if (lang && hljs.getLanguage(lang)) {
26+
const processLang = lang.replace("diff:", "")
27+
if (lang && hljs.getLanguage(processLang)) {
2528
try {
26-
return hljs.highlight(str, { language: lang }).value
29+
const returnValue = hljs.highlight(str, { language: lang }).value
30+
return returnValue
2731
} catch (__) { }
2832
}
2933
return ""

0 commit comments

Comments
 (0)