@temelj/mdx 0.14.0 → 0.15.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/README.md +468 -82
- package/dist/character-entities.d.mts +4 -0
- package/dist/character-entities.d.mts.map +1 -0
- package/dist/character-entities.mjs +2132 -0
- package/dist/character-entities.mjs.map +1 -0
- package/dist/character-reference.d.mts +6 -0
- package/dist/character-reference.d.mts.map +1 -0
- package/dist/character-reference.mjs +18 -0
- package/dist/character-reference.mjs.map +1 -0
- package/dist/compile-analysis.d.mts +28 -0
- package/dist/compile-analysis.d.mts.map +1 -0
- package/dist/compile-analysis.mjs +74 -0
- package/dist/compile-analysis.mjs.map +1 -0
- package/dist/compile-emit.d.mts +9 -0
- package/dist/compile-emit.d.mts.map +1 -0
- package/dist/compile-emit.mjs +187 -0
- package/dist/compile-emit.mjs.map +1 -0
- package/dist/compile-esm.d.mts +34 -0
- package/dist/compile-esm.d.mts.map +1 -0
- package/dist/compile-esm.mjs +187 -0
- package/dist/compile-esm.mjs.map +1 -0
- package/dist/compile-names.d.mts +13 -0
- package/dist/compile-names.d.mts.map +1 -0
- package/dist/compile-names.mjs +32 -0
- package/dist/compile-names.mjs.map +1 -0
- package/dist/compiler.d.mts +69 -85
- package/dist/compiler.d.mts.map +1 -1
- package/dist/compiler.mjs +185 -418
- package/dist/compiler.mjs.map +1 -1
- package/dist/diagnostics.d.mts +37 -0
- package/dist/diagnostics.d.mts.map +1 -0
- package/dist/diagnostics.mjs +57 -0
- package/dist/diagnostics.mjs.map +1 -0
- package/dist/errors.d.mts +157 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +263 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/footnote-numbering.d.mts +27 -0
- package/dist/footnote-numbering.d.mts.map +1 -0
- package/dist/footnote-numbering.mjs +49 -0
- package/dist/footnote-numbering.mjs.map +1 -0
- package/dist/format-context.d.mts +46 -0
- package/dist/format-context.d.mts.map +1 -0
- package/dist/format-context.mjs +26 -0
- package/dist/format-context.mjs.map +1 -0
- package/dist/format-directive.d.mts +9 -0
- package/dist/format-directive.d.mts.map +1 -0
- package/dist/format-directive.mjs +99 -0
- package/dist/format-directive.mjs.map +1 -0
- package/dist/format-jsx.d.mts +8 -0
- package/dist/format-jsx.d.mts.map +1 -0
- package/dist/format-jsx.mjs +47 -0
- package/dist/format-jsx.mjs.map +1 -0
- package/dist/format-math.d.mts +9 -0
- package/dist/format-math.d.mts.map +1 -0
- package/dist/format-math.mjs +79 -0
- package/dist/format-math.mjs.map +1 -0
- package/dist/format-safe.d.mts +25 -0
- package/dist/format-safe.d.mts.map +1 -0
- package/dist/format-safe.mjs +366 -0
- package/dist/format-safe.mjs.map +1 -0
- package/dist/format-table.d.mts +8 -0
- package/dist/format-table.d.mts.map +1 -0
- package/dist/format-table.mjs +55 -0
- package/dist/format-table.mjs.map +1 -0
- package/dist/format-track.d.mts +18 -0
- package/dist/format-track.d.mts.map +1 -0
- package/dist/format-track.mjs +34 -0
- package/dist/format-track.mjs.map +1 -0
- package/dist/format.d.mts +7 -0
- package/dist/format.d.mts.map +1 -0
- package/dist/format.mjs +549 -0
- package/dist/format.mjs.map +1 -0
- package/dist/frontmatter.d.mts +15 -0
- package/dist/frontmatter.d.mts.map +1 -0
- package/dist/frontmatter.mjs +187 -0
- package/dist/frontmatter.mjs.map +1 -0
- package/dist/heading.d.mts +6 -0
- package/dist/heading.d.mts.map +1 -0
- package/dist/heading.mjs +19 -0
- package/dist/heading.mjs.map +1 -0
- package/dist/html-format.d.mts +32 -0
- package/dist/html-format.d.mts.map +1 -0
- package/dist/html-format.mjs +127 -0
- package/dist/html-format.mjs.map +1 -0
- package/dist/html-lower.d.mts +78 -0
- package/dist/html-lower.d.mts.map +1 -0
- package/dist/html-lower.mjs +583 -0
- package/dist/html-lower.mjs.map +1 -0
- package/dist/html-stream.d.mts +13 -0
- package/dist/html-stream.d.mts.map +1 -0
- package/dist/html-stream.mjs +32 -0
- package/dist/html-stream.mjs.map +1 -0
- package/dist/html.d.mts +120 -0
- package/dist/html.d.mts.map +1 -0
- package/dist/html.mjs +77 -0
- package/dist/html.mjs.map +1 -0
- package/dist/identifier.d.mts +4 -0
- package/dist/identifier.d.mts.map +1 -0
- package/dist/identifier.mjs +8 -0
- package/dist/identifier.mjs.map +1 -0
- package/dist/javascript-ast.d.mts +16 -0
- package/dist/javascript-ast.d.mts.map +1 -0
- package/dist/javascript-ast.mjs +39 -0
- package/dist/javascript-ast.mjs.map +1 -0
- package/dist/javascript-jsx.d.mts +24 -0
- package/dist/javascript-jsx.d.mts.map +1 -0
- package/dist/javascript-jsx.mjs +189 -0
- package/dist/javascript-jsx.mjs.map +1 -0
- package/dist/javascript.d.mts +9 -0
- package/dist/javascript.d.mts.map +1 -0
- package/dist/javascript.mjs +31 -0
- package/dist/javascript.mjs.map +1 -0
- package/dist/jsx-reference.d.mts +15 -0
- package/dist/jsx-reference.d.mts.map +1 -0
- package/dist/jsx-reference.mjs +31 -0
- package/dist/jsx-reference.mjs.map +1 -0
- package/dist/mod.d.mts +25 -9
- package/dist/mod.mjs +19 -8
- package/dist/model.d.mts +196 -0
- package/dist/model.d.mts.map +1 -0
- package/dist/model.mjs +113 -0
- package/dist/model.mjs.map +1 -0
- package/dist/parser/block-container-recognizers.d.mts +40 -0
- package/dist/parser/block-container-recognizers.d.mts.map +1 -0
- package/dist/parser/block-container-recognizers.mjs +90 -0
- package/dist/parser/block-container-recognizers.mjs.map +1 -0
- package/dist/parser/block-directive-recognizers.d.mts +22 -0
- package/dist/parser/block-directive-recognizers.d.mts.map +1 -0
- package/dist/parser/block-directive-recognizers.mjs +77 -0
- package/dist/parser/block-directive-recognizers.mjs.map +1 -0
- package/dist/parser/block-leaf-recognizers.d.mts +53 -0
- package/dist/parser/block-leaf-recognizers.d.mts.map +1 -0
- package/dist/parser/block-leaf-recognizers.mjs +386 -0
- package/dist/parser/block-leaf-recognizers.mjs.map +1 -0
- package/dist/parser/block-parser.d.mts +38 -0
- package/dist/parser/block-parser.d.mts.map +1 -0
- package/dist/parser/block-parser.mjs +895 -0
- package/dist/parser/block-parser.mjs.map +1 -0
- package/dist/parser/block-syntax.d.mts +240 -0
- package/dist/parser/block-syntax.d.mts.map +1 -0
- package/dist/parser/characters.d.mts +19 -0
- package/dist/parser/characters.d.mts.map +1 -0
- package/dist/parser/characters.mjs +52 -0
- package/dist/parser/characters.mjs.map +1 -0
- package/dist/parser/config.d.mts +16 -0
- package/dist/parser/config.d.mts.map +1 -0
- package/dist/parser/config.mjs +25 -0
- package/dist/parser/config.mjs.map +1 -0
- package/dist/parser/directive-attributes.d.mts +9 -0
- package/dist/parser/directive-attributes.d.mts.map +1 -0
- package/dist/parser/directive-attributes.mjs +24 -0
- package/dist/parser/directive-attributes.mjs.map +1 -0
- package/dist/parser/embedded-scanner.d.mts +18 -0
- package/dist/parser/embedded-scanner.d.mts.map +1 -0
- package/dist/parser/embedded-scanner.mjs +199 -0
- package/dist/parser/embedded-scanner.mjs.map +1 -0
- package/dist/parser/inline-autolink.d.mts +7 -0
- package/dist/parser/inline-autolink.d.mts.map +1 -0
- package/dist/parser/inline-autolink.mjs +42 -0
- package/dist/parser/inline-autolink.mjs.map +1 -0
- package/dist/parser/inline-character-reference.d.mts +7 -0
- package/dist/parser/inline-character-reference.d.mts.map +1 -0
- package/dist/parser/inline-character-reference.mjs +22 -0
- package/dist/parser/inline-character-reference.mjs.map +1 -0
- package/dist/parser/inline-code.d.mts +7 -0
- package/dist/parser/inline-code.d.mts.map +1 -0
- package/dist/parser/inline-code.mjs +29 -0
- package/dist/parser/inline-code.mjs.map +1 -0
- package/dist/parser/inline-directive.d.mts +9 -0
- package/dist/parser/inline-directive.d.mts.map +1 -0
- package/dist/parser/inline-directive.mjs +45 -0
- package/dist/parser/inline-directive.mjs.map +1 -0
- package/dist/parser/inline-embedded.d.mts +19 -0
- package/dist/parser/inline-embedded.d.mts.map +1 -0
- package/dist/parser/inline-embedded.mjs +92 -0
- package/dist/parser/inline-embedded.mjs.map +1 -0
- package/dist/parser/inline-emphasis.d.mts +11 -0
- package/dist/parser/inline-emphasis.d.mts.map +1 -0
- package/dist/parser/inline-emphasis.mjs +79 -0
- package/dist/parser/inline-emphasis.mjs.map +1 -0
- package/dist/parser/inline-input.d.mts +46 -0
- package/dist/parser/inline-input.d.mts.map +1 -0
- package/dist/parser/inline-input.mjs +137 -0
- package/dist/parser/inline-input.mjs.map +1 -0
- package/dist/parser/inline-link.d.mts +12 -0
- package/dist/parser/inline-link.d.mts.map +1 -0
- package/dist/parser/inline-link.mjs +187 -0
- package/dist/parser/inline-link.mjs.map +1 -0
- package/dist/parser/inline-math.d.mts +10 -0
- package/dist/parser/inline-math.d.mts.map +1 -0
- package/dist/parser/inline-math.mjs +46 -0
- package/dist/parser/inline-math.mjs.map +1 -0
- package/dist/parser/inline-output.d.mts +34 -0
- package/dist/parser/inline-output.d.mts.map +1 -0
- package/dist/parser/inline-output.mjs +62 -0
- package/dist/parser/inline-output.mjs.map +1 -0
- package/dist/parser/inline-parser.d.mts +14 -0
- package/dist/parser/inline-parser.d.mts.map +1 -0
- package/dist/parser/inline-parser.mjs +328 -0
- package/dist/parser/inline-parser.mjs.map +1 -0
- package/dist/parser/inline-pending.d.mts +23 -0
- package/dist/parser/inline-pending.d.mts.map +1 -0
- package/dist/parser/inline-pending.mjs +100 -0
- package/dist/parser/inline-pending.mjs.map +1 -0
- package/dist/parser/inline-syntax.d.mts +118 -0
- package/dist/parser/inline-syntax.d.mts.map +1 -0
- package/dist/parser/inline-syntax.mjs +1 -0
- package/dist/parser/javascript-boundary.d.mts +16 -0
- package/dist/parser/javascript-boundary.d.mts.map +1 -0
- package/dist/parser/javascript-boundary.mjs +42 -0
- package/dist/parser/javascript-boundary.mjs.map +1 -0
- package/dist/parser/javascript-scanner.d.mts +22 -0
- package/dist/parser/javascript-scanner.d.mts.map +1 -0
- package/dist/parser/javascript-scanner.mjs +122 -0
- package/dist/parser/javascript-scanner.mjs.map +1 -0
- package/dist/parser/materialize-cache.d.mts +34 -0
- package/dist/parser/materialize-cache.d.mts.map +1 -0
- package/dist/parser/materialize-cache.mjs +12 -0
- package/dist/parser/materialize-cache.mjs.map +1 -0
- package/dist/parser/materialize-jsx.d.mts +14 -0
- package/dist/parser/materialize-jsx.d.mts.map +1 -0
- package/dist/parser/materialize-jsx.mjs +76 -0
- package/dist/parser/materialize-jsx.mjs.map +1 -0
- package/dist/parser/materialize.d.mts +61 -0
- package/dist/parser/materialize.d.mts.map +1 -0
- package/dist/parser/materialize.mjs +736 -0
- package/dist/parser/materialize.mjs.map +1 -0
- package/dist/parser/recognizer.d.mts +20 -0
- package/dist/parser/recognizer.d.mts.map +1 -0
- package/dist/parser/recognizer.mjs +24 -0
- package/dist/parser/recognizer.mjs.map +1 -0
- package/dist/parser/session.d.mts +42 -0
- package/dist/parser/session.d.mts.map +1 -0
- package/dist/parser/session.mjs +89 -0
- package/dist/parser/session.mjs.map +1 -0
- package/dist/parser.d.mts +25 -0
- package/dist/parser.d.mts.map +1 -0
- package/dist/parser.mjs +37 -0
- package/dist/parser.mjs.map +1 -0
- package/dist/plugin-internal.d.mts +25 -0
- package/dist/plugin-internal.d.mts.map +1 -0
- package/dist/plugin-internal.mjs +99 -0
- package/dist/plugin-internal.mjs.map +1 -0
- package/dist/plugin.d.mts +37 -0
- package/dist/plugin.d.mts.map +1 -0
- package/dist/plugin.mjs +1 -0
- package/dist/plugins/code-block-metadata.d.mts +42 -0
- package/dist/plugins/code-block-metadata.d.mts.map +1 -0
- package/dist/plugins/code-block-metadata.mjs +133 -0
- package/dist/plugins/code-block-metadata.mjs.map +1 -0
- package/dist/plugins/heading-id.d.mts +15 -0
- package/dist/plugins/heading-id.d.mts.map +1 -0
- package/dist/plugins/heading-id.mjs +45 -0
- package/dist/plugins/heading-id.mjs.map +1 -0
- package/dist/plugins/lower-heading.d.mts +16 -0
- package/dist/plugins/lower-heading.d.mts.map +1 -0
- package/dist/plugins/lower-heading.mjs +28 -0
- package/dist/plugins/lower-heading.mjs.map +1 -0
- package/dist/plugins/math-render.d.mts +26 -0
- package/dist/plugins/math-render.d.mts.map +1 -0
- package/dist/plugins/math-render.mjs +51 -0
- package/dist/plugins/math-render.mjs.map +1 -0
- package/dist/plugins/mod.d.mts +9 -6
- package/dist/plugins/mod.mjs +8 -6
- package/dist/plugins/remove-esm.d.mts +10 -0
- package/dist/plugins/remove-esm.d.mts.map +1 -0
- package/dist/plugins/remove-esm.mjs +12 -0
- package/dist/plugins/remove-esm.mjs.map +1 -0
- package/dist/plugins/shiki.d.mts +21 -0
- package/dist/plugins/shiki.d.mts.map +1 -0
- package/dist/plugins/shiki.mjs +144 -0
- package/dist/plugins/shiki.mjs.map +1 -0
- package/dist/plugins/syntax-highlight.d.mts +38 -0
- package/dist/plugins/syntax-highlight.d.mts.map +1 -0
- package/dist/plugins/syntax-highlight.mjs +106 -0
- package/dist/plugins/syntax-highlight.mjs.map +1 -0
- package/dist/processor.d.mts +60 -0
- package/dist/processor.d.mts.map +1 -0
- package/dist/processor.mjs +106 -0
- package/dist/processor.mjs.map +1 -0
- package/dist/ranges.d.mts +10 -0
- package/dist/ranges.d.mts.map +1 -0
- package/dist/ranges.mjs +22 -0
- package/dist/ranges.mjs.map +1 -0
- package/dist/source-map.d.mts +28 -0
- package/dist/source-map.d.mts.map +1 -0
- package/dist/source-map.mjs +90 -0
- package/dist/source-map.mjs.map +1 -0
- package/dist/source-text.d.mts +35 -0
- package/dist/source-text.d.mts.map +1 -0
- package/dist/source-text.mjs +132 -0
- package/dist/source-text.mjs.map +1 -0
- package/dist/source.d.mts +86 -0
- package/dist/source.d.mts.map +1 -0
- package/dist/source.mjs +264 -0
- package/dist/source.mjs.map +1 -0
- package/dist/stream-events.d.mts +59 -0
- package/dist/stream-events.d.mts.map +1 -0
- package/dist/stream-events.mjs +115 -0
- package/dist/stream-events.mjs.map +1 -0
- package/dist/stream-session.d.mts +79 -0
- package/dist/stream-session.d.mts.map +1 -0
- package/dist/stream-session.mjs +904 -0
- package/dist/stream-session.mjs.map +1 -0
- package/dist/stream-tail.d.mts +84 -0
- package/dist/stream-tail.d.mts.map +1 -0
- package/dist/stream-tail.mjs +359 -0
- package/dist/stream-tail.mjs.map +1 -0
- package/dist/stream-types.d.mts +89 -0
- package/dist/stream-types.d.mts.map +1 -0
- package/dist/stream-types.mjs +1 -0
- package/dist/stream.d.mts +28 -0
- package/dist/stream.d.mts.map +1 -0
- package/dist/stream.mjs +68 -0
- package/dist/stream.mjs.map +1 -0
- package/dist/syntax-options.d.mts +21 -0
- package/dist/syntax-options.d.mts.map +1 -0
- package/dist/syntax-options.mjs +26 -0
- package/dist/syntax-options.mjs.map +1 -0
- package/dist/traversal.d.mts +25 -0
- package/dist/traversal.d.mts.map +1 -0
- package/dist/traversal.mjs +136 -0
- package/dist/traversal.mjs.map +1 -0
- package/dist/tree.d.mts +18 -0
- package/dist/tree.d.mts.map +1 -0
- package/dist/tree.mjs +43 -0
- package/dist/tree.mjs.map +1 -0
- package/dist/unified/adapter.d.mts +24 -0
- package/dist/unified/adapter.d.mts.map +1 -0
- package/dist/unified/adapter.mjs +44 -0
- package/dist/unified/adapter.mjs.map +1 -0
- package/dist/unified/mod.d.mts +2 -0
- package/dist/unified/mod.mjs +1 -0
- package/dist/unified/runtime.d.mts +10 -0
- package/dist/unified/runtime.d.mts.map +1 -0
- package/dist/unified/runtime.mjs +115 -0
- package/dist/unified/runtime.mjs.map +1 -0
- package/dist/unified/tree-bridge.d.mts +63 -0
- package/dist/unified/tree-bridge.d.mts.map +1 -0
- package/dist/unified/tree-bridge.mjs +876 -0
- package/dist/unified/tree-bridge.mjs.map +1 -0
- package/dist/uri.d.mts +5 -0
- package/dist/uri.d.mts.map +1 -0
- package/dist/uri.mjs +32 -0
- package/dist/uri.mjs.map +1 -0
- package/package.json +56 -30
- package/dist/plugins/heading-id/plugin.d.mts +0 -17
- package/dist/plugins/heading-id/plugin.d.mts.map +0 -1
- package/dist/plugins/heading-id/plugin.mjs +0 -23
- package/dist/plugins/heading-id/plugin.mjs.map +0 -1
- package/dist/plugins/katex/plugin.d.mts +0 -39
- package/dist/plugins/katex/plugin.d.mts.map +0 -1
- package/dist/plugins/katex/plugin.mjs +0 -107
- package/dist/plugins/katex/plugin.mjs.map +0 -1
- package/dist/plugins/remove-imports-exports.d.mts +0 -10
- package/dist/plugins/remove-imports-exports.d.mts.map +0 -1
- package/dist/plugins/remove-imports-exports.mjs +0 -15
- package/dist/plugins/remove-imports-exports.mjs.map +0 -1
- package/dist/plugins/syntax-highlight/code-meta.d.mts +0 -22
- package/dist/plugins/syntax-highlight/code-meta.d.mts.map +0 -1
- package/dist/plugins/syntax-highlight/code-meta.mjs +0 -38
- package/dist/plugins/syntax-highlight/code-meta.mjs.map +0 -1
- package/dist/plugins/syntax-highlight/plugin.d.mts +0 -57
- package/dist/plugins/syntax-highlight/plugin.d.mts.map +0 -1
- package/dist/plugins/syntax-highlight/plugin.mjs +0 -93
- package/dist/plugins/syntax-highlight/plugin.mjs.map +0 -1
- package/dist/plugins/tree-processor/plugin.d.mts +0 -19
- package/dist/plugins/tree-processor/plugin.d.mts.map +0 -1
- package/dist/plugins/tree-processor/plugin.mjs +0 -21
- package/dist/plugins/tree-processor/plugin.mjs.map +0 -1
- package/dist/types.d.mts +0 -2
- /package/dist/{types.mjs → parser/block-syntax.mjs} +0 -0
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { HastNode as Node } from "../../types.mjs";
|
|
2
|
-
import { TransformerNotationHighlightOptions } from "@shikijs/transformers";
|
|
3
|
-
import { BundledLanguage, BundledTheme, CodeToHastOptions } from "shiki";
|
|
4
|
-
import { Plugin } from "unified";
|
|
5
|
-
//#region src/plugins/syntax-highlight/plugin.d.ts
|
|
6
|
-
type ShikiHastOptions = Partial<CodeToHastOptions<BundledLanguage, BundledTheme>>;
|
|
7
|
-
type SyntaxDataAttribute = "source-code" | "language" | "line-count";
|
|
8
|
-
/**
|
|
9
|
-
* Options for {@linkcode syntaxHighlightPlugin}.
|
|
10
|
-
*/
|
|
11
|
-
interface SyntaxHighlightPluginOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Include these data attributes on the `<pre>` element.
|
|
14
|
-
* These might be useful to have when building custom code components.
|
|
15
|
-
*/
|
|
16
|
-
includeDataAttributes?: SyntaxDataAttribute[];
|
|
17
|
-
/**
|
|
18
|
-
* Options for the highlight transformer.
|
|
19
|
-
*/
|
|
20
|
-
highlight?: {
|
|
21
|
-
transformer?: TransformerNotationHighlightOptions;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Options for line numbers.
|
|
25
|
-
*/
|
|
26
|
-
lineNumbers?: {
|
|
27
|
-
/**
|
|
28
|
-
* The name of the variable that contains the line number width.
|
|
29
|
-
* This is used for padding the line numbers so that they align.
|
|
30
|
-
*/
|
|
31
|
-
widthVariableName?: string;
|
|
32
|
-
/**
|
|
33
|
-
* A class name to be added to the line numbers.
|
|
34
|
-
*/
|
|
35
|
-
className?: string;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Options for command line.
|
|
39
|
-
*/
|
|
40
|
-
commandLine?: {
|
|
41
|
-
/**
|
|
42
|
-
* A class name to be added to the prompt line.
|
|
43
|
-
*/
|
|
44
|
-
className?: string;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Extra options for the Shiki hast transformer.
|
|
48
|
-
*/
|
|
49
|
-
shikiHastOptions?: ShikiHastOptions;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* A plugin that highlights code blocks using Shiki.
|
|
53
|
-
*/
|
|
54
|
-
declare const syntaxHighlightPlugin: Plugin<[SyntaxHighlightPluginOptions?], Node, Node>;
|
|
55
|
-
//#endregion
|
|
56
|
-
export { SyntaxHighlightPluginOptions, syntaxHighlightPlugin };
|
|
57
|
-
//# sourceMappingURL=plugin.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../../../src/plugins/syntax-highlight/plugin.ts"],"mappings":";;;;;KAsBK,mBAAmB,QAAQ,kBAAkB,iBAAiB;KAE9D;;;;UAKY;;;;;EAKf,wBAAwB;;;;EAKxB;IACE,cAAc;;;;;EAMhB;;;;;IAKE;;;;IAIA;;;;;EAMF;;;;IAIE;;;;;EAMF,mBAAmB;;;;;cAMR,uBAAuB,QAAQ,gCAAgC,MAAU"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { extractCodeMeta } from "./code-meta.mjs";
|
|
2
|
-
import { toString } from "hast-util-to-string";
|
|
3
|
-
import { visit } from "unist-util-visit";
|
|
4
|
-
import { transformerNotationHighlight } from "@shikijs/transformers";
|
|
5
|
-
import { numericRangeContains } from "@temelj/iterator";
|
|
6
|
-
import { ShikiError, codeToHast } from "shiki";
|
|
7
|
-
//#region src/plugins/syntax-highlight/plugin.ts
|
|
8
|
-
/**
|
|
9
|
-
* A plugin that highlights code blocks using Shiki.
|
|
10
|
-
*/
|
|
11
|
-
const syntaxHighlightPlugin = (options = {}) => {
|
|
12
|
-
return async (tree) => {
|
|
13
|
-
const promises = [];
|
|
14
|
-
async function visitor(node, index, parent) {
|
|
15
|
-
if (!parent || index === null || node.tagName !== "pre") return;
|
|
16
|
-
const codeNode = node.children[0];
|
|
17
|
-
if (!codeNode || codeNode.type !== "element" || codeNode.tagName !== "code" || !codeNode.properties) return;
|
|
18
|
-
const lang = getNodeLanguage(codeNode);
|
|
19
|
-
if (typeof lang !== "string") return;
|
|
20
|
-
const meta = extractCodeMeta(codeNode);
|
|
21
|
-
const sourceCode = toString(codeNode).trim();
|
|
22
|
-
const hastOptions = {
|
|
23
|
-
tokenizeTimeLimit: 1e4,
|
|
24
|
-
lang,
|
|
25
|
-
themes: {
|
|
26
|
-
light: "github-light-default",
|
|
27
|
-
dark: "github-dark-default"
|
|
28
|
-
},
|
|
29
|
-
...options.shikiHastOptions
|
|
30
|
-
};
|
|
31
|
-
if (hastOptions.transformers === void 0) hastOptions.transformers = [];
|
|
32
|
-
if (options.highlight) hastOptions.transformers.push(transformerNotationHighlight({
|
|
33
|
-
...options.highlight.transformer,
|
|
34
|
-
matchAlgorithm: "v3"
|
|
35
|
-
}));
|
|
36
|
-
let lineCount = 0;
|
|
37
|
-
hastOptions.transformers.push({ code(node) {
|
|
38
|
-
let lineIndex = 0;
|
|
39
|
-
for (const line of node.children.filter((node) => node.type === "element")) {
|
|
40
|
-
line.properties["data-line"] = lineIndex + 1;
|
|
41
|
-
if (options.highlight) {
|
|
42
|
-
if (meta.highlight && numericRangeContains(meta.highlight.lineRange, lineIndex)) this.addClassToHast(line, options.highlight.transformer?.classActiveLine ?? "highlighted");
|
|
43
|
-
}
|
|
44
|
-
if (options.lineNumbers && meta.showLineNumbers && (meta.showLineNumbers.lineRange.length === 0 || numericRangeContains(meta.showLineNumbers.lineRange, lineIndex))) this.addClassToHast(line, options.lineNumbers.className ?? "line-number");
|
|
45
|
-
if (options.commandLine && meta.commandLine && (meta.commandLine.commandRange.length === 0 || numericRangeContains(meta.commandLine.commandRange, lineIndex))) this.addClassToHast(line, options.commandLine.className ?? "line-command");
|
|
46
|
-
lineIndex++;
|
|
47
|
-
}
|
|
48
|
-
lineCount = lineIndex;
|
|
49
|
-
if (meta.showLineNumbers) {
|
|
50
|
-
if (typeof node.properties.style !== "string") node.properties.style = "";
|
|
51
|
-
node.properties.style += `--${options.lineNumbers?.widthVariableName ?? "line-number-width"}:${1 + Math.floor(Math.log10(this.lines.length))}ch;`;
|
|
52
|
-
}
|
|
53
|
-
} });
|
|
54
|
-
try {
|
|
55
|
-
const hastPre = (await codeToHast(sourceCode, hastOptions)).children[0];
|
|
56
|
-
const properties = {
|
|
57
|
-
...hastPre.properties,
|
|
58
|
-
dataFileName: meta.fileName
|
|
59
|
-
};
|
|
60
|
-
if (options.includeDataAttributes) {
|
|
61
|
-
if (options.includeDataAttributes.includes("language")) properties.dataLanguage = lang;
|
|
62
|
-
if (options.includeDataAttributes.includes("source-code")) properties.dataSourceCode = sourceCode;
|
|
63
|
-
if (options.includeDataAttributes.includes("line-count")) properties.dataLineCount = lineCount;
|
|
64
|
-
}
|
|
65
|
-
parent.children.splice(index, 1, {
|
|
66
|
-
...hastPre,
|
|
67
|
-
properties
|
|
68
|
-
});
|
|
69
|
-
} catch (error) {
|
|
70
|
-
if (error instanceof ShikiError) {
|
|
71
|
-
if (error.message.includes("Language `math` is not included in this bundle")) return;
|
|
72
|
-
}
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
visit(tree, "element", (node, index, parent) => {
|
|
77
|
-
promises.push(visitor(node, index, parent));
|
|
78
|
-
});
|
|
79
|
-
await Promise.all(promises);
|
|
80
|
-
return tree;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
function getNodeLanguage(node) {
|
|
84
|
-
if (!Array.isArray(node.properties.className)) return;
|
|
85
|
-
const prefix = "language-";
|
|
86
|
-
const language = node.properties.className.find((name) => typeof name === "string" && name.startsWith(prefix));
|
|
87
|
-
if (typeof language === "string") return language.slice(9);
|
|
88
|
-
return language;
|
|
89
|
-
}
|
|
90
|
-
//#endregion
|
|
91
|
-
export { syntaxHighlightPlugin };
|
|
92
|
-
|
|
93
|
-
//# sourceMappingURL=plugin.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":["hastToString"],"sources":["../../../src/plugins/syntax-highlight/plugin.ts"],"sourcesContent":["import type { Properties } from \"hast\";\nimport type { Plugin } from \"unified\";\n\nimport {\n type TransformerNotationHighlightOptions,\n transformerNotationHighlight,\n} from \"@shikijs/transformers\";\nimport { numericRangeContains } from \"@temelj/iterator\";\nimport { toString as hastToString } from \"hast-util-to-string\";\nimport {\n type BundledLanguage,\n type BundledTheme,\n type CodeToHastOptions,\n codeToHast,\n ShikiError,\n} from \"shiki\";\nimport { visit } from \"unist-util-visit\";\n\nimport type { HastElement, HastNode } from \"../../types\";\n\nimport { extractCodeMeta } from \"./code-meta\";\n\ntype ShikiHastOptions = Partial<CodeToHastOptions<BundledLanguage, BundledTheme>>;\n\ntype SyntaxDataAttribute = \"source-code\" | \"language\" | \"line-count\";\n\n/**\n * Options for {@linkcode syntaxHighlightPlugin}.\n */\nexport interface SyntaxHighlightPluginOptions {\n /**\n * Include these data attributes on the `<pre>` element.\n * These might be useful to have when building custom code components.\n */\n includeDataAttributes?: SyntaxDataAttribute[];\n\n /**\n * Options for the highlight transformer.\n */\n highlight?: {\n transformer?: TransformerNotationHighlightOptions;\n };\n\n /**\n * Options for line numbers.\n */\n lineNumbers?: {\n /**\n * The name of the variable that contains the line number width.\n * This is used for padding the line numbers so that they align.\n */\n widthVariableName?: string;\n /**\n * A class name to be added to the line numbers.\n */\n className?: string;\n };\n\n /**\n * Options for command line.\n */\n commandLine?: {\n /**\n * A class name to be added to the prompt line.\n */\n className?: string;\n };\n\n /**\n * Extra options for the Shiki hast transformer.\n */\n shikiHastOptions?: ShikiHastOptions;\n}\n\n/**\n * A plugin that highlights code blocks using Shiki.\n */\nexport const syntaxHighlightPlugin: Plugin<[SyntaxHighlightPluginOptions?], HastNode, HastNode> = (\n options: SyntaxHighlightPluginOptions = {},\n) => {\n return async (tree) => {\n const promises: Promise<void>[] = [];\n\n async function visitor(node: HastElement, index: number, parent: HastElement): Promise<void> {\n if (!parent || index === null || node.tagName !== \"pre\") {\n return;\n }\n\n const codeNode = node.children[0];\n if (\n !codeNode ||\n codeNode.type !== \"element\" ||\n codeNode.tagName !== \"code\" ||\n !codeNode.properties\n ) {\n return;\n }\n\n const lang = getNodeLanguage(codeNode);\n if (typeof lang !== \"string\") {\n return;\n }\n\n const meta = extractCodeMeta(codeNode);\n\n const sourceCode = hastToString(codeNode).trim();\n\n const hastOptions: CodeToHastOptions<BundledLanguage, BundledTheme> = {\n tokenizeTimeLimit: 10_000,\n lang,\n themes: {\n light: \"github-light-default\",\n dark: \"github-dark-default\",\n },\n ...options.shikiHastOptions,\n };\n if (hastOptions.transformers === undefined) {\n hastOptions.transformers = [];\n }\n\n if (options.highlight) {\n hastOptions.transformers.push(\n transformerNotationHighlight({\n ...options.highlight.transformer,\n matchAlgorithm: \"v3\",\n }),\n );\n }\n\n let lineCount = 0;\n hastOptions.transformers.push({\n code(node): void {\n let lineIndex = 0;\n for (const line of node.children.filter(\n (node: HastNode) => node.type === \"element\",\n ) as HastElement[]) {\n line.properties[\"data-line\"] = lineIndex + 1;\n\n if (options.highlight) {\n if (meta.highlight && numericRangeContains(meta.highlight.lineRange, lineIndex)) {\n this.addClassToHast(\n line,\n options.highlight.transformer?.classActiveLine ?? \"highlighted\",\n );\n }\n }\n\n if (\n options.lineNumbers &&\n meta.showLineNumbers &&\n (meta.showLineNumbers.lineRange.length === 0 ||\n numericRangeContains(meta.showLineNumbers.lineRange, lineIndex))\n ) {\n this.addClassToHast(line, options.lineNumbers.className ?? \"line-number\");\n }\n\n if (\n options.commandLine &&\n meta.commandLine &&\n (meta.commandLine.commandRange.length === 0 ||\n numericRangeContains(meta.commandLine.commandRange, lineIndex))\n ) {\n this.addClassToHast(line, options.commandLine.className ?? \"line-command\");\n }\n\n lineIndex++;\n }\n\n lineCount = lineIndex;\n\n if (meta.showLineNumbers) {\n if (typeof node.properties.style !== \"string\") {\n node.properties.style = \"\";\n }\n node.properties.style += `--${\n options.lineNumbers?.widthVariableName ?? \"line-number-width\"\n }:${1 + Math.floor(Math.log10(this.lines.length))}ch;`;\n }\n },\n });\n\n try {\n const hast = await codeToHast(sourceCode, hastOptions);\n\n // Insert highlighted code into parent\n const hastPre = hast.children[0] as HastElement;\n\n const properties: Properties = {\n ...hastPre.properties,\n dataFileName: meta.fileName,\n };\n if (options.includeDataAttributes) {\n if (options.includeDataAttributes.includes(\"language\")) {\n properties.dataLanguage = lang;\n }\n if (options.includeDataAttributes.includes(\"source-code\")) {\n properties.dataSourceCode = sourceCode;\n }\n if (options.includeDataAttributes.includes(\"line-count\")) {\n properties.dataLineCount = lineCount;\n }\n }\n\n parent.children.splice(index, 1, {\n ...hastPre,\n properties,\n });\n } catch (error) {\n if (error instanceof ShikiError) {\n if (error.message.includes(\"Language `math` is not included in this bundle\")) {\n // Skip if the block is math block.\n return;\n }\n }\n throw error;\n }\n }\n\n visit(tree, \"element\", (node: HastElement, index: number, parent: HastElement) => {\n promises.push(visitor(node, index, parent));\n });\n\n await Promise.all(promises);\n\n return tree;\n };\n};\n\nfunction getNodeLanguage(node: HastElement): string | undefined {\n if (!Array.isArray(node.properties.className)) {\n return undefined;\n }\n const prefix = \"language-\";\n const language = node.properties.className.find(\n (name) => typeof name === \"string\" && name.startsWith(prefix),\n ) as string | undefined;\n if (typeof language === \"string\") {\n return language.slice(prefix.length);\n }\n return language;\n}\n"],"mappings":"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"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HastElement as Element, HastNode as Node } from "../../types.mjs";
|
|
2
|
-
import { Plugin } from "unified";
|
|
3
|
-
//#region src/plugins/tree-processor/plugin.d.ts
|
|
4
|
-
type MdxTreeProcessor = (node: Element, index: number, parent: Element) => void | Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* Options for {@linkcode treeProcessorPlugin}.
|
|
7
|
-
*/
|
|
8
|
-
type TreeProcessorPluginOptions = {
|
|
9
|
-
/** The processor. */
|
|
10
|
-
process: MdxTreeProcessor;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* A plugin that allows to process MDX tree nodes.
|
|
14
|
-
* It can be async or sync.
|
|
15
|
-
*/
|
|
16
|
-
declare const treeProcessorPlugin: Plugin<[TreeProcessorPluginOptions?], Node, Node>;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { MdxTreeProcessor, treeProcessorPlugin };
|
|
19
|
-
//# sourceMappingURL=plugin.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../../../src/plugins/tree-processor/plugin.ts"],"mappings":";;;KAMY,oBACV,MAAM,SACN,eACA,QAAQ,mBACE;;;;KAKP;;EAEH,SAAS;;;;;;cAOE,qBAAqB,QAAQ,8BAA8B,MAAU"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { visit } from "unist-util-visit";
|
|
2
|
-
//#region src/plugins/tree-processor/plugin.ts
|
|
3
|
-
/**
|
|
4
|
-
* A plugin that allows to process MDX tree nodes.
|
|
5
|
-
* It can be async or sync.
|
|
6
|
-
*/
|
|
7
|
-
const treeProcessorPlugin = ({ process } = { process: () => {} }) => {
|
|
8
|
-
return async (tree) => {
|
|
9
|
-
const promises = [];
|
|
10
|
-
visit(tree, "element", function visitor(node, index, parent) {
|
|
11
|
-
const p = process(node, index, parent);
|
|
12
|
-
if (p instanceof Promise || Object.prototype.toString.call(p) === "[object Promise]") promises.push(p);
|
|
13
|
-
});
|
|
14
|
-
await Promise.allSettled(promises);
|
|
15
|
-
return tree;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
//#endregion
|
|
19
|
-
export { treeProcessorPlugin };
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=plugin.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../../../src/plugins/tree-processor/plugin.ts"],"sourcesContent":["import type { Plugin } from \"unified\";\n\nimport { visit } from \"unist-util-visit\";\n\nimport type { HastElement, HastNode } from \"../../types\";\n\nexport type MdxTreeProcessor = (\n node: HastElement,\n index: number,\n parent: HastElement,\n) => void | Promise<void>;\n\n/**\n * Options for {@linkcode treeProcessorPlugin}.\n */\ntype TreeProcessorPluginOptions = {\n /** The processor. */\n process: MdxTreeProcessor;\n};\n\n/**\n * A plugin that allows to process MDX tree nodes.\n * It can be async or sync.\n */\nexport const treeProcessorPlugin: Plugin<[TreeProcessorPluginOptions?], HastNode, HastNode> = (\n { process } = { process: () => {} },\n) => {\n return async (tree) => {\n const promises: Promise<void>[] = [];\n\n visit(\n tree,\n \"element\",\n function visitor(node: HastElement, index: number, parent: HastElement): void {\n const p = process(node, index, parent);\n if (p instanceof Promise || Object.prototype.toString.call(p) === \"[object Promise]\") {\n promises.push(p as Promise<void>);\n }\n },\n );\n\n await Promise.allSettled(promises);\n\n return tree;\n };\n};\n"],"mappings":";;;;;;AAwBA,MAAa,uBACX,EAAE,YAAY,EAAE,eAAe,CAAC,EAAE,MAC/B;CACH,OAAO,OAAO,SAAS;EACrB,MAAM,WAA4B,CAAC;EAEnC,MACE,MACA,WACA,SAAS,QAAQ,MAAmB,OAAe,QAA2B;GAC5E,MAAM,IAAI,QAAQ,MAAM,OAAO,MAAM;GACrC,IAAI,aAAa,WAAW,OAAO,UAAU,SAAS,KAAK,CAAC,MAAM,oBAChE,SAAS,KAAK,CAAkB;EAEpC,CACF;EAEA,MAAM,QAAQ,WAAW,QAAQ;EAEjC,OAAO;CACT;AACF"}
|
package/dist/types.d.mts
DELETED
|
File without changes
|