reallysimpledocs 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/astro/index.js
CHANGED
|
@@ -32,7 +32,7 @@ const normalizeImportPath = (filePath) => filePath.replaceAll(path.sep, "/");
|
|
|
32
32
|
|
|
33
33
|
const normalizeBoolean = (value, fallback = true) => (value === undefined ? fallback : Boolean(value));
|
|
34
34
|
|
|
35
|
-
const
|
|
35
|
+
const defaultShikiConfig = {
|
|
36
36
|
themes: {
|
|
37
37
|
light: "github-light",
|
|
38
38
|
dark: "github-dark",
|
|
@@ -40,6 +40,16 @@ const shikiConfig = {
|
|
|
40
40
|
defaultColor: false,
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
function normalizeShikiConfig(value = {}) {
|
|
44
|
+
return {
|
|
45
|
+
themes: {
|
|
46
|
+
...defaultShikiConfig.themes,
|
|
47
|
+
...(value.themes || {}),
|
|
48
|
+
},
|
|
49
|
+
defaultColor: value.defaultColor ?? defaultShikiConfig.defaultColor,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
43
53
|
function collectMdxModules(docsDir) {
|
|
44
54
|
if (!fs.existsSync(docsDir)) return {};
|
|
45
55
|
const modules = {};
|
|
@@ -77,6 +87,7 @@ export default function reallySimpleDocs(options = {}) {
|
|
|
77
87
|
components: options.components || {},
|
|
78
88
|
routeBase: options.routeBase ?? "/docs",
|
|
79
89
|
assetsBase: options.assetsBase || "/assets",
|
|
90
|
+
shiki: normalizeShikiConfig(options.shiki),
|
|
80
91
|
};
|
|
81
92
|
|
|
82
93
|
return {
|
|
@@ -153,7 +164,7 @@ export default function reallySimpleDocs(options = {}) {
|
|
|
153
164
|
integrations: [
|
|
154
165
|
mdx({
|
|
155
166
|
syntaxHighlight: "shiki",
|
|
156
|
-
shikiConfig,
|
|
167
|
+
shikiConfig: normalizedOptions.shiki,
|
|
157
168
|
}),
|
|
158
169
|
],
|
|
159
170
|
markdown: {
|
|
@@ -161,7 +172,7 @@ export default function reallySimpleDocs(options = {}) {
|
|
|
161
172
|
remarkPlugins: [[remarkPreviewSource, { docsDir }]],
|
|
162
173
|
rehypePlugins: [rehypeBasecoatTables],
|
|
163
174
|
}),
|
|
164
|
-
shikiConfig,
|
|
175
|
+
shikiConfig: normalizedOptions.shiki,
|
|
165
176
|
},
|
|
166
177
|
vite: {
|
|
167
178
|
build: {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
---
|
|
2
|
+
import config from "virtual:reallysimpledocs/config";
|
|
2
3
|
import { highlightCode } from "../../lib/highlight.js";
|
|
3
4
|
import { decodeHtml } from "../../lib/html.js";
|
|
4
5
|
|
|
5
6
|
const { lang = "text", title, code, class: className = "" } = Astro.props;
|
|
6
7
|
const slotHtml = Astro.slots.has("default") ? await Astro.slots.render("default") : "";
|
|
7
8
|
const rawCode = typeof code === "string" ? code.trim() : decodeSlotText(slotHtml);
|
|
8
|
-
const html = await highlightCode(rawCode, lang);
|
|
9
|
+
const html = await highlightCode(rawCode, lang, config.shiki);
|
|
9
10
|
|
|
10
11
|
function decodeSlotText(value) {
|
|
11
12
|
const text = String(value || "")
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
---
|
|
2
|
+
import config from "virtual:reallysimpledocs/config";
|
|
2
3
|
import { highlightCode } from "../../lib/highlight.js";
|
|
3
4
|
|
|
4
5
|
const { code = "", lang = "html", title = "Preview", class: className = "" } = Astro.props;
|
|
5
6
|
const id = `preview-${Math.random().toString(36).slice(2)}`;
|
|
6
|
-
const html = await highlightCode(code, lang);
|
|
7
|
+
const html = await highlightCode(code, lang, config.shiki);
|
|
7
8
|
const previewClassName = className || "w-fit";
|
|
8
9
|
---
|
|
9
10
|
|
package/src/runtime/lib/docs.js
CHANGED
|
@@ -107,7 +107,7 @@ export async function renderDoc(config, page) {
|
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
const tokens = marked.lexer(content);
|
|
110
|
-
await highlightCode(tokens);
|
|
110
|
+
await highlightCode(tokens, config.shiki);
|
|
111
111
|
const html = marked.parser(tokens, { renderer });
|
|
112
112
|
return { page, html: await transformBasecoatTablesHtml(html), headings };
|
|
113
113
|
}
|
|
@@ -360,10 +360,10 @@ function normalizeDocSource(source) {
|
|
|
360
360
|
.trimStart();
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
-
async function highlightCode(tokens) {
|
|
363
|
+
async function highlightCode(tokens, shiki) {
|
|
364
364
|
for (const token of tokens) {
|
|
365
365
|
if (token.type === "code") {
|
|
366
|
-
const html = codeBlockHtml(token, await highlightToken(token));
|
|
366
|
+
const html = codeBlockHtml(token, await highlightToken(token, shiki));
|
|
367
367
|
Object.assign(token, {
|
|
368
368
|
type: "html",
|
|
369
369
|
raw: html,
|
|
@@ -374,7 +374,7 @@ async function highlightCode(tokens) {
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
for (const childTokens of nestedTokenLists(token)) {
|
|
377
|
-
await highlightCode(childTokens);
|
|
377
|
+
await highlightCode(childTokens, shiki);
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
}
|
|
@@ -385,28 +385,32 @@ function codeBlockHtml(token, html) {
|
|
|
385
385
|
return `<div class="code-frame" data-code-title="${escapeHtml(title)}"><header><span>${escapeHtml(title)}</span></header><div class="code-block">${html}</div></div>`;
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
-
async function highlightToken(token) {
|
|
388
|
+
async function highlightToken(token, shiki = {}) {
|
|
389
|
+
const shikiConfig = normalizeShikiConfig(shiki);
|
|
389
390
|
try {
|
|
390
391
|
return await codeToHtml(token.text, {
|
|
391
392
|
lang: normalizeLanguage(token.lang),
|
|
392
|
-
|
|
393
|
-
light: "github-light",
|
|
394
|
-
dark: "github-dark",
|
|
395
|
-
},
|
|
396
|
-
defaultColor: false,
|
|
393
|
+
...shikiConfig,
|
|
397
394
|
});
|
|
398
395
|
} catch {
|
|
399
396
|
return codeToHtml(token.text, {
|
|
400
397
|
lang: "text",
|
|
401
|
-
|
|
402
|
-
light: "github-light",
|
|
403
|
-
dark: "github-dark",
|
|
404
|
-
},
|
|
405
|
-
defaultColor: false,
|
|
398
|
+
...shikiConfig,
|
|
406
399
|
});
|
|
407
400
|
}
|
|
408
401
|
}
|
|
409
402
|
|
|
403
|
+
function normalizeShikiConfig(value = {}) {
|
|
404
|
+
return {
|
|
405
|
+
themes: {
|
|
406
|
+
light: "github-light",
|
|
407
|
+
dark: "github-dark",
|
|
408
|
+
...(value.themes || {}),
|
|
409
|
+
},
|
|
410
|
+
defaultColor: value.defaultColor ?? false,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
410
414
|
function normalizeLanguage(lang) {
|
|
411
415
|
const value = lang?.trim().split(/\s+/)[0].toLowerCase() || "text";
|
|
412
416
|
if (value === "njk") return "html";
|
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
import { codeToHtml } from "shiki";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const defaultShikiConfig = {
|
|
4
|
+
themes: {
|
|
5
|
+
light: "github-light",
|
|
6
|
+
dark: "github-dark",
|
|
7
|
+
},
|
|
8
|
+
defaultColor: false,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function highlightCode(code, lang = "text", shiki = defaultShikiConfig) {
|
|
4
12
|
const value = String(code || "");
|
|
5
13
|
const language = String(lang || "text").toLowerCase() === "mdx" ? "tsx" : String(lang || "text");
|
|
6
14
|
const html = await codeToHtml(value, {
|
|
7
15
|
lang: language,
|
|
8
|
-
|
|
9
|
-
light: "github-light",
|
|
10
|
-
dark: "github-dark",
|
|
11
|
-
},
|
|
12
|
-
defaultColor: false,
|
|
16
|
+
...normalizeShikiConfig(shiki),
|
|
13
17
|
});
|
|
14
18
|
return addPreClass(html, "scrollbar");
|
|
15
19
|
}
|
|
16
20
|
|
|
21
|
+
function normalizeShikiConfig(value = {}) {
|
|
22
|
+
return {
|
|
23
|
+
themes: {
|
|
24
|
+
...defaultShikiConfig.themes,
|
|
25
|
+
...(value.themes || {}),
|
|
26
|
+
},
|
|
27
|
+
defaultColor: value.defaultColor ?? defaultShikiConfig.defaultColor,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
17
31
|
function addPreClass(html, className) {
|
|
18
32
|
return String(html).replace(/<pre(\s[^>]*)?>/, (match, attrs = "") => {
|
|
19
33
|
const classMatch = attrs.match(/\sclass=(["'])(.*?)\1/s);
|