Skip to content

Commit f9f7b64

Browse files
committed
chore: updated packages, dual shiki themes, etc
1 parent ae5ccd0 commit f9f7b64

File tree

6 files changed

+67
-49
lines changed

6 files changed

+67
-49
lines changed

package-lock.json

Lines changed: 41 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"remark-rehype": "^11.1.0",
4040
"remark-stringify": "^11.0.0",
4141
"semver": "^7.6.3",
42-
"shiki": "^1.12.1",
42+
"shiki": "^1.14.1",
4343
"unified": "^11.0.5",
4444
"unist-builder": "^4.0.0",
4545
"unist-util-find-after": "^5.0.0",

shiki.config.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ import shellScriptLanguage from 'shiki/langs/shellscript.mjs';
1515
import shellSessionLanguage from 'shiki/langs/shellsession.mjs';
1616
import typeScriptLanguage from 'shiki/langs/typescript.mjs';
1717

18-
import shikiNordTheme from 'shiki/themes/nord.mjs';
18+
import lightTheme from 'shiki/themes/catppuccin-latte.mjs';
19+
import darkTheme from 'shiki/themes/catppuccin-mocha.mjs';
1920

2021
/**
21-
* @TODO: Use `shiki.config.mjs` from nodejs/nodejs.org
22-
*
2322
* Creates a Shiki configuration for the API Docs tooling
2423
*
2524
* @type {import('@shikijs/core').HighlighterCoreOptions}
2625
*/
2726
export default {
2827
loadWasm: getWasmInstance,
29-
theme: shikiNordTheme,
28+
// Only register the themes we need, to support light/dark theme
29+
themes: [lightTheme, darkTheme],
30+
// Only register the languages that the API docs use
31+
// and override the JavaScript language with the aliases
3032
langs: [
3133
{ ...javaScriptLanguage[0], aliases: ['mjs', 'cjs', 'js'] },
3234
...jsonLanguage,

src/generators/legacy-html/assets/style.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ tt,
531531
pre {
532532
padding: 1rem;
533533
vertical-align: top;
534-
background-color: var(--background-color-highlight);
534+
border-radius: 4px;
535535
margin: 1rem;
536536
overflow-x: auto;
537537
}
@@ -1027,7 +1027,8 @@ kbd {
10271027
text-transform: uppercase;
10281028
font-weight: 700;
10291029
padding: 0 0.5rem;
1030-
margin-right: 0.2rem;
1030+
margin-right: 10px;
1031+
margin-top: -2px;
10311032
height: 1.5rem;
10321033
transition-property: background-color, border-color, color, box-shadow, filter;
10331034
transition-duration: 0.3s;

src/generators/legacy-html/template.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
document.documentElement.classList.add('dark-mode');
2727
}
2828
</script>
29+
<style>
30+
html.dark-mode .shiki,
31+
html.dark-mode .shiki span {
32+
color: var(--shiki-dark) !important;
33+
background-color: var(--shiki-dark-bg) !important;
34+
/* Optional, if you also want font styles */
35+
font-style: var(--shiki-dark-font-style) !important;
36+
font-weight: var(--shiki-dark-font-weight) !important;
37+
text-decoration: var(--shiki-dark-text-decoration) !important;
38+
}
39+
</style>
2940
</head>
3041
<body class="alt apidoc" id="api-section-__FILENAME__">
3142
<div id="content" class="clearfix">

src/utils/highlighter.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export default function rehypeShikiji() {
9494
// Parses the <pre> contents and returns a HAST tree with the highlighted code
9595
const { children } = shikiHighlighter.codeToHast(preElementContents, {
9696
lang: languageId,
97-
theme: shikiConfig.theme,
97+
// Allows support for dual themes (light, dark) for Shiki
98+
themes: { light: shikiConfig.themes[0], dark: shikiConfig.themes[1] },
9899
});
99100

100101
// Adds the original language back to the <pre> element
@@ -147,11 +148,14 @@ export default function rehypeShikiji() {
147148
// We grab Shiki's styling from the code tag
148149
// back to the pre element tag to ensure consistency
149150
style: codeElements[0].properties.style,
151+
class: 'shiki',
150152
},
151153
[
152154
createElement('input', {
153155
class: 'js-flavor-toggle',
154156
type: 'checkbox',
157+
// If the CJS code block is the first one, then we should keep
158+
// the checkbox checked so that it highglit the CJS by default
155159
checked: codeElements[0].properties.language === 'cjs',
156160
}),
157161
...codeElements,

0 commit comments

Comments
 (0)