Skip to content

Commit

Permalink
feat: configure Light Owl and Night Owl for syntax highlighting (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
greatislander authored Jul 23, 2024
1 parent 85ec92b commit e0145bf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
21 changes: 18 additions & 3 deletions src/_transforms/syntax-highlight.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
16 changes: 15 additions & 1 deletion src/assets/styles/report.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e0145bf

Please sign in to comment.