@thedatagrid/docs-kit 0.0.0-stage → 0.2.0
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/CHANGELOG.md +20 -0
- package/README.md +224 -2
- package/dist/code/demoFiles.d.ts +14 -0
- package/dist/code/demoFiles.d.ts.map +1 -0
- package/dist/code/demoFiles.js +46 -0
- package/dist/code/demoFiles.js.map +1 -0
- package/dist/code/heights.d.ts +17 -0
- package/dist/code/heights.d.ts.map +1 -0
- package/dist/code/heights.js +40 -0
- package/dist/code/heights.js.map +1 -0
- package/dist/code/highlightSpec.d.ts +34 -0
- package/dist/code/highlightSpec.d.ts.map +1 -0
- package/dist/code/highlightSpec.js +119 -0
- package/dist/code/highlightSpec.js.map +1 -0
- package/dist/code/imports.d.ts +5 -0
- package/dist/code/imports.d.ts.map +1 -0
- package/dist/code/imports.js +17 -0
- package/dist/code/imports.js.map +1 -0
- package/dist/code/index.d.ts +8 -0
- package/dist/code/index.d.ts.map +1 -0
- package/dist/code/index.js +8 -0
- package/dist/code/index.js.map +1 -0
- package/dist/code/lineRanges.d.ts +5 -0
- package/dist/code/lineRanges.d.ts.map +1 -0
- package/dist/code/lineRanges.js +35 -0
- package/dist/code/lineRanges.js.map +1 -0
- package/dist/code/regions.d.ts +53 -0
- package/dist/code/regions.d.ts.map +1 -0
- package/dist/code/regions.js +237 -0
- package/dist/code/regions.js.map +1 -0
- package/dist/code/shiki.d.ts +58 -0
- package/dist/code/shiki.d.ts.map +1 -0
- package/dist/code/shiki.js +244 -0
- package/dist/code/shiki.js.map +1 -0
- package/dist/demos/build.d.ts +17 -0
- package/dist/demos/build.d.ts.map +1 -0
- package/dist/demos/build.js +426 -0
- package/dist/demos/build.js.map +1 -0
- package/dist/demos/cli.d.ts +3 -0
- package/dist/demos/cli.d.ts.map +1 -0
- package/dist/demos/cli.js +102 -0
- package/dist/demos/cli.js.map +1 -0
- package/dist/demos/client.d.ts +27 -0
- package/dist/demos/client.d.ts.map +1 -0
- package/dist/demos/client.js +61 -0
- package/dist/demos/client.js.map +1 -0
- package/dist/demos/compile/core.d.ts +64 -0
- package/dist/demos/compile/core.d.ts.map +1 -0
- package/dist/demos/compile/core.js +174 -0
- package/dist/demos/compile/core.js.map +1 -0
- package/dist/demos/config.d.ts +108 -0
- package/dist/demos/config.d.ts.map +1 -0
- package/dist/demos/config.js +4 -0
- package/dist/demos/config.js.map +1 -0
- package/dist/demos/devEvents.d.ts +13 -0
- package/dist/demos/devEvents.d.ts.map +1 -0
- package/dist/demos/devEvents.js +45 -0
- package/dist/demos/devEvents.js.map +1 -0
- package/dist/demos/html.d.ts +21 -0
- package/dist/demos/html.d.ts.map +1 -0
- package/dist/demos/html.js +57 -0
- package/dist/demos/html.js.map +1 -0
- package/dist/demos/index.d.ts +8 -0
- package/dist/demos/index.d.ts.map +1 -0
- package/dist/demos/index.js +6 -0
- package/dist/demos/index.js.map +1 -0
- package/dist/demos/pages.d.ts +15 -0
- package/dist/demos/pages.d.ts.map +1 -0
- package/dist/demos/pages.js +71 -0
- package/dist/demos/pages.js.map +1 -0
- package/dist/demos/runtime/iframe.d.ts +50 -0
- package/dist/demos/runtime/iframe.d.ts.map +1 -0
- package/dist/demos/runtime/iframe.js +245 -0
- package/dist/demos/runtime/iframe.js.map +1 -0
- package/dist/demos/runtime/react.d.ts +3 -0
- package/dist/demos/runtime/react.d.ts.map +1 -0
- package/dist/demos/runtime/react.js +17 -0
- package/dist/demos/runtime/react.js.map +1 -0
- package/dist/demos/slug.d.ts +3 -0
- package/dist/demos/slug.d.ts.map +1 -0
- package/dist/demos/slug.js +11 -0
- package/dist/demos/slug.js.map +1 -0
- package/dist/demos/vendor.d.ts +32 -0
- package/dist/demos/vendor.d.ts.map +1 -0
- package/dist/demos/vendor.js +127 -0
- package/dist/demos/vendor.js.map +1 -0
- package/dist/demos/worker/compile.worker.d.ts +2 -0
- package/dist/demos/worker/compile.worker.d.ts.map +1 -0
- package/dist/demos/worker/compile.worker.js +27 -0
- package/dist/demos/worker/compile.worker.js.map +1 -0
- package/dist/editor/install.d.ts +15 -0
- package/dist/editor/install.d.ts.map +1 -0
- package/dist/editor/install.js +71 -0
- package/dist/editor/install.js.map +1 -0
- package/dist/fork/codesandbox.d.ts +39 -0
- package/dist/fork/codesandbox.d.ts.map +1 -0
- package/dist/fork/codesandbox.js +156 -0
- package/dist/fork/codesandbox.js.map +1 -0
- package/dist/fork/index.d.ts +2 -0
- package/dist/fork/index.d.ts.map +1 -0
- package/dist/fork/index.js +2 -0
- package/dist/fork/index.js.map +1 -0
- package/dist/react/Demo.d.ts +80 -0
- package/dist/react/Demo.d.ts.map +1 -0
- package/dist/react/Demo.js +156 -0
- package/dist/react/Demo.js.map +1 -0
- package/dist/react/DemoIframe.d.ts +22 -0
- package/dist/react/DemoIframe.d.ts.map +1 -0
- package/dist/react/DemoIframe.js +123 -0
- package/dist/react/DemoIframe.js.map +1 -0
- package/dist/react/DemoShell.d.ts +47 -0
- package/dist/react/DemoShell.d.ts.map +1 -0
- package/dist/react/DemoShell.js +341 -0
- package/dist/react/DemoShell.js.map +1 -0
- package/dist/react/devEvents.d.ts +17 -0
- package/dist/react/devEvents.d.ts.map +1 -0
- package/dist/react/devEvents.js +30 -0
- package/dist/react/devEvents.js.map +1 -0
- package/dist/react/editor.d.ts +17 -0
- package/dist/react/editor.d.ts.map +1 -0
- package/dist/react/editor.js +158 -0
- package/dist/react/editor.js.map +1 -0
- package/dist/react/fork.d.ts +10 -0
- package/dist/react/fork.d.ts.map +1 -0
- package/dist/react/fork.js +30 -0
- package/dist/react/fork.js.map +1 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +4 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/styles.css +471 -0
- package/dist/remark/index.d.ts +3 -0
- package/dist/remark/index.d.ts.map +1 -0
- package/dist/remark/index.js +3 -0
- package/dist/remark/index.js.map +1 -0
- package/dist/remark/meta.d.ts +7 -0
- package/dist/remark/meta.d.ts.map +1 -0
- package/dist/remark/meta.js +20 -0
- package/dist/remark/meta.js.map +1 -0
- package/dist/remark/remarkDemoFences.d.ts +77 -0
- package/dist/remark/remarkDemoFences.d.ts.map +1 -0
- package/dist/remark/remarkDemoFences.js +259 -0
- package/dist/remark/remarkDemoFences.js.map +1 -0
- package/editor-extension/README.md +23 -0
- package/editor-extension/extension.js +40 -0
- package/editor-extension/links.js +137 -0
- package/editor-extension/package.json +19 -0
- package/package.json +107 -4
- package/src/code/demoFiles.ts +54 -0
- package/src/code/heights.ts +47 -0
- package/src/code/highlightSpec.ts +139 -0
- package/src/code/imports.ts +18 -0
- package/src/code/index.ts +46 -0
- package/src/code/lineRanges.ts +31 -0
- package/src/code/regions.ts +270 -0
- package/src/code/shiki.ts +271 -0
- package/src/demos/build.ts +477 -0
- package/src/demos/cli.ts +97 -0
- package/src/demos/client.ts +82 -0
- package/src/demos/compile/core.ts +228 -0
- package/src/demos/config.ts +106 -0
- package/src/demos/devEvents.ts +45 -0
- package/src/demos/html.ts +74 -0
- package/src/demos/index.ts +25 -0
- package/src/demos/pages.ts +79 -0
- package/src/demos/runtime/iframe.ts +262 -0
- package/src/demos/runtime/react.ts +19 -0
- package/src/demos/slug.ts +10 -0
- package/src/demos/vendor.ts +142 -0
- package/src/demos/worker/compile.worker.ts +35 -0
- package/src/editor/install.ts +85 -0
- package/src/fork/codesandbox.ts +189 -0
- package/src/fork/index.ts +10 -0
- package/src/react/Demo.tsx +250 -0
- package/src/react/DemoIframe.tsx +165 -0
- package/src/react/DemoShell.tsx +592 -0
- package/src/react/devEvents.ts +34 -0
- package/src/react/editor.ts +178 -0
- package/src/react/fork.ts +31 -0
- package/src/react/index.ts +10 -0
- package/src/react/styles.css +471 -0
- package/src/remark/index.ts +2 -0
- package/src/remark/meta.ts +20 -0
- package/src/remark/remarkDemoFences.ts +330 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Expands `"1-3,7"` into `[1, 2, 3, 7]` (1-based). */
|
|
2
|
+
export function parseLineRanges(spec) {
|
|
3
|
+
const lines = [];
|
|
4
|
+
for (const part of spec.split(',')) {
|
|
5
|
+
const token = part.trim();
|
|
6
|
+
if (!token)
|
|
7
|
+
continue;
|
|
8
|
+
const [start, end = start] = token.split('-').map((n) => Number(n.trim()));
|
|
9
|
+
if (!Number.isFinite(start) || !Number.isFinite(end))
|
|
10
|
+
continue;
|
|
11
|
+
for (let line = start; line <= end; line++)
|
|
12
|
+
lines.push(line);
|
|
13
|
+
}
|
|
14
|
+
return lines;
|
|
15
|
+
}
|
|
16
|
+
/** Compacts `[1, 2, 3, 7]` into `"1-3,7"`. */
|
|
17
|
+
export function formatLineRanges(lines) {
|
|
18
|
+
if (!lines.length)
|
|
19
|
+
return '';
|
|
20
|
+
const parts = [];
|
|
21
|
+
let start = lines[0];
|
|
22
|
+
let prev = lines[0];
|
|
23
|
+
for (let i = 1; i < lines.length; i++) {
|
|
24
|
+
const n = lines[i];
|
|
25
|
+
if (n === prev + 1) {
|
|
26
|
+
prev = n;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
parts.push(start === prev ? String(start) : `${start}-${prev}`);
|
|
30
|
+
start = prev = n;
|
|
31
|
+
}
|
|
32
|
+
parts.push(start === prev ? String(start) : `${start}-${prev}`);
|
|
33
|
+
return parts.join(',');
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=lineRanges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lineRanges.js","sourceRoot":"","sources":["../../src/code/lineRanges.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC1B,IA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;IACnB,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC,CAAC;IAChE,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { HighlightSpec } from './highlightSpec.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Source preparation for docs fences:
|
|
4
|
+
*
|
|
5
|
+
* - `sliceRegion` extracts a VS Code / fumadocs `#region name` block (`region="name"`).
|
|
6
|
+
* - `extractCodeMarkers` strips `#highlight` / `#region` marker comments and
|
|
7
|
+
* returns the lines they highlight.
|
|
8
|
+
*/
|
|
9
|
+
export type SlicedRange = {
|
|
10
|
+
source: string;
|
|
11
|
+
/** 1-based original file line numbers of the displayed lines. */
|
|
12
|
+
originalLines: number[];
|
|
13
|
+
};
|
|
14
|
+
export declare function dedent(lines: string[]): string;
|
|
15
|
+
export declare function listRegionNames(source: string): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Returns the displayed source for `region="name"` plus the original file line
|
|
18
|
+
* numbers (so a `lines` gutter can keep showing those). Throws with the list
|
|
19
|
+
* of known regions when the name doesn't exist.
|
|
20
|
+
*/
|
|
21
|
+
export declare function sliceRegion(source: string, spec: string, context: string): SlicedRange;
|
|
22
|
+
export type CodeWithMarkers = SlicedRange & {
|
|
23
|
+
/** Displayed (1-based) lines marked with `#highlight`, labels on the first line of each block. */
|
|
24
|
+
highlight: HighlightSpec;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Strips marker comments from a snippet and returns the lines they highlight.
|
|
28
|
+
*
|
|
29
|
+
* - `// #highlight label` … `// #endhighlight` highlights the lines in between.
|
|
30
|
+
* Without a closing `#endhighlight` (before the next `#highlight`), only the
|
|
31
|
+
* next non-blank line is highlighted.
|
|
32
|
+
* With a label, the opening marker becomes an empty highlighted line that
|
|
33
|
+
* shows the label; without one it is removed.
|
|
34
|
+
* - `code // #highlight label` highlights that single line.
|
|
35
|
+
* - `/* … *\/` and `{/* … *\/}` (JSX children) work for both forms.
|
|
36
|
+
* - `#region` / `#endregion` lines are dropped, so full-file views don't show them.
|
|
37
|
+
*
|
|
38
|
+
* `originalLines` (from `sliceRegion`) is kept in step with the removed lines.
|
|
39
|
+
*/
|
|
40
|
+
export declare function extractCodeMarkers(source: string, context: string, originalLines?: number[]): CodeWithMarkers;
|
|
41
|
+
/**
|
|
42
|
+
* Removes every marker comment (`#highlight`, `#endhighlight`, trailing
|
|
43
|
+
* `// #highlight`, `#region` lines) without the empty label rows that
|
|
44
|
+
* `extractCodeMarkers` keeps for display: the code to copy, edit and fork.
|
|
45
|
+
*/
|
|
46
|
+
export declare function stripCodeMarkers(source: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Applies literal `search → replacement` pairs to source shown in the docs
|
|
49
|
+
* (e.g. `process.env.API_URL` → `"https://…"`), so displayed, edited and
|
|
50
|
+
* forked code runs without the docs build's `define`s.
|
|
51
|
+
*/
|
|
52
|
+
export declare function applySourceReplacements(source: string, replacements: Record<string, string> | undefined): string;
|
|
53
|
+
//# sourceMappingURL=regions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regions.d.ts","sourceRoot":"","sources":["../../src/code/regions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;;;;GAMG;AAEH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,iEAAiE;IACjE,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAyCF,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAM9C;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CASxD;AAqCD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW,CAgBtF;AAaD,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG;IAC1C,kGAAkG;IAClG,SAAS,EAAE,aAAa,CAAC;CAC1B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,EAAE,GACvB,eAAe,CAuEjB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQvD;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAC/C,MAAM,CAOR"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VS Code–style region markers, adapted from fumadocs / VitePress.
|
|
3
|
+
* https://github.com/fuma-nama/fumadocs (remark-include)
|
|
4
|
+
*/
|
|
5
|
+
const REGION_MARKERS = [
|
|
6
|
+
{
|
|
7
|
+
start: /^\s*\/\/\s*#?region\b\s*(.*?)\s*$/,
|
|
8
|
+
end: /^\s*\/\/\s*#?endregion\b\s*(.*?)\s*$/,
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
start: /^\s*<!--\s*#?region\b\s*(.*?)\s*-->/,
|
|
12
|
+
end: /^\s*<!--\s*#?endregion\b\s*(.*?)\s*-->/,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
start: /^\s*\{?\/\*\s*#region\b\s*(.*?)\s*\*\/\}?/,
|
|
16
|
+
end: /^\s*\{?\/\*\s*#endregion\b\s*(.*?)\s*\*\/\}?/,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
start: /^\s*#[rR]egion\b\s*(.*?)\s*$/,
|
|
20
|
+
end: /^\s*#[eE]nd ?[rR]egion\b\s*(.*?)\s*$/,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
start: /^\s*#\s*#?region\b\s*(.*?)\s*$/,
|
|
24
|
+
end: /^\s*#\s*#?endregion\b\s*(.*?)\s*$/,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
start: /^\s*(?:--|::|@?REM)\s*#region\b\s*(.*?)\s*$/,
|
|
28
|
+
end: /^\s*(?:--|::|@?REM)\s*#endregion\b\s*(.*?)\s*$/,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
start: /^\s*#pragma\s+region\b\s*(.*?)\s*$/,
|
|
32
|
+
end: /^\s*#pragma\s+endregion\b\s*(.*?)\s*$/,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
start: /^\s*\(\*\s*#region\b\s*(.*?)\s*\*\)/,
|
|
36
|
+
end: /^\s*\(\*\s*#endregion\b\s*(.*?)\s*\*\)/,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
export function dedent(lines) {
|
|
40
|
+
const indents = lines
|
|
41
|
+
.filter((line) => line.trim())
|
|
42
|
+
.map((line) => /^[ \t]*/.exec(line)[0].length);
|
|
43
|
+
const minIndent = indents.length ? Math.min(...indents) : 0;
|
|
44
|
+
return lines.map((line) => line.slice(minIndent)).join('\n');
|
|
45
|
+
}
|
|
46
|
+
export function listRegionNames(source) {
|
|
47
|
+
const names = new Set();
|
|
48
|
+
for (const line of source.split('\n')) {
|
|
49
|
+
for (const re of REGION_MARKERS) {
|
|
50
|
+
const match = re.start.exec(line);
|
|
51
|
+
if (match?.[1])
|
|
52
|
+
names.add(match[1]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return [...names];
|
|
56
|
+
}
|
|
57
|
+
function extractNamedRegion(source, regionName) {
|
|
58
|
+
const all = source.split('\n');
|
|
59
|
+
for (let i = 0; i < all.length; i++) {
|
|
60
|
+
for (const re of REGION_MARKERS) {
|
|
61
|
+
let match = re.start.exec(all[i]);
|
|
62
|
+
if (match?.[1] !== regionName)
|
|
63
|
+
continue;
|
|
64
|
+
let depth = 1;
|
|
65
|
+
const extractedLines = [];
|
|
66
|
+
const originalLines = [];
|
|
67
|
+
for (let j = i + 1; j < all.length; j++) {
|
|
68
|
+
match = re.start.exec(all[j]);
|
|
69
|
+
if (match) {
|
|
70
|
+
depth++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
match = re.end.exec(all[j]);
|
|
74
|
+
if (match) {
|
|
75
|
+
if (match[1] === regionName) {
|
|
76
|
+
depth = 0;
|
|
77
|
+
}
|
|
78
|
+
else if (match[1] === '') {
|
|
79
|
+
depth--;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (depth > 0)
|
|
85
|
+
continue;
|
|
86
|
+
return { source: dedent(extractedLines), originalLines };
|
|
87
|
+
}
|
|
88
|
+
extractedLines.push(all[j]);
|
|
89
|
+
originalLines.push(j + 1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns the displayed source for `region="name"` plus the original file line
|
|
97
|
+
* numbers (so a `lines` gutter can keep showing those). Throws with the list
|
|
98
|
+
* of known regions when the name doesn't exist.
|
|
99
|
+
*/
|
|
100
|
+
export function sliceRegion(source, spec, context) {
|
|
101
|
+
const name = spec.trim();
|
|
102
|
+
if (!name)
|
|
103
|
+
throw new Error(`${context}: \`region\` is empty`);
|
|
104
|
+
const extracted = extractNamedRegion(source, name);
|
|
105
|
+
if (!extracted) {
|
|
106
|
+
const known = listRegionNames(source);
|
|
107
|
+
const hint = known.length
|
|
108
|
+
? ` (known regions: ${known.map((n) => `"${n}"`).join(', ')})`
|
|
109
|
+
: ' (no `#region` markers in the file)';
|
|
110
|
+
throw new Error(`${context}: \`region="${spec}"\` — region "${name}" not found${hint}. ` +
|
|
111
|
+
`Mark it with \`//#region ${name}\` … \`//#endregion\``);
|
|
112
|
+
}
|
|
113
|
+
return extracted;
|
|
114
|
+
}
|
|
115
|
+
/** Whole-line `// #highlight label`, `/* #highlight label *\/` or `{/* #highlight label *\/}`. */
|
|
116
|
+
const HIGHLIGHT_START_RE = /^\s*(?:\/\/\s*#highlight\b(.*)|\{?\/\*\s*#highlight\b(.*?)\*\/\}?)\s*$/;
|
|
117
|
+
const HIGHLIGHT_END_RE = /^\s*(?:\/\/\s*#endhighlight\b.*|\{?\/\*\s*#endhighlight\b.*?\*\/\}?)\s*$/;
|
|
118
|
+
/** Trailing `code // #highlight label` (or a `/* … *\/` / `{/* … *\/}` comment) after code. */
|
|
119
|
+
const HIGHLIGHT_INLINE_RE = /^(.*?\S)\s*(?:\/\/\s*#highlight\b(.*)|\{\/\*\s*#highlight\b(.*?)\*\/\}|\/\*\s*#highlight\b(.*?)\*\/)\s*$/;
|
|
120
|
+
function isRegionMarker(line) {
|
|
121
|
+
return REGION_MARKERS.some((re) => re.start.test(line) || re.end.test(line));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Strips marker comments from a snippet and returns the lines they highlight.
|
|
125
|
+
*
|
|
126
|
+
* - `// #highlight label` … `// #endhighlight` highlights the lines in between.
|
|
127
|
+
* Without a closing `#endhighlight` (before the next `#highlight`), only the
|
|
128
|
+
* next non-blank line is highlighted.
|
|
129
|
+
* With a label, the opening marker becomes an empty highlighted line that
|
|
130
|
+
* shows the label; without one it is removed.
|
|
131
|
+
* - `code // #highlight label` highlights that single line.
|
|
132
|
+
* - `/* … *\/` and `{/* … *\/}` (JSX children) work for both forms.
|
|
133
|
+
* - `#region` / `#endregion` lines are dropped, so full-file views don't show them.
|
|
134
|
+
*
|
|
135
|
+
* `originalLines` (from `sliceRegion`) is kept in step with the removed lines.
|
|
136
|
+
*/
|
|
137
|
+
export function extractCodeMarkers(source, context, originalLines) {
|
|
138
|
+
const input = source.split('\n');
|
|
139
|
+
const inputLines = originalLines ?? input.map((_, index) => index + 1);
|
|
140
|
+
const kept = [];
|
|
141
|
+
const keptLines = [];
|
|
142
|
+
const highlight = { lines: [], labels: {} };
|
|
143
|
+
/** `nextLineOnly`: no `#endhighlight` follows, so the block ends after the next non-blank line. */
|
|
144
|
+
let block = null;
|
|
145
|
+
const mark = (label) => {
|
|
146
|
+
const line = kept.length;
|
|
147
|
+
if (!highlight.lines.includes(line))
|
|
148
|
+
highlight.lines.push(line);
|
|
149
|
+
if (label && !highlight.labels[line])
|
|
150
|
+
highlight.labels[line] = label;
|
|
151
|
+
};
|
|
152
|
+
const hasClosingMarker = (startIndex) => {
|
|
153
|
+
for (let index = startIndex + 1; index < input.length; index++) {
|
|
154
|
+
if (HIGHLIGHT_END_RE.test(input[index]))
|
|
155
|
+
return true;
|
|
156
|
+
if (HIGHLIGHT_START_RE.test(input[index]))
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
};
|
|
161
|
+
for (let index = 0; index < input.length; index++) {
|
|
162
|
+
const text = input[index];
|
|
163
|
+
const fileLine = inputLines[index];
|
|
164
|
+
const start = HIGHLIGHT_START_RE.exec(text);
|
|
165
|
+
if (start) {
|
|
166
|
+
// A block with an `#endhighlight` never sees another `#highlight` first (see hasClosingMarker).
|
|
167
|
+
if (block) {
|
|
168
|
+
throw new Error(`${context}: the \`#highlight\` on line ${block.fileLine} has no code line before the \`#highlight\` on line ${fileLine}`);
|
|
169
|
+
}
|
|
170
|
+
const label = (start[1] ?? start[2] ?? '').trim();
|
|
171
|
+
if (label) {
|
|
172
|
+
// the label row keeps the marker's indentation, so the label lines up with the block
|
|
173
|
+
kept.push(/^\s*/.exec(text)[0]);
|
|
174
|
+
keptLines.push(fileLine);
|
|
175
|
+
mark(label);
|
|
176
|
+
}
|
|
177
|
+
block = { fileLine, startsAt: kept.length + 1, nextLineOnly: !hasClosingMarker(index) };
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (HIGHLIGHT_END_RE.test(text)) {
|
|
181
|
+
if (!block) {
|
|
182
|
+
throw new Error(`${context}: \`#endhighlight\` on line ${fileLine} has no matching \`#highlight\``);
|
|
183
|
+
}
|
|
184
|
+
if (kept.length < block.startsAt) {
|
|
185
|
+
throw new Error(`${context}: the \`#highlight\` block on line ${block.fileLine} is empty`);
|
|
186
|
+
}
|
|
187
|
+
block = null;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (isRegionMarker(text))
|
|
191
|
+
continue;
|
|
192
|
+
const inline = HIGHLIGHT_INLINE_RE.exec(text);
|
|
193
|
+
kept.push(inline ? inline[1] : text);
|
|
194
|
+
keptLines.push(fileLine);
|
|
195
|
+
if (inline)
|
|
196
|
+
mark((inline[2] ?? inline[3] ?? inline[4] ?? '').trim());
|
|
197
|
+
if (block) {
|
|
198
|
+
mark('');
|
|
199
|
+
if (block.nextLineOnly && text.trim())
|
|
200
|
+
block = null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (block) {
|
|
204
|
+
throw new Error(`${context}: the \`#highlight\` on line ${block.fileLine} has no code line after it`);
|
|
205
|
+
}
|
|
206
|
+
return { source: dedent(kept), originalLines: keptLines, highlight };
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Removes every marker comment (`#highlight`, `#endhighlight`, trailing
|
|
210
|
+
* `// #highlight`, `#region` lines) without the empty label rows that
|
|
211
|
+
* `extractCodeMarkers` keeps for display: the code to copy, edit and fork.
|
|
212
|
+
*/
|
|
213
|
+
export function stripCodeMarkers(source) {
|
|
214
|
+
const kept = [];
|
|
215
|
+
for (const line of source.split('\n')) {
|
|
216
|
+
if (HIGHLIGHT_START_RE.test(line) || HIGHLIGHT_END_RE.test(line) || isRegionMarker(line))
|
|
217
|
+
continue;
|
|
218
|
+
const inline = HIGHLIGHT_INLINE_RE.exec(line);
|
|
219
|
+
kept.push(inline ? inline[1] : line);
|
|
220
|
+
}
|
|
221
|
+
return dedent(kept);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Applies literal `search → replacement` pairs to source shown in the docs
|
|
225
|
+
* (e.g. `process.env.API_URL` → `"https://…"`), so displayed, edited and
|
|
226
|
+
* forked code runs without the docs build's `define`s.
|
|
227
|
+
*/
|
|
228
|
+
export function applySourceReplacements(source, replacements) {
|
|
229
|
+
if (!replacements)
|
|
230
|
+
return source;
|
|
231
|
+
let result = source;
|
|
232
|
+
for (const [search, replacement] of Object.entries(replacements)) {
|
|
233
|
+
result = result.split(search).join(replacement);
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=regions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regions.js","sourceRoot":"","sources":["../../src/code/regions.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,MAAM,cAAc,GAAqC;IACvD;QACE,KAAK,EAAE,mCAAmC;QAC1C,GAAG,EAAE,sCAAsC;KAC5C;IACD;QACE,KAAK,EAAE,qCAAqC;QAC5C,GAAG,EAAE,wCAAwC;KAC9C;IACD;QACE,KAAK,EAAE,2CAA2C;QAClD,GAAG,EAAE,8CAA8C;KACpD;IACD;QACE,KAAK,EAAE,8BAA8B;QACrC,GAAG,EAAE,sCAAsC;KAC5C;IACD;QACE,KAAK,EAAE,gCAAgC;QACvC,GAAG,EAAE,mCAAmC;KACzC;IACD;QACE,KAAK,EAAE,6CAA6C;QACpD,GAAG,EAAE,gDAAgD;KACtD;IACD;QACE,KAAK,EAAE,oCAAoC;QAC3C,GAAG,EAAE,uCAAuC;KAC7C;IACD;QACE,KAAK,EAAE,qCAAqC;QAC5C,GAAG,EAAE,wCAAwC;KAC9C;CACF,CAAC;AAEF,MAAM,UAAU,MAAM,CAAC,KAAe;IACpC,MAAM,OAAO,GAAG,KAAK;SAClB,MAAM,CAAC,CA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AC,IAAI,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC;YAAE,SAAS;QACnG,MAAM,MAAM,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAc,EACd,YAAgD;IAEhD,IAAI,CAAC,YAAY;QAAE,OAAO,MAAM,CAAC;IACjC,IAAI,MAAM,GAAG,MAAM,CAAC;IACpB,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QACjE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type ShikiTransformer } from 'shiki';
|
|
2
|
+
import { type HighlightSpec } from './highlightSpec.ts';
|
|
3
|
+
/** Light + dark shiki themes; output uses CSS variables (`defaultColor: false`). */
|
|
4
|
+
export type CodeThemes = {
|
|
5
|
+
light: string;
|
|
6
|
+
dark: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const DEFAULT_CODE_THEMES: CodeThemes;
|
|
9
|
+
/** Shiki language for a file name. */
|
|
10
|
+
export declare function langForFile(fileName: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Caps standalone code blocks whose meta carries `height` at that many pixels,
|
|
13
|
+
* scrolling inside. `auto` (the natural height) is a no-op.
|
|
14
|
+
*/
|
|
15
|
+
export declare function transformerHeightMeta(): ShikiTransformer;
|
|
16
|
+
/** POSIX `join` + normalize, enough for relative import specifiers. */
|
|
17
|
+
export declare function joinPath(...parts: string[]): string;
|
|
18
|
+
export declare function dirnameOf(filePath: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Finds the demo file an import specifier points to. `fromFile` and
|
|
21
|
+
* `fileNames` share one root (e.g. paths relative to the demo's folder).
|
|
22
|
+
*/
|
|
23
|
+
export declare function matchImportedFile(specifier: string, fromFile: string, fileNames: string[]): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Turns relative import specifiers into buttons (`data-demo-file`) that the
|
|
26
|
+
* demo shell uses to switch the active file tab.
|
|
27
|
+
*/
|
|
28
|
+
export declare function transformerImportFileLinks(fromFile: string, fileNames: string[]): ShikiTransformer;
|
|
29
|
+
/**
|
|
30
|
+
* Adds a `highlighted` class to the given lines. `#highlight label` labels are
|
|
31
|
+
* appended as `.line-label` on the first line of each block. Without an
|
|
32
|
+
* explicit spec it reads the `{…}` that the remark plugin wrote into the
|
|
33
|
+
* fence meta (for `@shikijs/rehype` pipelines).
|
|
34
|
+
*/
|
|
35
|
+
export declare function transformerLineHighlight(spec?: number[] | HighlightSpec): ShikiTransformer;
|
|
36
|
+
/**
|
|
37
|
+
* Gutter line numbers on every line (the `lines` fence flag). With
|
|
38
|
+
* `originalLines` (or `originalLines="12-14"` in the fence meta, written for
|
|
39
|
+
* `region` fences) the gutter shows those file line numbers.
|
|
40
|
+
*/
|
|
41
|
+
export declare function transformerLineNumbers(originalLines?: number[] | true): ShikiTransformer;
|
|
42
|
+
/** The transformers a markdown-level `@shikijs/rehype` pipeline needs for remark-processed fences. */
|
|
43
|
+
export declare function fenceTransformers(): ShikiTransformer[];
|
|
44
|
+
export type HighlightOptions = {
|
|
45
|
+
lang: string;
|
|
46
|
+
themes?: CodeThemes;
|
|
47
|
+
highlight?: HighlightSpec | null;
|
|
48
|
+
/** `true` for 1-based numbers, an array for original file line numbers. */
|
|
49
|
+
lineNumbers?: number[] | true | null;
|
|
50
|
+
/** Relative-import buttons: the current file and the other files of the demo. */
|
|
51
|
+
importLinks?: {
|
|
52
|
+
fromFile: string;
|
|
53
|
+
fileNames: string[];
|
|
54
|
+
} | null;
|
|
55
|
+
};
|
|
56
|
+
/** Highlights code to HTML with dual themes (CSS variables) and the docs transformers. */
|
|
57
|
+
export declare function highlightCode(code: string, options: HighlightOptions): Promise<string>;
|
|
58
|
+
//# sourceMappingURL=shiki.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shiki.d.ts","sourceRoot":"","sources":["../../src/code/shiki.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAE1D,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAC;AAI5B,oFAAoF;AACpF,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzD,eAAO,MAAM,mBAAmB,EAAE,UAA2D,CAAC;AAO9F,sCAAsC;AACtC,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CA2BpD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,gBAAgB,CAYxD;AAOD,uEAAuE;AACvE,wBAAgB,QAAQ,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAYnD;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EAAE,GAClB,MAAM,GAAG,SAAS,CAOpB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAuClG;AAQD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,aAAa,GAAG,gBAAgB,CAiC1F;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,gBAAgB,CA6BxF;AAED,sGAAsG;AACtG,wBAAgB,iBAAiB,IAAI,gBAAgB,EAAE,CAEtD;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,SAAS,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IACjC,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;IACrC,iFAAiF;IACjF,WAAW,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAAC;CAChE,CAAC;AAEF,0FAA0F;AAC1F,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAa5F"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { codeToHtml } from 'shiki';
|
|
2
|
+
import { HEIGHT_META_RE, HIGHLIGHT_META_RE, LINES_META_RE, ORIGINAL_LINES_META_RE, parseHighlightSpec, } from "./highlightSpec.js";
|
|
3
|
+
import { parseDemoHeight } from "./heights.js";
|
|
4
|
+
import { parseLineRanges } from "./lineRanges.js";
|
|
5
|
+
export const DEFAULT_CODE_THEMES = { light: 'github-light', dark: 'tokyo-night' };
|
|
6
|
+
const metaOf = (ctx) => ctx.meta;
|
|
7
|
+
const rawMeta = (ctx) => ctx.options.meta?.__raw || '';
|
|
8
|
+
/** Shiki language for a file name. */
|
|
9
|
+
export function langForFile(fileName) {
|
|
10
|
+
const ext = /\.([a-z0-9]+)$/i.exec(fileName)?.[1]?.toLowerCase() ?? '';
|
|
11
|
+
switch (ext) {
|
|
12
|
+
case 'ts':
|
|
13
|
+
case 'mts':
|
|
14
|
+
case 'cts':
|
|
15
|
+
return 'ts';
|
|
16
|
+
case 'js':
|
|
17
|
+
case 'mjs':
|
|
18
|
+
case 'cjs':
|
|
19
|
+
return 'js';
|
|
20
|
+
case 'jsx':
|
|
21
|
+
return 'jsx';
|
|
22
|
+
case 'css':
|
|
23
|
+
return 'css';
|
|
24
|
+
case 'json':
|
|
25
|
+
return 'json';
|
|
26
|
+
case 'vue':
|
|
27
|
+
return 'vue';
|
|
28
|
+
case 'html':
|
|
29
|
+
return 'html';
|
|
30
|
+
case 'md':
|
|
31
|
+
case 'mdx':
|
|
32
|
+
return 'mdx';
|
|
33
|
+
default:
|
|
34
|
+
return 'tsx';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Caps standalone code blocks whose meta carries `height` at that many pixels,
|
|
39
|
+
* scrolling inside. `auto` (the natural height) is a no-op.
|
|
40
|
+
*/
|
|
41
|
+
export function transformerHeightMeta() {
|
|
42
|
+
return {
|
|
43
|
+
name: 'docs-kit:height-meta',
|
|
44
|
+
pre(node) {
|
|
45
|
+
const match = rawMeta(this).match(HEIGHT_META_RE);
|
|
46
|
+
if (!match)
|
|
47
|
+
return;
|
|
48
|
+
const heightPx = parseDemoHeight(match[1]);
|
|
49
|
+
if (heightPx === 'auto')
|
|
50
|
+
return;
|
|
51
|
+
const prev = node.properties.style ? `${String(node.properties.style).replace(/;\s*$/, '')};` : '';
|
|
52
|
+
node.properties.style = `${prev}max-height:${heightPx}px;overflow:auto`;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Whole quoted specifier, optionally with the space shiki leaves on the token. */
|
|
57
|
+
const QUOTED_RELATIVE_IMPORT_RE = /^(\s*)(['"])(\.\.?\/[^'"]+)\2(\s*)$/;
|
|
58
|
+
/** Path only — dual-theme highlighting splits quotes into their own spans. */
|
|
59
|
+
const BARE_RELATIVE_IMPORT_RE = /^\.\.?\/[^'"]+$/;
|
|
60
|
+
/** POSIX `join` + normalize, enough for relative import specifiers. */
|
|
61
|
+
export function joinPath(...parts) {
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const segment of parts.join('/').split('/')) {
|
|
64
|
+
if (!segment || segment === '.')
|
|
65
|
+
continue;
|
|
66
|
+
if (segment === '..') {
|
|
67
|
+
if (out.length && out[out.length - 1] !== '..')
|
|
68
|
+
out.pop();
|
|
69
|
+
else
|
|
70
|
+
out.push('..');
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
out.push(segment);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return out.join('/');
|
|
77
|
+
}
|
|
78
|
+
export function dirnameOf(filePath) {
|
|
79
|
+
const index = filePath.lastIndexOf('/');
|
|
80
|
+
return index === -1 ? '' : filePath.slice(0, index);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Finds the demo file an import specifier points to. `fromFile` and
|
|
84
|
+
* `fileNames` share one root (e.g. paths relative to the demo's folder).
|
|
85
|
+
*/
|
|
86
|
+
export function matchImportedFile(specifier, fromFile, fileNames) {
|
|
87
|
+
const target = joinPath(dirnameOf(fromFile), specifier);
|
|
88
|
+
return (fileNames.find((name) => name === target) ??
|
|
89
|
+
fileNames.find((name) => name.startsWith(`${target}.`) && !name.slice(target.length + 1).includes('/')) ??
|
|
90
|
+
fileNames.find((name) => name.startsWith(`${target}/index.`)));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Turns relative import specifiers into buttons (`data-demo-file`) that the
|
|
94
|
+
* demo shell uses to switch the active file tab.
|
|
95
|
+
*/
|
|
96
|
+
export function transformerImportFileLinks(fromFile, fileNames) {
|
|
97
|
+
return {
|
|
98
|
+
name: 'docs-kit:import-file-links',
|
|
99
|
+
span(hast, _line, _col, _lineEl, token) {
|
|
100
|
+
const content = token?.content;
|
|
101
|
+
if (!content)
|
|
102
|
+
return;
|
|
103
|
+
const quoted = content.match(QUOTED_RELATIVE_IMPORT_RE);
|
|
104
|
+
const specifier = quoted ? quoted[3] : BARE_RELATIVE_IMPORT_RE.test(content) ? content : null;
|
|
105
|
+
if (!specifier)
|
|
106
|
+
return;
|
|
107
|
+
const file = matchImportedFile(specifier, fromFile, fileNames.filter((name) => name !== fromFile));
|
|
108
|
+
if (!file)
|
|
109
|
+
return;
|
|
110
|
+
// Dual-theme output (and quoted tokens with no extra space): the whole
|
|
111
|
+
// span *is* the specifier, so retag it. Quoted tokens that still include
|
|
112
|
+
// a leading space wrap only the path so the underline doesn't cover it.
|
|
113
|
+
const lead = quoted?.[1];
|
|
114
|
+
const trail = quoted?.[4];
|
|
115
|
+
if (quoted && (lead || trail)) {
|
|
116
|
+
const quotedPath = `${quoted[2]}${specifier}${quoted[2]}`;
|
|
117
|
+
const children = [];
|
|
118
|
+
if (lead)
|
|
119
|
+
children.push({ type: 'text', value: lead });
|
|
120
|
+
children.push({
|
|
121
|
+
type: 'element',
|
|
122
|
+
tagName: 'button',
|
|
123
|
+
properties: { type: 'button', class: 'dk-file-link', 'data-demo-file': file, title: `Open ${file}` },
|
|
124
|
+
children: [{ type: 'text', value: quotedPath }],
|
|
125
|
+
});
|
|
126
|
+
if (trail)
|
|
127
|
+
children.push({ type: 'text', value: trail });
|
|
128
|
+
hast.children = children;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
hast.tagName = 'button';
|
|
132
|
+
hast.properties.type = 'button';
|
|
133
|
+
hast.properties['data-demo-file'] = file;
|
|
134
|
+
hast.properties.title = `Open ${file}`;
|
|
135
|
+
this.addClassToHast(hast, 'dk-file-link');
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function hastText(node) {
|
|
140
|
+
return node.type === 'text' ? (node.value ?? '') : (node.children ?? []).map(hastText).join('');
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Adds a `highlighted` class to the given lines. `#highlight label` labels are
|
|
144
|
+
* appended as `.line-label` on the first line of each block. Without an
|
|
145
|
+
* explicit spec it reads the `{…}` that the remark plugin wrote into the
|
|
146
|
+
* fence meta (for `@shikijs/rehype` pipelines).
|
|
147
|
+
*/
|
|
148
|
+
export function transformerLineHighlight(spec) {
|
|
149
|
+
return {
|
|
150
|
+
name: 'docs-kit:line-highlight',
|
|
151
|
+
preprocess() {
|
|
152
|
+
const meta = metaOf(this);
|
|
153
|
+
if (spec) {
|
|
154
|
+
meta.__dkHighlight = Array.isArray(spec) ? spec : spec.lines;
|
|
155
|
+
meta.__dkHighlightLabels = Array.isArray(spec) ? {} : spec.labels;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const match = rawMeta(this).match(HIGHLIGHT_META_RE);
|
|
159
|
+
const parsed = match ? parseHighlightSpec(match[1]) : { lines: [], labels: {} };
|
|
160
|
+
meta.__dkHighlight = parsed.lines;
|
|
161
|
+
meta.__dkHighlightLabels = parsed.labels;
|
|
162
|
+
},
|
|
163
|
+
line(node, line) {
|
|
164
|
+
const meta = metaOf(this);
|
|
165
|
+
if (meta.__dkHighlight.includes(line))
|
|
166
|
+
this.addClassToHast(node, 'highlighted');
|
|
167
|
+
const label = meta.__dkHighlightLabels[line];
|
|
168
|
+
if (!label)
|
|
169
|
+
return;
|
|
170
|
+
this.addClassToHast(node, 'has-label');
|
|
171
|
+
if (!hastText(node).trim())
|
|
172
|
+
this.addClassToHast(node, 'label-only');
|
|
173
|
+
node.children = [
|
|
174
|
+
{ type: 'element', tagName: 'span', properties: { class: 'line-code' }, children: node.children },
|
|
175
|
+
{
|
|
176
|
+
type: 'element',
|
|
177
|
+
tagName: 'span',
|
|
178
|
+
properties: { class: 'line-label' },
|
|
179
|
+
children: [{ type: 'text', value: label }],
|
|
180
|
+
},
|
|
181
|
+
];
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Gutter line numbers on every line (the `lines` fence flag). With
|
|
187
|
+
* `originalLines` (or `originalLines="12-14"` in the fence meta, written for
|
|
188
|
+
* `region` fences) the gutter shows those file line numbers.
|
|
189
|
+
*/
|
|
190
|
+
export function transformerLineNumbers(originalLines) {
|
|
191
|
+
return {
|
|
192
|
+
name: 'docs-kit:line-numbers',
|
|
193
|
+
preprocess() {
|
|
194
|
+
const meta = metaOf(this);
|
|
195
|
+
if (originalLines) {
|
|
196
|
+
meta.__dkLineNumbers = originalLines;
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const raw = rawMeta(this);
|
|
200
|
+
if (!LINES_META_RE.test(raw)) {
|
|
201
|
+
meta.__dkLineNumbers = null;
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const original = raw.match(ORIGINAL_LINES_META_RE);
|
|
205
|
+
meta.__dkLineNumbers = original ? parseLineRanges(original[1]) : true;
|
|
206
|
+
},
|
|
207
|
+
pre(node) {
|
|
208
|
+
if (metaOf(this).__dkLineNumbers == null)
|
|
209
|
+
return;
|
|
210
|
+
this.addClassToHast(node, 'has-line-numbers');
|
|
211
|
+
},
|
|
212
|
+
line(node, line) {
|
|
213
|
+
const nums = metaOf(this).__dkLineNumbers;
|
|
214
|
+
if (nums == null)
|
|
215
|
+
return;
|
|
216
|
+
const n = Array.isArray(nums) ? nums[line - 1] : line;
|
|
217
|
+
if (n == null)
|
|
218
|
+
return;
|
|
219
|
+
node.properties['data-line'] = String(n);
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/** The transformers a markdown-level `@shikijs/rehype` pipeline needs for remark-processed fences. */
|
|
224
|
+
export function fenceTransformers() {
|
|
225
|
+
return [transformerLineHighlight(), transformerLineNumbers(), transformerHeightMeta()];
|
|
226
|
+
}
|
|
227
|
+
/** Highlights code to HTML with dual themes (CSS variables) and the docs transformers. */
|
|
228
|
+
export async function highlightCode(code, options) {
|
|
229
|
+
const transformers = [];
|
|
230
|
+
if (options.highlight?.lines.length)
|
|
231
|
+
transformers.push(transformerLineHighlight(options.highlight));
|
|
232
|
+
if (options.lineNumbers)
|
|
233
|
+
transformers.push(transformerLineNumbers(options.lineNumbers));
|
|
234
|
+
if (options.importLinks?.fileNames.length) {
|
|
235
|
+
transformers.push(transformerImportFileLinks(options.importLinks.fromFile, options.importLinks.fileNames));
|
|
236
|
+
}
|
|
237
|
+
return codeToHtml(code, {
|
|
238
|
+
lang: options.lang,
|
|
239
|
+
themes: options.themes ?? DEFAULT_CODE_THEMES,
|
|
240
|
+
defaultColor: false,
|
|
241
|
+
transformers,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=shiki.js.map
|