diff --git a/package-lock.json b/package-lock.json index 602e035..b01d056 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "execa": "^9.3.0", "linkedom": "^0.18.4", "new-github-issue-url": "^1.0.0", + "night-owl": "github:sdras/night-owl-vscode-theme", "shiki": "^1.11.0" }, "devDependencies": { @@ -6293,6 +6294,13 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/night-owl": { + "version": "2.0.1", + "resolved": "git+ssh://git@github.com/sdras/night-owl-vscode-theme.git#f260cea5356261337d18809bdbe922952c7a6fa4", + "engines": { + "vscode": "^1.17.0" + } + }, "node_modules/node-fetch": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", diff --git a/package.json b/package.json index 007cc93..afe70ca 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "execa": "^9.3.0", "linkedom": "^0.18.4", "new-github-issue-url": "^1.0.0", + "night-owl": "github:sdras/night-owl-vscode-theme", "shiki": "^1.11.0" }, "devDependencies": { diff --git a/src/_transforms/syntax-highlight.js b/src/_transforms/syntax-highlight.js index 3579fc6..0058c1f 100644 --- a/src/_transforms/syntax-highlight.js +++ b/src/_transforms/syntax-highlight.js @@ -1,17 +1,32 @@ +import { readFile } from "fs/promises"; import { parseHTML } from "linkedom"; -import { codeToHtml } from "shiki"; +import { bundledLanguages, createHighlighter } from "shiki"; export default async function (content) { if (this.page.outputPath && this.page.outputPath.includes(".html")) { const { document } = parseHTML(content); const codeBlocks = [...document.querySelectorAll("pre code")]; + const lightOwl = JSON.parse(await readFile(new URL("./../../node_modules/night-owl/themes/Night Owl-Light-color-theme-noitalic.json", import.meta.url))); + + lightOwl.name = "light-owl"; + + const highlighter = await createHighlighter({ + themes: [lightOwl, "night-owl"], + langs: Object.keys(bundledLanguages) + }); + if (codeBlocks.length > 0) { for (const codeBlock of codeBlocks) { const lang = codeBlock.className.replace("language-", ""); - const html = await codeToHtml(codeBlock.textContent, { + + const html = highlighter.codeToHtml(codeBlock.textContent, { lang, - theme: "night-owl" + themes: { + dark: "night-owl", + light: "light-owl" + }, + defaultColor: false }); codeBlock.parentNode.outerHTML = html; diff --git a/src/assets/styles/report.css b/src/assets/styles/report.css index e3ad772..7a1b25a 100644 --- a/src/assets/styles/report.css +++ b/src/assets/styles/report.css @@ -161,12 +161,26 @@ code { font-size: 0.875rem; } -pre.shiki { +.shiki { border-radius: 0.25rem; padding-block: 0.5em; padding-inline: 1em; } +.shiki, +.shiki span { + background-color: var(--shiki-light-bg); + color: var(--shiki-light); +} + +@media (prefers-color-scheme: dark) { + .shiki, + .shiki span { + background-color: var(--shiki-dark-bg); + color: var(--shiki-dark); + } +} + [aria-expanded] { appearance: none; background: transparent;