@temelj/mdx 0.14.0 → 0.16.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 +470 -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 +167 -420
- 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-decode.d.mts +15 -0
- package/dist/frontmatter-decode.d.mts.map +1 -0
- package/dist/frontmatter-decode.mjs +187 -0
- package/dist/frontmatter-decode.mjs.map +1 -0
- package/dist/frontmatter-schema.d.mts +8 -0
- package/dist/frontmatter-schema.d.mts.map +1 -0
- package/dist/frontmatter-schema.mjs +28 -0
- package/dist/frontmatter-schema.mjs.map +1 -0
- package/dist/frontmatter.d.mts +40 -0
- package/dist/frontmatter.d.mts.map +1 -0
- package/dist/frontmatter.mjs +109 -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 +26 -9
- package/dist/mod.mjs +20 -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 +136 -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
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
import { FootnoteNumbering } from "./footnote-numbering.mjs";
|
|
2
|
+
import { indexDocument, mdxChildren } from "./model.mjs";
|
|
3
|
+
import { formatMdx } from "./format.mjs";
|
|
4
|
+
import { isUrlControlCharacter, normalizeUri } from "./uri.mjs";
|
|
5
|
+
import { isFunction } from "@temelj/value";
|
|
6
|
+
//#region src/html-lower.ts
|
|
7
|
+
function createHtmlLoweringCache() {
|
|
8
|
+
return {
|
|
9
|
+
loose: /* @__PURE__ */ new WeakMap(),
|
|
10
|
+
tight: /* @__PURE__ */ new WeakMap(),
|
|
11
|
+
lists: /* @__PURE__ */ new WeakMap()
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const percentEncodedByteLength = 2;
|
|
15
|
+
const hexadecimalRadix = 16;
|
|
16
|
+
const percentEncodedByte = /^[0-9A-Fa-f]{2}$/u;
|
|
17
|
+
const linkSchemes = /* @__PURE__ */ new Set([
|
|
18
|
+
"http",
|
|
19
|
+
"https",
|
|
20
|
+
"irc",
|
|
21
|
+
"ircs",
|
|
22
|
+
"mailto",
|
|
23
|
+
"xmpp"
|
|
24
|
+
]);
|
|
25
|
+
const imageSchemes = /* @__PURE__ */ new Set(["http", "https"]);
|
|
26
|
+
function lowerHtml(document, options = {}) {
|
|
27
|
+
const index = indexDocument(document);
|
|
28
|
+
const numbering = new FootnoteNumbering();
|
|
29
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
30
|
+
for (const reference of footnoteReferences(document)) if (index.footnotes.has(reference.identifier)) occurrences.set(reference, numbering.reference(reference.identifier));
|
|
31
|
+
const scope = {
|
|
32
|
+
definition: (identifier) => index.definitions.get(identifier),
|
|
33
|
+
footnote: (identifier) => index.footnotes.get(identifier),
|
|
34
|
+
options,
|
|
35
|
+
occurrence: (node) => occurrences.get(node)
|
|
36
|
+
};
|
|
37
|
+
const children = lowerNodes(document.children, scope);
|
|
38
|
+
const footnotes = lowerFootnoteSection(numbering, scope);
|
|
39
|
+
if (footnotes !== void 0) children.push(footnotes);
|
|
40
|
+
return {
|
|
41
|
+
kind: "root",
|
|
42
|
+
children: joinBlocks(children),
|
|
43
|
+
origin: document.origin
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Lowers sibling nodes in one scope. `previous` is the sibling before them,
|
|
48
|
+
* because text after a hard break drops its leading spaces.
|
|
49
|
+
*/
|
|
50
|
+
function lowerNodes(nodes, scope, previous) {
|
|
51
|
+
return lowerChildren(nodes, {
|
|
52
|
+
scope,
|
|
53
|
+
listLoose: false,
|
|
54
|
+
volatile: { count: 0 }
|
|
55
|
+
}, previous);
|
|
56
|
+
}
|
|
57
|
+
/** Separates top-level blocks with line endings, like a document root. */
|
|
58
|
+
function joinBlocks(nodes) {
|
|
59
|
+
return wrap(nodes, false);
|
|
60
|
+
}
|
|
61
|
+
/** Footnote reference nodes in document order. */
|
|
62
|
+
function footnoteReferences(node) {
|
|
63
|
+
const result = [];
|
|
64
|
+
const visit = (current) => {
|
|
65
|
+
if (current.kind === "footnoteReference") result.push(current);
|
|
66
|
+
mdxChildren(current).forEach(visit);
|
|
67
|
+
};
|
|
68
|
+
visit(node);
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
function lowerHtmlNode(node, context) {
|
|
72
|
+
const replaced = context.scope.replace?.(node);
|
|
73
|
+
if (replaced !== void 0) {
|
|
74
|
+
context.volatile.count++;
|
|
75
|
+
return replaced;
|
|
76
|
+
}
|
|
77
|
+
const cache = context.listLoose ? context.scope.cache?.loose : context.scope.cache?.tight;
|
|
78
|
+
if (cache?.has(node) === true) return cache.get(node);
|
|
79
|
+
const volatile = context.volatile.count;
|
|
80
|
+
const lowered = lowerHtmlNodeCore(node, context);
|
|
81
|
+
const result = lowered === void 0 || node.origin === void 0 ? lowered : isHtmlNodeArray(lowered) ? lowered.map((item) => withOrigin(item, node.origin)) : withOrigin(lowered, node.origin);
|
|
82
|
+
if (context.volatile.count === volatile) cache?.set(node, result);
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
function isHtmlNodeArray(value) {
|
|
86
|
+
return Array.isArray(value);
|
|
87
|
+
}
|
|
88
|
+
function withOrigin(node, origin) {
|
|
89
|
+
return origin === void 0 || node.origin !== void 0 ? node : {
|
|
90
|
+
...node,
|
|
91
|
+
origin
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** Authored source when the file is known, otherwise canonical MDX. */
|
|
95
|
+
function authored(node, context) {
|
|
96
|
+
const source = context.scope.options.source;
|
|
97
|
+
return source !== void 0 && node.origin !== void 0 ? source.slice(node.origin) : formatMdx(node);
|
|
98
|
+
}
|
|
99
|
+
function lowerHtmlNodeCore(node, context) {
|
|
100
|
+
switch (node.kind) {
|
|
101
|
+
case "text": return text(node.value);
|
|
102
|
+
case "emphasis": return htmlElement("em", node.children, context);
|
|
103
|
+
case "strong": return htmlElement("strong", node.children, context);
|
|
104
|
+
case "delete": return htmlElement("del", node.children, context);
|
|
105
|
+
case "directiveLabel": return lowerChildren(node.children, context);
|
|
106
|
+
case "textDirective": return lowerTextDirective(node, context);
|
|
107
|
+
case "inlineCode": return element("code", {}, [text(node.value.replace(/\r\n?|\n/gu, " "))]);
|
|
108
|
+
case "inlineMath": return {
|
|
109
|
+
kind: "math",
|
|
110
|
+
source: node.value.replace(/\r\n?|\n/gu, " "),
|
|
111
|
+
style: "inline"
|
|
112
|
+
};
|
|
113
|
+
case "hardBreak": return [element("br"), text("\n")];
|
|
114
|
+
case "link": return lowerLink(node.url, node.title, node.children, context);
|
|
115
|
+
case "linkReference": {
|
|
116
|
+
const definition = context.scope.definition(node.identifier);
|
|
117
|
+
if (definition !== void 0) return lowerLink(definition.url, definition.title, node.children, context);
|
|
118
|
+
return context.scope.provisional === true ? unresolvedReference("link", node, lowerChildren(node.children, context), context) : revertReference(node, context);
|
|
119
|
+
}
|
|
120
|
+
case "image": return lowerImage(node.url, node.alt, node.title, context);
|
|
121
|
+
case "imageReference": {
|
|
122
|
+
const definition = context.scope.definition(node.identifier);
|
|
123
|
+
if (definition !== void 0) return lowerImage(definition.url, node.alt, definition.title, context);
|
|
124
|
+
return context.scope.provisional === true ? unresolvedReference("image", node, [text(node.alt)], context) : text(formatMdx(node));
|
|
125
|
+
}
|
|
126
|
+
case "footnoteReference": {
|
|
127
|
+
context.volatile.count++;
|
|
128
|
+
const occurrence = context.scope.occurrence(node);
|
|
129
|
+
if (occurrence !== void 0) return lowerFootnoteReference(node, occurrence, context.scope.options);
|
|
130
|
+
return context.scope.provisional === true ? unresolvedReference("footnote", node, [], context) : text(formatMdx(node));
|
|
131
|
+
}
|
|
132
|
+
case "definition":
|
|
133
|
+
case "footnoteDefinition":
|
|
134
|
+
case "frontmatter":
|
|
135
|
+
case "esm": return;
|
|
136
|
+
case "leafDirective": return lowerLeafDirective(node, context);
|
|
137
|
+
case "containerDirective": return lowerContainerDirective(node, context);
|
|
138
|
+
case "rawHtmlBlock":
|
|
139
|
+
case "rawHtmlInline": return {
|
|
140
|
+
kind: "raw",
|
|
141
|
+
value: node.value
|
|
142
|
+
};
|
|
143
|
+
case "inlineExpression":
|
|
144
|
+
case "blockExpression": return {
|
|
145
|
+
kind: "expression",
|
|
146
|
+
code: node.code,
|
|
147
|
+
fallback: authored(node, context)
|
|
148
|
+
};
|
|
149
|
+
case "jsxTextElement":
|
|
150
|
+
case "jsxFlowElement": return {
|
|
151
|
+
kind: "jsx",
|
|
152
|
+
state: "complete",
|
|
153
|
+
element: node.kind === "jsxFlowElement" ? "flow" : "text",
|
|
154
|
+
name: node.name,
|
|
155
|
+
attributes: node.attributes,
|
|
156
|
+
fallback: authored(node, context),
|
|
157
|
+
children: lowerChildren(node.children, context)
|
|
158
|
+
};
|
|
159
|
+
case "paragraph": return node.children.every(isEmbeddedPhrasing) && node.children.some((child) => child.kind !== "text") ? lowerChildren(node.children, context) : htmlElement("p", node.children, context);
|
|
160
|
+
case "heading": return htmlElement(`h${node.depth}`, node.children, context);
|
|
161
|
+
case "codeBlock": {
|
|
162
|
+
const language = node.language?.trim().split(/\s+/u)[0];
|
|
163
|
+
return language === void 0 || language.length === 0 ? element("pre", {}, [element("code", {}, [text(node.value.length === 0 ? "" : `${node.value}\n`)])]) : {
|
|
164
|
+
kind: "codeBlock",
|
|
165
|
+
code: node.value,
|
|
166
|
+
language,
|
|
167
|
+
meta: node.meta
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
case "displayMath": return {
|
|
171
|
+
kind: "math",
|
|
172
|
+
source: node.value,
|
|
173
|
+
style: "display",
|
|
174
|
+
meta: node.meta
|
|
175
|
+
};
|
|
176
|
+
case "thematicBreak": return element("hr");
|
|
177
|
+
case "list": return lowerList(node, context);
|
|
178
|
+
case "listItem": return lowerListItem(node, context);
|
|
179
|
+
case "table": return lowerTable(node, context);
|
|
180
|
+
case "tableRow": return lowerTableRow(node, void 0, false, context);
|
|
181
|
+
case "tableCell": return htmlElement("td", node.children, context);
|
|
182
|
+
case "blockquote": return element("blockquote", {}, wrap(lowerChildren(node.children, context), true));
|
|
183
|
+
case "document": return wrap(lowerChildren(node.children, context), false);
|
|
184
|
+
default: return node;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function isEmbeddedPhrasing(node) {
|
|
188
|
+
return node.kind === "jsxTextElement" || node.kind === "inlineExpression" || node.kind === "text" && node.value.trim() === "";
|
|
189
|
+
}
|
|
190
|
+
function lowerTextDirective(node, context) {
|
|
191
|
+
return element("span", directiveHtmlAttributes(node.name, "text", node.attributes), node.label === void 0 ? [] : lowerChildren(node.label.children, context));
|
|
192
|
+
}
|
|
193
|
+
function lowerLeafDirective(node, context) {
|
|
194
|
+
return element("div", directiveHtmlAttributes(node.name, "leaf", node.attributes), node.label === void 0 ? [] : [directiveLabel(node, context)]);
|
|
195
|
+
}
|
|
196
|
+
function lowerContainerDirective(node, context) {
|
|
197
|
+
const children = [];
|
|
198
|
+
if (node.label !== void 0) children.push(directiveLabel(node, context));
|
|
199
|
+
children.push(...lowerChildren(node.children, context));
|
|
200
|
+
return element("div", directiveHtmlAttributes(node.name, "container", node.attributes), wrap(children, true));
|
|
201
|
+
}
|
|
202
|
+
function directiveLabel(node, context) {
|
|
203
|
+
return element("span", { "data-directive-label": "" }, lowerChildren(node.label?.children ?? [], context));
|
|
204
|
+
}
|
|
205
|
+
function directiveHtmlAttributes(name, kind, entries) {
|
|
206
|
+
const attributes = {
|
|
207
|
+
"data-directive": name,
|
|
208
|
+
"data-directive-kind": kind
|
|
209
|
+
};
|
|
210
|
+
return entries.length === 0 ? attributes : {
|
|
211
|
+
...attributes,
|
|
212
|
+
"data-directive-attributes": JSON.stringify(entries.map((entry) => [entry.name, entry.value]))
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function unresolvedReference(reference, node, children, context) {
|
|
216
|
+
return {
|
|
217
|
+
kind: "unresolvedReference",
|
|
218
|
+
reference,
|
|
219
|
+
identifier: node.identifier,
|
|
220
|
+
source: authored(node, context),
|
|
221
|
+
children
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function lowerFootnoteReference(node, occurrence, options) {
|
|
225
|
+
const prefix = options.clobberPrefix ?? "user-content-";
|
|
226
|
+
const identifier = normalizeUri(node.identifier.toLowerCase());
|
|
227
|
+
const suffix = occurrence.occurrence > 1 ? `-${occurrence.occurrence}` : "";
|
|
228
|
+
return {
|
|
229
|
+
kind: "footnoteReference",
|
|
230
|
+
identifier: node.identifier,
|
|
231
|
+
occurrence: occurrence.occurrence,
|
|
232
|
+
ordinal: occurrence.ordinal,
|
|
233
|
+
children: [element("a", {
|
|
234
|
+
href: `#${prefix}fn-${identifier}`,
|
|
235
|
+
id: `${prefix}fnref-${identifier}${suffix}`,
|
|
236
|
+
"data-footnote-ref": "",
|
|
237
|
+
"aria-describedby": "footnote-label"
|
|
238
|
+
}, [text(String(occurrence.ordinal))])]
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** The generated section for the numbered footnotes, or `undefined` when none is referenced. */
|
|
242
|
+
function lowerFootnoteSection(numbering, scope) {
|
|
243
|
+
const order = numbering.order;
|
|
244
|
+
if (order.length === 0) return;
|
|
245
|
+
const context = {
|
|
246
|
+
scope,
|
|
247
|
+
listLoose: false,
|
|
248
|
+
volatile: { count: 0 }
|
|
249
|
+
};
|
|
250
|
+
const prefix = scope.options.clobberPrefix ?? "user-content-";
|
|
251
|
+
const items = [];
|
|
252
|
+
for (let index = 0; index < order.length; index++) {
|
|
253
|
+
const identifier = order[index];
|
|
254
|
+
const definition = scope.footnote(identifier);
|
|
255
|
+
if (definition === void 0) continue;
|
|
256
|
+
const safeIdentifier = normalizeUri(identifier.toLowerCase());
|
|
257
|
+
const blocks = lowerChildren(definition.children, context);
|
|
258
|
+
const backreferences = footnoteBackreferences(safeIdentifier, index, numbering.count(identifier), prefix, scope.options);
|
|
259
|
+
const tail = blocks.at(-1);
|
|
260
|
+
if (tail?.kind === "element" && tail.tagName === "p") blocks[blocks.length - 1] = {
|
|
261
|
+
...tail,
|
|
262
|
+
children: [
|
|
263
|
+
...tail.children,
|
|
264
|
+
...tail.children.length === 0 ? [] : [text(" ")],
|
|
265
|
+
...backreferences
|
|
266
|
+
]
|
|
267
|
+
};
|
|
268
|
+
else {
|
|
269
|
+
if (blocks.length > 0) blocks.push(text("\n"));
|
|
270
|
+
blocks.push(...backreferences);
|
|
271
|
+
}
|
|
272
|
+
items.push(element("li", { id: `${prefix}fn-${safeIdentifier}` }, wrap(blocks, true)));
|
|
273
|
+
}
|
|
274
|
+
const heading = element(scope.options.footnoteLabelTagName ?? "h2", {
|
|
275
|
+
id: "footnote-label",
|
|
276
|
+
class: ["sr-only"]
|
|
277
|
+
}, [text(scope.options.footnoteLabel ?? "Footnotes")]);
|
|
278
|
+
return {
|
|
279
|
+
kind: "footnoteSection",
|
|
280
|
+
identifiers: [...order],
|
|
281
|
+
children: wrap([heading, element("ol", {}, wrap(items, true))], true)
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function footnoteBackreferences(identifier, referenceIndex, count, prefix, options) {
|
|
285
|
+
const values = [];
|
|
286
|
+
for (let reuse = 1; reuse <= count; reuse++) {
|
|
287
|
+
if (values.length > 0) values.push(text(" "));
|
|
288
|
+
const configured = options.footnoteBackLabel;
|
|
289
|
+
const label = isFunction(configured) ? configured(referenceIndex, reuse) : configured ?? defaultFootnoteBackLabel(referenceIndex, reuse);
|
|
290
|
+
values.push(element("a", {
|
|
291
|
+
href: `#${prefix}fnref-${identifier}${reuse > 1 ? `-${reuse}` : ""}`,
|
|
292
|
+
"data-footnote-backref": "",
|
|
293
|
+
"aria-label": label,
|
|
294
|
+
class: ["data-footnote-backref"]
|
|
295
|
+
}, [text("↩"), ...reuse > 1 ? [element("sup", {}, [text(String(reuse))])] : []]));
|
|
296
|
+
}
|
|
297
|
+
return values;
|
|
298
|
+
}
|
|
299
|
+
function defaultFootnoteBackLabel(referenceIndex, reuse) {
|
|
300
|
+
return `Back to reference ${referenceIndex + 1}${reuse > 1 ? `-${reuse}` : ""}`;
|
|
301
|
+
}
|
|
302
|
+
function lowerTable(node, context) {
|
|
303
|
+
const head = node.children[0];
|
|
304
|
+
const children = [];
|
|
305
|
+
if (head !== void 0) children.push(element("thead", {}, [lowerTableRow(head, node.alignments, true, context)]));
|
|
306
|
+
if (node.children.length > 1) children.push(element("tbody", {}, node.children.slice(1).map((row) => lowerTableRow(row, node.alignments, false, context))));
|
|
307
|
+
return element("table", {}, children);
|
|
308
|
+
}
|
|
309
|
+
function lowerTableRow(node, alignments, heading, context) {
|
|
310
|
+
const length = alignments?.length ?? node.children.length;
|
|
311
|
+
const cells = [];
|
|
312
|
+
for (let index = 0; index < length; index++) {
|
|
313
|
+
const cell = node.children.at(index);
|
|
314
|
+
const alignment = alignments?.[index];
|
|
315
|
+
cells.push(element(heading ? "th" : "td", alignment === void 0 || alignment === "none" ? {} : { align: alignment }, cell === void 0 ? [] : lowerChildren(cell.children, context)));
|
|
316
|
+
}
|
|
317
|
+
return element("tr", {}, cells);
|
|
318
|
+
}
|
|
319
|
+
function lowerLink(url, title, children, context) {
|
|
320
|
+
const href = resolveUrl(url, "link", context.scope.options);
|
|
321
|
+
return element("a", href === void 0 ? {} : title === void 0 ? { href } : {
|
|
322
|
+
href,
|
|
323
|
+
title
|
|
324
|
+
}, lowerChildren(children, context));
|
|
325
|
+
}
|
|
326
|
+
function lowerImage(source, alt, title, context) {
|
|
327
|
+
const src = resolveUrl(source, "image", context.scope.options);
|
|
328
|
+
if (src === void 0) return text(alt);
|
|
329
|
+
return element("img", title === void 0 ? {
|
|
330
|
+
src,
|
|
331
|
+
alt
|
|
332
|
+
} : {
|
|
333
|
+
src,
|
|
334
|
+
alt,
|
|
335
|
+
title
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* A list wraps its items in line endings. A growing list reuses the wrapped
|
|
340
|
+
* children of its unchanged leading items, so an append lowers only new items.
|
|
341
|
+
* Stream previews build long children from fixed fragments, so extending them
|
|
342
|
+
* copies only the fragment list; strict output stays flat.
|
|
343
|
+
*/
|
|
344
|
+
function lowerList(node, context) {
|
|
345
|
+
const items = node.children;
|
|
346
|
+
const prefix = listPrefix(items, context.scope.cache);
|
|
347
|
+
const rest = items.slice((prefix?.index ?? -1) + 1);
|
|
348
|
+
const spread = (prefix?.spread ?? false) || rest.some((item) => item.spread);
|
|
349
|
+
const loose = node.spread || spread;
|
|
350
|
+
const tasks = (prefix?.tasks ?? false) || rest.some((item) => item.checked !== void 0);
|
|
351
|
+
const reused = prefix !== void 0 && prefix.loose === loose ? prefix : void 0;
|
|
352
|
+
const itemContext = {
|
|
353
|
+
...context,
|
|
354
|
+
listLoose: loose
|
|
355
|
+
};
|
|
356
|
+
const children = new ChildSequence(context.scope.provisional === true, reused?.children);
|
|
357
|
+
if (reused === void 0) children.push(newline);
|
|
358
|
+
let stable = true;
|
|
359
|
+
let spreadSoFar = reused?.spread ?? false;
|
|
360
|
+
let tasksSoFar = reused?.tasks ?? false;
|
|
361
|
+
for (let index = (reused?.index ?? -1) + 1; index < items.length; index++) {
|
|
362
|
+
spreadSoFar ||= items[index].spread;
|
|
363
|
+
tasksSoFar ||= items[index].checked !== void 0;
|
|
364
|
+
const volatile = context.volatile.count;
|
|
365
|
+
const lowered = lowerHtmlNode(items[index], itemContext);
|
|
366
|
+
for (const item of lowered === void 0 ? [] : isHtmlNodeArray(lowered) ? lowered : [lowered]) {
|
|
367
|
+
if (children.size > 1) children.push(newline);
|
|
368
|
+
children.push(item);
|
|
369
|
+
}
|
|
370
|
+
stable &&= context.volatile.count === volatile;
|
|
371
|
+
if (stable && index >= items.length - prefixWindow) context.scope.cache?.lists.set(items[index], {
|
|
372
|
+
index,
|
|
373
|
+
loose,
|
|
374
|
+
spread: spreadSoFar,
|
|
375
|
+
tasks: tasksSoFar,
|
|
376
|
+
children: children.prefix()
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
const attributes = {};
|
|
380
|
+
if (node.ordered && node.start !== 1) attributes.start = node.start;
|
|
381
|
+
if (tasks) attributes.class = ["contains-task-list"];
|
|
382
|
+
if (children.size > 1) children.push(newline);
|
|
383
|
+
return element(node.ordered ? "ol" : "ul", attributes, children.toArray());
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* How far back a list prefix can end. The parser closes an item only when the
|
|
387
|
+
* next line completes, so the last two items are rebuilt by each tail draft.
|
|
388
|
+
*/
|
|
389
|
+
const prefixWindow = 8;
|
|
390
|
+
/** Children of a long sequence in fragments of this many nodes. */
|
|
391
|
+
const fragmentSize = 64;
|
|
392
|
+
/**
|
|
393
|
+
* Children that grow at the end. With fragments, full groups of nodes become
|
|
394
|
+
* frozen fragments that later prefixes share, so copying a prefix costs only
|
|
395
|
+
* the fragment list and the partial group.
|
|
396
|
+
*/
|
|
397
|
+
var ChildSequence = class {
|
|
398
|
+
#fragmented;
|
|
399
|
+
#fragments;
|
|
400
|
+
#rest;
|
|
401
|
+
#size;
|
|
402
|
+
constructor(fragmented, prefix) {
|
|
403
|
+
this.#fragmented = fragmented;
|
|
404
|
+
this.#fragments = prefix === void 0 ? [] : [...prefix.fragments];
|
|
405
|
+
this.#rest = prefix === void 0 ? [] : [...prefix.rest];
|
|
406
|
+
this.#size = prefix?.size ?? 0;
|
|
407
|
+
}
|
|
408
|
+
get size() {
|
|
409
|
+
return this.#size;
|
|
410
|
+
}
|
|
411
|
+
push(node) {
|
|
412
|
+
this.#rest.push(node);
|
|
413
|
+
this.#size++;
|
|
414
|
+
if (this.#fragmented && this.#rest.length === fragmentSize) {
|
|
415
|
+
this.#fragments.push(Object.freeze({
|
|
416
|
+
kind: "root",
|
|
417
|
+
children: this.#rest
|
|
418
|
+
}));
|
|
419
|
+
this.#rest = [];
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
prefix() {
|
|
423
|
+
return {
|
|
424
|
+
fragments: [...this.#fragments],
|
|
425
|
+
rest: [...this.#rest],
|
|
426
|
+
size: this.#size
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
/** A short sequence stays flat, so fragments appear only where they save copying. */
|
|
430
|
+
toArray() {
|
|
431
|
+
if (this.#fragments.length < 2) return [...this.#fragments.flatMap((fragment) => fragment.children), ...this.#rest];
|
|
432
|
+
return [...this.#fragments, ...this.#rest];
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
/** The longest cached prefix of `items`, found from the end. */
|
|
436
|
+
function listPrefix(items, cache) {
|
|
437
|
+
for (let index = items.length - 1; index >= Math.max(0, items.length - prefixWindow); index--) {
|
|
438
|
+
const item = items[index];
|
|
439
|
+
const prefix = item === void 0 ? void 0 : cache?.lists.get(item);
|
|
440
|
+
if (prefix?.index === index) return prefix;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
function lowerListItem(node, context) {
|
|
444
|
+
const blocks = [...lowerChildren(node.children, context)];
|
|
445
|
+
if (node.checked !== void 0) {
|
|
446
|
+
const checkbox = element("input", node.checked ? {
|
|
447
|
+
type: "checkbox",
|
|
448
|
+
disabled: true,
|
|
449
|
+
checked: true
|
|
450
|
+
} : {
|
|
451
|
+
type: "checkbox",
|
|
452
|
+
disabled: true
|
|
453
|
+
});
|
|
454
|
+
const first = blocks[0];
|
|
455
|
+
if (first?.kind === "element" && first.tagName === "p") blocks[0] = {
|
|
456
|
+
...first,
|
|
457
|
+
children: [
|
|
458
|
+
checkbox,
|
|
459
|
+
...first.children.length === 0 ? [] : [text(" ")],
|
|
460
|
+
...first.children
|
|
461
|
+
]
|
|
462
|
+
};
|
|
463
|
+
else blocks.unshift(element("p", {}, [checkbox]));
|
|
464
|
+
}
|
|
465
|
+
const children = [];
|
|
466
|
+
for (let index = 0; index < blocks.length; index++) {
|
|
467
|
+
const child = blocks[index];
|
|
468
|
+
const paragraph = child.kind === "element" && child.tagName === "p";
|
|
469
|
+
if (context.listLoose || index !== 0 || !paragraph) children.push(text("\n"));
|
|
470
|
+
if (paragraph && !context.listLoose) children.push(...child.children);
|
|
471
|
+
else children.push(child);
|
|
472
|
+
}
|
|
473
|
+
const tail = blocks.at(-1);
|
|
474
|
+
if (tail !== void 0 && (context.listLoose || tail.kind !== "element" || tail.tagName !== "p")) children.push(text("\n"));
|
|
475
|
+
return element("li", node.checked === void 0 ? {} : { class: ["task-list-item"] }, children);
|
|
476
|
+
}
|
|
477
|
+
function revertReference(node, context) {
|
|
478
|
+
const children = lowerChildren(node.children, context);
|
|
479
|
+
const suffix = node.referenceKind === "shortcut" ? "]" : node.referenceKind === "collapsed" ? "][]" : `][${node.identifier}]`;
|
|
480
|
+
if (children.length === 0) return [text(`[${suffix}`)];
|
|
481
|
+
const first = children[0];
|
|
482
|
+
const result = first.kind === "text" ? [text(`[${first.value}`), ...children.slice(1)] : [text("["), ...children];
|
|
483
|
+
const last = result[result.length - 1];
|
|
484
|
+
if (last.kind === "text") result[result.length - 1] = text(last.value + suffix);
|
|
485
|
+
else result.push(text(suffix));
|
|
486
|
+
return result;
|
|
487
|
+
}
|
|
488
|
+
function lowerChildren(children, context, previous) {
|
|
489
|
+
const values = [];
|
|
490
|
+
for (let index = 0; index < children.length; index++) {
|
|
491
|
+
const child = children[index];
|
|
492
|
+
const lowered = lowerHtmlNode(child, context);
|
|
493
|
+
if (lowered === void 0) continue;
|
|
494
|
+
const additions = isHtmlNodeArray(lowered) ? [...lowered] : [lowered];
|
|
495
|
+
if ((index === 0 ? previous : children[index - 1])?.kind === "hardBreak" && additions.length > 0) additions[0] = trimSpaceStart(additions[0]);
|
|
496
|
+
values.push(...additions);
|
|
497
|
+
}
|
|
498
|
+
return values;
|
|
499
|
+
}
|
|
500
|
+
function htmlElement(tagName, children, context) {
|
|
501
|
+
return element(tagName, {}, lowerChildren(children, context));
|
|
502
|
+
}
|
|
503
|
+
function element(tagName, attributes = {}, children = []) {
|
|
504
|
+
return {
|
|
505
|
+
kind: "element",
|
|
506
|
+
tagName,
|
|
507
|
+
attributes,
|
|
508
|
+
children
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function text(value) {
|
|
512
|
+
return {
|
|
513
|
+
kind: "text",
|
|
514
|
+
value
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function trimSpaceStart(node) {
|
|
518
|
+
if (node.kind === "text") return {
|
|
519
|
+
...node,
|
|
520
|
+
value: node.value.replace(/^[\t ]+/u, "")
|
|
521
|
+
};
|
|
522
|
+
if (node.kind === "element") {
|
|
523
|
+
const first = node.children[0];
|
|
524
|
+
if (first?.kind === "text") return {
|
|
525
|
+
...node,
|
|
526
|
+
children: [{
|
|
527
|
+
...first,
|
|
528
|
+
value: first.value.replace(/^[\t ]+/u, "")
|
|
529
|
+
}, ...node.children.slice(1)]
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
return node;
|
|
533
|
+
}
|
|
534
|
+
/** Line endings between blocks. Trees are immutable, so every separator shares one node. */
|
|
535
|
+
const newline = Object.freeze({
|
|
536
|
+
kind: "text",
|
|
537
|
+
value: "\n"
|
|
538
|
+
});
|
|
539
|
+
function wrap(nodes, loose) {
|
|
540
|
+
const result = [];
|
|
541
|
+
if (loose) result.push(newline);
|
|
542
|
+
nodes.forEach((node, index) => {
|
|
543
|
+
if (index > 0) result.push(newline);
|
|
544
|
+
result.push(node);
|
|
545
|
+
});
|
|
546
|
+
if (loose && nodes.length > 0) result.push(newline);
|
|
547
|
+
return result;
|
|
548
|
+
}
|
|
549
|
+
function resolveUrl(url, kind, options) {
|
|
550
|
+
const sanitized = sanitizeUrl(url, options, kind);
|
|
551
|
+
return options.urlTransform === void 0 ? sanitized : options.urlTransform(url, kind, sanitized);
|
|
552
|
+
}
|
|
553
|
+
function sanitizeUrl(value, options, use) {
|
|
554
|
+
const decoded = decodeUrlForSchemeCheck(value);
|
|
555
|
+
const colon = decoded.indexOf(":");
|
|
556
|
+
const slash = decoded.indexOf("/");
|
|
557
|
+
const query = decoded.indexOf("?");
|
|
558
|
+
const hash = decoded.indexOf("#");
|
|
559
|
+
if (colon >= 0 && (slash < 0 || colon < slash) && (query < 0 || colon < query) && (hash < 0 || colon < hash) && options.allowUnsafeUrls !== true) {
|
|
560
|
+
const scheme = decoded.slice(0, colon).toLowerCase();
|
|
561
|
+
if (use === "image" ? !imageSchemes.has(scheme) : !linkSchemes.has(scheme)) return;
|
|
562
|
+
}
|
|
563
|
+
return normalizeUri(value);
|
|
564
|
+
}
|
|
565
|
+
function decodeUrlForSchemeCheck(value) {
|
|
566
|
+
const result = [];
|
|
567
|
+
for (let index = 0; index < value.length; index++) {
|
|
568
|
+
const character = value[index];
|
|
569
|
+
const hexadecimal = value.slice(index + 1, index + 1 + percentEncodedByteLength);
|
|
570
|
+
if (character === "%" && percentEncodedByte.test(hexadecimal)) {
|
|
571
|
+
const decoded = String.fromCodePoint(Number.parseInt(hexadecimal, hexadecimalRadix));
|
|
572
|
+
if (!isUrlControlCharacter(decoded)) result.push(decoded);
|
|
573
|
+
index += hexadecimal.length;
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
if (!isUrlControlCharacter(character)) result.push(character);
|
|
577
|
+
}
|
|
578
|
+
return result.join("");
|
|
579
|
+
}
|
|
580
|
+
//#endregion
|
|
581
|
+
export { createHtmlLoweringCache, footnoteReferences, joinBlocks, lowerFootnoteSection, lowerHtml, lowerNodes, sanitizeUrl };
|
|
582
|
+
|
|
583
|
+
//# sourceMappingURL=html-lower.mjs.map
|