@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 @@
|
|
|
1
|
+
{"version":3,"file":"format.mjs","names":["exhaustive"],"sources":["../src/format.ts"],"sourcesContent":["import type {\n BlockQuoteNode,\n CodeBlockNode,\n DefinitionNode,\n FootnoteDefinitionNode,\n FootnoteReferenceNode,\n HeadingNode,\n ImageNode,\n ImageReferenceNode,\n LinkNode,\n LinkReferenceNode,\n ListItemNode,\n ListNode,\n MdxNode,\n ParagraphNode,\n} from \"./model.ts\";\n\nimport { encodeNumericCharacterReference } from \"./character-reference.ts\";\nimport {\n indentLines,\n longestRun,\n rootInfo,\n type FormatContext,\n type FormatInfo,\n type FormatOptions,\n} from \"./format-context.ts\";\nimport {\n formatContainerDirective,\n formatDirective,\n formatDirectiveLabel,\n containsDirective,\n} from \"./format-directive.ts\";\nimport { formatJsxFlowElement, formatJsxTextElement, indentExpression } from \"./format-jsx.ts\";\nimport { formatDisplayMath, formatInlineMath, mathFormats } from \"./format-math.ts\";\nimport {\n UNSAFE_PATTERNS,\n compileUnsafePattern,\n safeSource,\n type FormatConstruct,\n type FormatSafeInfo,\n type FormatSafetyState,\n type FormatUnsafePattern,\n} from \"./format-safe.ts\";\nimport { formatTable, formatTableCell, formatTableRow } from \"./format-table.ts\";\nimport { FormatTracker } from \"./format-track.ts\";\nimport { normalizeIdentifier } from \"./identifier.ts\";\nimport { mdxChildren } from \"./model.ts\";\nimport {\n frontmatterFence,\n resolveSyntaxOptions,\n type MathFormat,\n type ResolvedSyntaxOptions,\n} from \"./syntax-options.ts\";\n\n/** Formats a node as canonical MDX for the enabled syntax. */\nexport function formatMdx(node: MdxNode, options: FormatOptions = {}): string {\n return new Formatter(options, containsDirective(node), mathFormats(node)).format(node, rootInfo);\n}\n\nclass Formatter implements FormatSafetyState, FormatContext {\n public readonly stack: FormatConstruct[] = [];\n public readonly unsafe: readonly FormatUnsafePattern[];\n private readonly compiledPatterns = new Map<FormatUnsafePattern, RegExp>();\n public readonly options: FormatOptions;\n public readonly syntax: ResolvedSyntaxOptions;\n private bulletLastUsed: \"*\" | \"+\" | \"-\" | \".\" | \")\" | undefined;\n\n public constructor(\n options: FormatOptions,\n containsDirectives: boolean,\n nodeMathFormats: ReadonlySet<MathFormat>,\n ) {\n this.options = { ...options };\n this.syntax = resolveSyntaxOptions(options.syntax);\n this.unsafe = [\n ...UNSAFE_PATTERNS,\n { character: \"{\", inConstruct: \"phrasing\" },\n { atBreak: true, character: \"{\" },\n { character: \"<\", inConstruct: \"phrasing\" },\n { atBreak: true, character: \"<\" },\n ...(containsDirectives || this.syntax.directives\n ? ([\n {\n before: \"[^:]\",\n character: \":\",\n after: \"[A-Za-z]\",\n inConstruct: \"phrasing\",\n },\n { atBreak: true, character: \":\", after: \":\" },\n ] satisfies FormatUnsafePattern[])\n : []),\n ...(nodeMathFormats.has(\"dollar\") || this.syntax.math.includes(\"dollar\")\n ? ([\n {\n character: \"$\",\n inConstruct: \"phrasing\",\n },\n { character: \"$\", inConstruct: \"mathFlowMeta\" },\n { atBreak: true, character: \"$\", after: \"\\\\$\" },\n ] satisfies FormatUnsafePattern[])\n : []),\n ...this.syntax.frontmatter.map(\n (format) =>\n ({\n atBreak: true,\n character: frontmatterFence(format).charAt(0),\n after: escapeRegularExpression(frontmatterFence(format).slice(1)),\n }) satisfies FormatUnsafePattern,\n ),\n ];\n }\n\n public compilePattern(pattern: FormatUnsafePattern): RegExp {\n const cached = this.compiledPatterns.get(pattern);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const expression = compileUnsafePattern(pattern);\n this.compiledPatterns.set(pattern, expression);\n\n return expression;\n }\n\n public format(node: MdxNode, info: FormatInfo): string {\n switch (node.kind) {\n case \"document\":\n return this.flow(node.children, info);\n case \"paragraph\":\n return this.paragraph(node, info);\n case \"heading\":\n return this.heading(node, info);\n case \"thematicBreak\":\n return this.thematicBreak();\n case \"codeBlock\":\n return this.codeBlock(node, info);\n case \"blockquote\":\n return this.blockQuote(node, info);\n case \"list\":\n return this.list(node, info);\n case \"listItem\":\n return this.flow(node.children, info, node.spread);\n case \"table\":\n return formatTable(this, node, info);\n case \"tableRow\":\n return formatTableRow(this, node, info);\n case \"tableCell\":\n return formatTableCell(this, node, info);\n case \"definition\":\n return this.definition(node, info);\n case \"footnoteDefinition\":\n return this.footnoteDefinition(node, info);\n case \"frontmatter\":\n return `${frontmatterFence(node.format)}${node.value.length === 0 ? \"\" : `\\n${node.value}`}\\n${frontmatterFence(node.format)}`;\n case \"directiveLabel\":\n return formatDirectiveLabel(this, node, info);\n case \"textDirective\":\n return formatDirective(this, node, info, \":\");\n case \"leafDirective\":\n return formatDirective(this, node, info, \"::\");\n case \"containerDirective\":\n return formatContainerDirective(this, node, info);\n case \"displayMath\":\n return formatDisplayMath(this, node, info);\n case \"rawHtmlBlock\":\n case \"rawHtmlInline\":\n return node.value;\n case \"text\":\n return this.safe(node.value, info);\n case \"emphasis\":\n return this.attention(\n node.children,\n info,\n this.attentionMarker(this.options.emphasis ?? \"*\", false),\n false,\n );\n case \"strong\":\n return this.attention(\n node.children,\n info,\n this.attentionMarker(this.options.strong ?? \"*\", true),\n true,\n );\n case \"delete\":\n return this.strikethrough(node.children, info);\n case \"inlineCode\":\n return this.stack.includes(\"tableCell\")\n ? formatInlineCode(node.value).replaceAll(\"|\", \"\\\\|\")\n : formatInlineCode(node.value);\n case \"inlineMath\":\n return formatInlineMath(this, node);\n case \"hardBreak\":\n return \"\\\\\\n\";\n case \"link\":\n return this.link(node, info);\n case \"image\":\n return this.image(node, info);\n case \"linkReference\":\n return this.linkReference(node, info);\n case \"imageReference\":\n return this.imageReference(node, info);\n case \"footnoteReference\":\n return this.footnoteReference(node);\n case \"inlineExpression\":\n case \"blockExpression\":\n return `{${indentExpression(node.code)}}`;\n case \"esm\":\n return node.code;\n case \"jsxTextElement\":\n return formatJsxTextElement(this, node, info);\n case \"jsxFlowElement\":\n return formatJsxFlowElement(this, node, info);\n default: {\n const exhaustive: never = node;\n\n return exhaustive;\n }\n }\n }\n\n public flow(nodes: readonly MdxNode[], info: FormatInfo, spread?: boolean): string {\n const tracker = new FormatTracker(info);\n const output: string[] = [];\n\n for (let index = 0; index < nodes.length; index++) {\n const node = nodes[index];\n output.push(\n tracker.move(this.format(node, { after: \"\\n\", before: \"\\n\", ...tracker.current() })),\n );\n const next = nodes[index + 1];\n\n if (next !== undefined) {\n output.push(tracker.move(this.join(node, next, spread)));\n }\n\n if (node.kind !== \"list\") {\n this.bulletLastUsed = undefined;\n }\n }\n\n return output.join(\"\");\n }\n\n private join(left: MdxNode, right: MdxNode, spread?: boolean): string {\n if (\n this.options.tightDefinitions === true &&\n left.kind === \"definition\" &&\n right.kind === \"definition\"\n ) {\n return \"\\n\";\n }\n\n if (spread !== undefined) {\n return spread ? \"\\n\\n\" : \"\\n\";\n }\n\n return \"\\n\\n\";\n }\n\n private paragraph(node: ParagraphNode, info: FormatInfo): string {\n const exit = this.enter(\"paragraph\");\n const exitPhrasing = this.enter(\"phrasing\");\n const value = this.phrasing(node.children, info);\n exitPhrasing();\n exit();\n\n return value;\n }\n\n public phrasing(nodes: readonly MdxNode[], info: FormatInfo): string {\n let tracker = new FormatTracker(info);\n const output: string[] = [];\n let before = info.before;\n\n for (let index = 0; index < nodes.length; index++) {\n const node = nodes[index];\n let nextIndex = index + 1;\n let text = node.kind === \"text\" ? node.value : undefined;\n let nextText = nodes.at(nextIndex);\n\n while (text !== undefined && nextText?.kind === \"text\") {\n text += nextText.value;\n nextIndex++;\n nextText = nodes.at(nextIndex);\n }\n\n const next = nodes[nextIndex];\n const after = next === undefined ? info.after : peek(next, this.options);\n\n if (\n output.length > 0 &&\n (before === \"\\r\" || before === \"\\n\") &&\n node.kind === \"rawHtmlInline\"\n ) {\n output[output.length - 1] = output[output.length - 1].replace(/(?:\\r\\n?|\\n)$/u, (ending) =>\n encodeLineEnding(ending),\n );\n before = \";\";\n tracker = new FormatTracker(info);\n tracker.move(output.join(\"\"));\n }\n\n let value =\n text === undefined\n ? this.format(node, { after, before, ...tracker.current() })\n : encodeBlankLineEndings(\n this.safe(text, {\n after,\n before,\n ...tracker.current(),\n }),\n );\n\n if (text !== undefined && after === \"[\" && value.endsWith(\"!\") && !value.endsWith(\"\\\\!\")) {\n value = `${value.slice(0, -1)}\\\\!`;\n }\n\n tracker.move(value);\n output.push(value);\n before = value.slice(-1);\n index = nextIndex - 1;\n }\n\n return output.join(\"\");\n }\n\n private heading(node: HeadingNode, info: FormatInfo): string {\n if (node.depth < 3 && node.children.some(containsLineEnding)) {\n const exit = this.enter(\"headingSetext\");\n const exitPhrasing = this.enter(\"phrasing\");\n const content = this.phrasing(node.children, { ...info, after: \"\\n\", before: \"\\n\" });\n exitPhrasing();\n exit();\n const lastLineStart = Math.max(content.lastIndexOf(\"\\r\"), content.lastIndexOf(\"\\n\")) + 1;\n\n return `${content}\\n${(node.depth === 1 ? \"=\" : \"-\").repeat(\n Math.max(1, content.length - lastLineStart),\n )}`;\n }\n\n const sequence = \"#\".repeat(node.depth);\n const exit = this.enter(\"headingAtx\");\n const exitPhrasing = this.enter(\"phrasing\");\n const tracker = new FormatTracker(info);\n tracker.move(`${sequence} `);\n\n let content = this.phrasing(node.children, {\n after: \"\\n\",\n before: \"# \",\n ...tracker.current(),\n });\n\n if (/^[\\t ]/u.test(content)) {\n content = encodeNumericCharacterReference(content.codePointAt(0) ?? 32) + content.slice(1);\n }\n\n if (content.endsWith(\"#\")) {\n content = `${content.slice(0, -1)}${encodeNumericCharacterReference(35)}`;\n }\n\n exitPhrasing();\n exit();\n\n if (content.length === 0) {\n return sequence;\n }\n\n return `${sequence} ${content}${this.options.closeAtx === true ? ` ${sequence}` : \"\"}`;\n }\n\n private thematicBreak(): string {\n const marker = this.options.rule ?? \"-\";\n const repetition = Math.max(3, this.options.ruleRepetition ?? 3);\n const value = `${marker}${this.options.ruleSpaces === true ? \" \" : \"\"}`.repeat(repetition);\n const rule = this.options.ruleSpaces === true ? value.slice(0, -1) : value;\n const frontmatterFences = new Set<string>(this.syntax.frontmatter.map(frontmatterFence));\n\n if (!frontmatterFences.has(rule)) {\n return rule;\n }\n\n let separator = \" \";\n let safeRule = Array.from({ length: repetition }, () => marker).join(separator);\n\n while (frontmatterFences.has(safeRule)) {\n separator += \" \";\n safeRule = Array.from({ length: repetition }, () => marker).join(separator);\n }\n\n return safeRule;\n }\n\n private codeBlock(node: CodeBlockNode, info: FormatInfo): string {\n const marker = this.options.fence ?? \"`\";\n const suffix = marker === \"`\" ? \"GraveAccent\" : \"Tilde\";\n const sequence = marker.repeat(Math.max(3, longestRun(node.value, marker) + 1));\n const tracker = new FormatTracker(info);\n let value = tracker.move(sequence);\n\n if (node.language !== undefined && node.language.length > 0) {\n const exitLanguage = this.enter(`codeFencedLang${suffix}`);\n value += tracker.move(this.safe(node.language, { after: \" \", before: value, encode: [\"`\"] }));\n exitLanguage();\n }\n\n if (node.meta !== undefined && node.meta.length > 0) {\n const exitMeta = this.enter(`codeFencedMeta${suffix}`);\n value += tracker.move(\n ` ${this.safe(node.meta, { after: \"\\n\", before: value, encode: [\"`\"] })}`,\n );\n exitMeta();\n }\n\n value += tracker.move(\"\\n\");\n\n if (node.value.length > 0) {\n value += tracker.move(`${node.value}\\n`);\n }\n\n return value + sequence;\n }\n\n private blockQuote(node: BlockQuoteNode, info: FormatInfo): string {\n const exit = this.enter(\"blockquote\");\n const tracker = new FormatTracker(info);\n tracker.move(\"> \");\n tracker.shift(2);\n\n const value = indentLines(\n this.flow(node.children, { after: \"\\n\", before: \"\\n\", ...tracker.current() }),\n (line, blank) => `>${blank ? \"\" : \" \"}${line}`,\n );\n\n exit();\n\n return value;\n }\n\n private list(node: ListNode, info: FormatInfo): string {\n const exit = this.enter(\"list\");\n\n let marker: \"*\" | \"+\" | \"-\" | \".\" | \")\" = node.ordered\n ? (this.options.bulletOrdered ?? \".\")\n : (this.options.bullet ?? \"-\");\n\n if (\n this.bulletLastUsed === marker ||\n (!node.ordered &&\n marker === (this.options.rule ?? \"-\") &&\n node.children.some((item) => item.children[0]?.kind === \"thematicBreak\"))\n ) {\n marker = alternateListMarker(marker);\n }\n\n const values = node.children.map((item, index) =>\n this.listItem(item, node, index, marker, info),\n );\n\n this.bulletLastUsed = marker;\n exit();\n\n return values.join(node.spread ? \"\\n\\n\" : \"\\n\");\n }\n\n private listItem(\n item: ListItemNode,\n parent: ListNode,\n index: number,\n listMarker: \"*\" | \"+\" | \"-\" | \".\" | \")\",\n info: FormatInfo,\n ): string {\n const marker = parent.ordered\n ? `${parent.start + (this.options.incrementListMarker === false ? 0 : index)}${listMarker}`\n : listMarker;\n\n let size = marker.length + 1;\n const indentation = this.options.listItemIndent ?? \"one\";\n\n if (indentation === \"tab\" || (indentation === \"mixed\" && (parent.spread || item.spread))) {\n size = Math.ceil(size / 4) * 4;\n }\n\n const prefix = `${marker}${\" \".repeat(size - marker.length)}`;\n const tracker = new FormatTracker(info);\n tracker.move(prefix);\n tracker.shift(size);\n const exit = this.enter(\"listItem\");\n\n let body = this.flow(\n item.children,\n { after: \"\\n\", before: \"\\n\", ...tracker.current() },\n parent.spread || item.spread,\n );\n\n if (item.checked !== undefined && item.children[0]?.kind === \"paragraph\") {\n body = `[${item.checked ? \"x\" : \" \"}] ${body}`;\n }\n\n const value = indentLines(body, (line, blank, lineIndex) =>\n lineIndex === 0\n ? `${blank ? marker : prefix}${line}`\n : `${blank ? \"\" : \" \".repeat(size)}${line}`,\n );\n\n exit();\n\n return value;\n }\n\n private definition(node: DefinitionNode, info: FormatInfo): string {\n const exit = this.enter(\"definition\");\n const tracker = new FormatTracker(info);\n const exitLabel = this.enter(\"label\");\n let value = tracker.move(\"[\");\n value += tracker.move(formatAssociationIdentifier(node.identifier));\n value += tracker.move(\"]: \");\n exitLabel();\n value += tracker.move(this.destination(node.url, value, node.title === undefined ? \"\\n\" : \" \"));\n\n if (node.title !== undefined) {\n value += tracker.move(this.title(node.title, value));\n }\n\n exit();\n\n return value;\n }\n\n private footnoteDefinition(node: FootnoteDefinitionNode, info: FormatInfo): string {\n const exit = this.enter(\"footnoteDefinition\");\n const tracker = new FormatTracker(info);\n const exitLabel = this.enter(\"label\");\n let value = tracker.move(\"[^\");\n value += tracker.move(this.safe(node.label, { before: value, after: \"]\" }));\n value += tracker.move(\"]:\");\n exitLabel();\n\n if (node.children.length > 0) {\n tracker.shift(4);\n\n const content = this.flow(node.children, {\n after: \"\\n\",\n before: \"\\n\",\n ...tracker.current(),\n });\n\n const blankFirst = this.options.footnoteFirstLineBlank === true;\n value +=\n (blankFirst ? \"\\n\" : \" \") +\n indentLines(content, (line, blank, lineIndex) =>\n !blankFirst && lineIndex === 0 ? line : `${blank ? \"\" : \" \"}${line}`,\n );\n }\n\n exit();\n\n return value;\n }\n\n private footnoteReference(node: FootnoteReferenceNode): string {\n const exit = this.enter(\"footnoteReference\");\n const exitReference = this.enter(\"reference\");\n const value = `[^${this.safe(node.label, { before: \"[^\", after: \"]\" })}]`;\n exitReference();\n exit();\n\n return value;\n }\n\n private attention(\n children: readonly MdxNode[],\n info: FormatInfo,\n marker: \"*\" | \"_\",\n strong: boolean,\n ): string {\n const sequence = strong ? marker + marker : marker;\n const exit = this.enter(strong ? \"strong\" : \"emphasis\");\n const tracker = new FormatTracker(info);\n const before = tracker.move(sequence);\n\n const content = tracker.move(\n this.phrasing(children, { after: marker, before, ...tracker.current() }),\n );\n\n exit();\n\n return before + content + sequence;\n }\n\n private attentionMarker(marker: \"*\" | \"_\", strong: boolean): \"*\" | \"_\" {\n return this.stack.includes(strong ? \"strong\" : \"emphasis\")\n ? marker === \"*\"\n ? \"_\"\n : \"*\"\n : marker;\n }\n\n private strikethrough(children: readonly MdxNode[], info: FormatInfo): string {\n const exit = this.enter(\"strikethrough\");\n const tracker = new FormatTracker(info);\n const before = tracker.move(\"~~\");\n\n const content = tracker.move(\n this.phrasing(children, { after: \"~\", before, ...tracker.current() }),\n );\n\n exit();\n\n return before + content + \"~~\";\n }\n\n private link(node: LinkNode, info: FormatInfo): string {\n const exit = this.enter(\"link\");\n const tracker = new FormatTracker(info);\n const exitLabel = this.enter(\"label\");\n let value = tracker.move(\"[\");\n value += tracker.move(\n this.phrasing(node.children, { after: \"]\", before: value, ...tracker.current() }),\n );\n value += tracker.move(\"](\");\n exitLabel();\n value += tracker.move(this.destination(node.url, value, node.title === undefined ? \")\" : \" \"));\n\n if (node.title !== undefined) {\n value += tracker.move(this.title(node.title, value));\n }\n\n exit();\n\n return value + \")\";\n }\n\n private image(node: ImageNode, info: FormatInfo): string {\n const exit = this.enter(\"image\");\n const tracker = new FormatTracker(info);\n const exitLabel = this.enter(\"label\");\n let value = tracker.move(\"![\");\n value += tracker.move(this.safe(node.alt, { before: value, after: \"]\" }));\n value += tracker.move(\"](\");\n exitLabel();\n value += tracker.move(this.destination(node.url, value, node.title === undefined ? \")\" : \" \"));\n\n if (node.title !== undefined) {\n value += tracker.move(this.title(node.title, value));\n }\n\n exit();\n\n return value + \")\";\n }\n\n private linkReference(node: LinkReferenceNode, info: FormatInfo): string {\n const exit = this.enter(\"linkReference\");\n const exitLabel = this.enter(\"label\");\n const label = this.phrasing(node.children, { ...info, before: \"[\", after: \"]\" });\n exitLabel();\n const value = `[${label}]${this.referenceSuffix(node.referenceKind, node.identifier, label)}`;\n exit();\n\n return value;\n }\n\n private imageReference(node: ImageReferenceNode, _info: FormatInfo): string {\n const exit = this.enter(\"imageReference\");\n const exitLabel = this.enter(\"label\");\n const alt = this.safe(node.alt, { before: \"![\", after: \"]\" });\n exitLabel();\n const value = `![${alt}]${this.referenceSuffix(node.referenceKind, node.identifier, alt)}`;\n exit();\n\n return value;\n }\n\n private referenceSuffix(\n kind: LinkReferenceNode[\"referenceKind\"],\n identifier: string,\n label: string,\n ): string {\n const reference = this.referenceIdentifier(identifier);\n\n if (label.length > 0 && normalizeIdentifier(label) === normalizeIdentifier(reference)) {\n if (kind === \"shortcut\") {\n return \"\";\n }\n\n if (kind === \"collapsed\") {\n return \"[]\";\n }\n }\n\n return `[${reference}]`;\n }\n\n private referenceIdentifier(identifier: string): string {\n return formatAssociationIdentifier(identifier);\n }\n\n private destination(value: string, before: string, after: string): string {\n if (value.length === 0 || /[\\0- \\u007F]/u.test(value)) {\n const exit = this.enter(\"destinationLiteral\");\n const result = `<${this.safe(value, { before: `${before}<`, after: \">\" })}>`;\n exit();\n\n return result;\n }\n\n const exit = this.enter(\"destinationRaw\");\n const result = this.safe(value, { before, after });\n exit();\n\n return result;\n }\n\n private title(value: string, before: string): string {\n const quote = this.options.quote ?? '\"';\n const exit = this.enter(quote === '\"' ? \"titleQuote\" : \"titleApostrophe\");\n const result = ` ${quote}${this.safe(value, { before: `${before} ${quote}`, after: quote })}${quote}`;\n exit();\n\n return result;\n }\n\n public safe(value: string, info: FormatSafeInfo): string {\n return safeSource(this, value, info);\n }\n\n public enter(construct: FormatConstruct): () => void {\n this.stack.push(construct);\n\n return (): void => {\n this.stack.pop();\n };\n }\n}\n\nfunction peek(node: MdxNode, options: FormatOptions): string {\n switch (node.kind) {\n case \"textDirective\":\n return \":\";\n case \"inlineMath\":\n return node.format === \"dollar\" ? \"$\" : \"\\\\\";\n case \"image\":\n case \"imageReference\":\n return \"!\";\n case \"footnoteReference\":\n case \"link\":\n case \"linkReference\":\n return \"[\";\n case \"emphasis\":\n return options.emphasis ?? \"*\";\n case \"strong\":\n return options.strong ?? \"*\";\n case \"delete\":\n return \"~\";\n case \"inlineCode\":\n return \"`\";\n case \"rawHtmlInline\":\n case \"jsxTextElement\":\n return \"<\";\n case \"hardBreak\":\n return \"\\\\\";\n case \"inlineExpression\":\n return \"{\";\n case \"text\":\n return node.value.charAt(0);\n default:\n return \"\";\n }\n}\n\nfunction formatInlineCode(input: string): string {\n const value = input.replace(/\\r\\n?|\\n/gu, \" \");\n let sequence = \"`\";\n\n while (new RegExp(`(^|[^\\`])${sequence}([^\\`]|$)`, \"u\").test(value)) {\n sequence += \"`\";\n }\n\n const padded =\n /[^ \\r\\n]/u.test(value) &&\n ((/^[ \\r\\n]/u.test(value) && /[ \\r\\n]$/u.test(value)) || /^`|`$/u.test(value))\n ? ` ${value} `\n : value;\n\n return `${sequence}${padded}${sequence}`;\n}\n\nfunction alternateListMarker(marker: \"*\" | \"+\" | \"-\" | \".\" | \")\"): \"*\" | \"-\" | \".\" | \")\" {\n if (marker === \".\") {\n return \")\";\n }\n\n if (marker === \")\") {\n return \".\";\n }\n\n return marker === \"*\" ? \"-\" : \"*\";\n}\n\nfunction containsLineEnding(node: MdxNode): boolean {\n if (node.kind === \"hardBreak\") {\n return true;\n }\n\n if ((node.kind === \"text\" || node.kind === \"rawHtmlInline\") && /\\r\\n?|\\n/u.test(node.value)) {\n return true;\n }\n\n return mdxChildren(node).some(containsLineEnding);\n}\n\nfunction encodeBlankLineEndings(value: string): string {\n return value.replace(/(?:(?:\\r\\n?|\\n)){2,}/gu, encodeLineEnding);\n}\n\nfunction encodeLineEnding(value: string): string {\n let result = \"\";\n\n for (const character of value) {\n result += encodeNumericCharacterReference(character.codePointAt(0) ?? 0);\n }\n\n return result;\n}\n\nfunction formatAssociationIdentifier(value: string): string {\n return value.replace(/[!-/:-@[-`{-~]/gu, \"\\\\$&\");\n}\n\nfunction escapeRegularExpression(value: string): string {\n return value.replace(/[|\\\\{}()[\\]^$+*?.]/gu, \"\\\\$&\");\n}\n"],"mappings":";;;;;;;;;;;;;AAuDA,SAAgB,UAAU,MAAe,UAAyB,CAAC,GAAW;CAC5E,OAAO,IAAI,UAAU,SAAS,kBAAkB,IAAI,GAAG,YAAY,IAAI,CAAC,CAAC,CAAC,OAAO,MAAM,QAAQ;AACjG;AAEA,IAAM,YAAN,MAA4D;CAC1D,QAA2C,CAAC;CAC5C;CACA,mCAAoC,IAAI,IAAiC;CACzE;CACA;CACA;CAEA,YACE,SACA,oBACA,iBACA;EACA,KAAK,UAAU,EAAE,GAAG,QAAQ;EAC5B,KAAK,SAAS,qBAAqB,QAAQ,MAAM;EACjD,KAAK,SAAS;GACZ,GAAG;GACH;IAAE,WAAW;IAAK,aAAa;GAAW;GAC1C;IAAE,SAAS;IAAM,WAAW;GAAI;GAChC;IAAE,WAAW;IAAK,aAAa;GAAW;GAC1C;IAAE,SAAS;IAAM,WAAW;GAAI;GAChC,GAAI,sBAAsB,KAAK,OAAO,aACjC,CACC;IACE,QAAQ;IACR,WAAW;IAC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K,MAAM,OAAO,CAAC;EAC5B,SACE,OAAO;CACX;AACF;AAEA,SAAS,iBAAiB,OAAuB;CAC/C,MAAM,QAAQ,MAAM,QAAQ,cAAc,GAAG;CAC7C,IAAI,WAAW;CAEf,OAAO,IAAI,OAAO,YAAY,SAAS,YAAY,GAAG,CAAC,CAAC,KAAK,KAAK,GAChE,YAAY;CAGd,MAAM,SACJ,YAAY,KAAK,KAAK,MACpB,YAAY,KAAK,KAAK,KAAK,YAAY,KAAK,KAAK,KAAM,SAAS,KAAK,KAAK,KACxE,IAAI,MAAM,KACV;CAEN,OAAO,GAAG,WAAW,SAAS;AAChC;AAEA,SAAS,oBAAoB,QAA4D;CACvF,IAAI,WAAW,KACb,OAAO;CAGT,IAAI,WAAW,KACb,OAAO;CAGT,OAAO,WAAW,MAAM,MAAM;AAChC;AAEA,SAAS,mBAAmB,MAAwB;CAClD,IAAI,KAAK,SAAS,aAChB,OAAO;CAGT,KAAK,KAAK,SAAS,UAAU,KAAK,SAAS,oBAAoB,YAAY,KAAK,KAAK,KAAK,GACxF,OAAO;CAGT,OAAO,YAAY,IAAI,CAAC,CAAC,KAAK,kBAAkB;AAClD;AAEA,SAAS,uBAAuB,OAAuB;CACrD,OAAO,MAAM,QAAQ,0BAA0B,gBAAgB;AACjE;AAEA,SAAS,iBAAiB,OAAuB;CAC/C,IAAI,SAAS;CAEb,KAAK,MAAM,aAAa,OACtB,UAAU,gCAAgC,UAAU,YAAY,CAAC,KAAK,CAAC;CAGzE,OAAO;AACT;AAEA,SAAS,4BAA4B,OAAuB;CAC1D,OAAO,MAAM,QAAQ,oBAAoB,MAAM;AACjD;AAEA,SAAS,wBAAwB,OAAuB;CACtD,OAAO,MAAM,QAAQ,wBAAwB,MAAM;AACrD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FrontmatterFormat } from "./syntax-options.mjs";
|
|
2
|
+
import { FrontmatterObject } from "./model.mjs";
|
|
3
|
+
import { SourceSpan } from "./source.mjs";
|
|
4
|
+
import { DiagnosticReporter } from "./diagnostics.mjs";
|
|
5
|
+
//#region src/frontmatter-decode.d.ts
|
|
6
|
+
interface DecodeOptions {
|
|
7
|
+
readonly diagnostics: DiagnosticReporter;
|
|
8
|
+
readonly format: FrontmatterFormat;
|
|
9
|
+
readonly source: string;
|
|
10
|
+
readonly span: SourceSpan;
|
|
11
|
+
}
|
|
12
|
+
export declare function decodeFrontmatter(options: DecodeOptions): FrontmatterObject | undefined;
|
|
13
|
+
//#endregion
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=frontmatter-decode.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter-decode.d.mts","names":[],"sources":["../src/frontmatter-decode.ts"],"mappings":";;;;;UAkBU;WACC,aAAa;WACb,QAAQ;WACR;WACA,MAAM;;wBAOD,kBAAkB,SAAS,gBAAgB"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { isBigInt, isBoolean, isFunction, isNumber, isObject, isPlainObject, isString, isSymbol } from "@temelj/value";
|
|
2
|
+
import { TomlDate, TomlError, parse } from "smol-toml";
|
|
3
|
+
import { parseDocument } from "yaml";
|
|
4
|
+
//#region src/frontmatter-decode.ts
|
|
5
|
+
const maximumYamlAliases = 100;
|
|
6
|
+
const maximumTomlDepth = 256;
|
|
7
|
+
function decodeFrontmatter(options) {
|
|
8
|
+
return options.format === "yaml" ? decodeYaml(options) : decodeToml(options);
|
|
9
|
+
}
|
|
10
|
+
function decodeYaml(options) {
|
|
11
|
+
let document;
|
|
12
|
+
try {
|
|
13
|
+
document = parseDocument(options.source, {
|
|
14
|
+
customTags: [],
|
|
15
|
+
intAsBigInt: true,
|
|
16
|
+
logLevel: "silent",
|
|
17
|
+
prettyErrors: false,
|
|
18
|
+
resolveKnownTags: false,
|
|
19
|
+
schema: "core",
|
|
20
|
+
strict: true,
|
|
21
|
+
stringKeys: true,
|
|
22
|
+
uniqueKeys: true,
|
|
23
|
+
version: "1.2"
|
|
24
|
+
});
|
|
25
|
+
} catch (cause) {
|
|
26
|
+
addParserFailure(options, cause);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
for (const warning of document.warnings) options.diagnostics.add({
|
|
30
|
+
code: yamlCode(warning.code),
|
|
31
|
+
message: warning.message,
|
|
32
|
+
severity: "warning",
|
|
33
|
+
span: relativeSpan(options.span, warning.pos[0], warning.pos[1])
|
|
34
|
+
});
|
|
35
|
+
for (const error of document.errors) options.diagnostics.add({
|
|
36
|
+
code: yamlCode(error.code),
|
|
37
|
+
message: error.message,
|
|
38
|
+
severity: "error",
|
|
39
|
+
span: relativeSpan(options.span, error.pos[0], error.pos[1])
|
|
40
|
+
});
|
|
41
|
+
if (document.errors.length > 0) return;
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = document.contents === null ? {} : document.toJS({ maxAliasCount: maximumYamlAliases });
|
|
45
|
+
} catch (cause) {
|
|
46
|
+
addParserFailure(options, cause);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
return convertRoot(parsed, options);
|
|
50
|
+
}
|
|
51
|
+
function decodeToml(options) {
|
|
52
|
+
let parsed;
|
|
53
|
+
try {
|
|
54
|
+
parsed = parse(options.source, {
|
|
55
|
+
integersAsBigInt: "asNeeded",
|
|
56
|
+
maxDepth: maximumTomlDepth
|
|
57
|
+
});
|
|
58
|
+
} catch (cause) {
|
|
59
|
+
if (cause instanceof TomlError) {
|
|
60
|
+
const offset = lineColumnOffset(options.source, cause.line, cause.column);
|
|
61
|
+
options.diagnostics.add({
|
|
62
|
+
code: "mdx.frontmatter.toml",
|
|
63
|
+
message: cause.message,
|
|
64
|
+
severity: "error",
|
|
65
|
+
span: relativeSpan(options.span, offset, offset + 1)
|
|
66
|
+
});
|
|
67
|
+
} else addParserFailure(options, cause);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
return convertRoot(parsed, options);
|
|
71
|
+
}
|
|
72
|
+
function convertRoot(value, options) {
|
|
73
|
+
if (!isPlainObject(value)) {
|
|
74
|
+
options.diagnostics.add({
|
|
75
|
+
code: "mdx.frontmatter.root",
|
|
76
|
+
message: "FrontmatterNode must contain a mapping at its root",
|
|
77
|
+
severity: "error",
|
|
78
|
+
span: options.span
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
return convertObject(value, options, "$", /* @__PURE__ */ new WeakSet());
|
|
83
|
+
}
|
|
84
|
+
function convertValue(value, options, path, active) {
|
|
85
|
+
if (value === null || isBoolean(value) || isNumber(value) || isString(value)) return value;
|
|
86
|
+
if (isBigInt(value)) return value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : value;
|
|
87
|
+
if (value instanceof TomlDate) return convertTemporal(value);
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
if (active.has(value)) return invalidValue(options, path, "cyclic alias");
|
|
90
|
+
active.add(value);
|
|
91
|
+
const converted = [];
|
|
92
|
+
for (const [index, item] of value.entries()) {
|
|
93
|
+
const result = convertValue(item, options, `${path}[${index}]`, active);
|
|
94
|
+
if (result === void 0) return;
|
|
95
|
+
converted.push(result);
|
|
96
|
+
}
|
|
97
|
+
active.delete(value);
|
|
98
|
+
Object.freeze(converted);
|
|
99
|
+
return converted;
|
|
100
|
+
}
|
|
101
|
+
if (isPlainObject(value)) return convertObject(value, options, path, active);
|
|
102
|
+
return invalidValue(options, path, describeValue(value));
|
|
103
|
+
}
|
|
104
|
+
function convertObject(value, options, path, active) {
|
|
105
|
+
if (active.has(value)) return invalidValue(options, path, "cyclic alias");
|
|
106
|
+
active.add(value);
|
|
107
|
+
const converted = {};
|
|
108
|
+
for (const [key, item] of Object.entries(value)) {
|
|
109
|
+
const result = convertValue(item, options, propertyPath(path, key), active);
|
|
110
|
+
if (result === void 0) return;
|
|
111
|
+
Object.defineProperty(converted, key, {
|
|
112
|
+
configurable: false,
|
|
113
|
+
enumerable: true,
|
|
114
|
+
value: result,
|
|
115
|
+
writable: false
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
active.delete(value);
|
|
119
|
+
Object.freeze(converted);
|
|
120
|
+
return converted;
|
|
121
|
+
}
|
|
122
|
+
function convertTemporal(value) {
|
|
123
|
+
const type = value.isDateTime() ? value.isLocal() ? "local-date-time" : "offset-date-time" : value.isDate() ? "local-date" : "local-time";
|
|
124
|
+
return Object.freeze({
|
|
125
|
+
kind: "temporal",
|
|
126
|
+
type,
|
|
127
|
+
value: value.toISOString()
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function invalidValue(options, path, description) {
|
|
131
|
+
options.diagnostics.add({
|
|
132
|
+
code: "mdx.frontmatter.value",
|
|
133
|
+
message: `Unsupported frontmatter value at ${path}: ${description}`,
|
|
134
|
+
severity: "error",
|
|
135
|
+
span: options.span
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function addParserFailure(options, cause) {
|
|
139
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
140
|
+
options.diagnostics.add({
|
|
141
|
+
code: `mdx.frontmatter.${options.format}`,
|
|
142
|
+
message,
|
|
143
|
+
severity: "error",
|
|
144
|
+
span: options.span
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
function yamlCode(code) {
|
|
148
|
+
return code === "RESOURCE_EXHAUSTION" ? "mdx.frontmatter.resource" : "mdx.frontmatter.yaml";
|
|
149
|
+
}
|
|
150
|
+
function relativeSpan(span, start, end) {
|
|
151
|
+
const length = span.end - span.start;
|
|
152
|
+
const relativeStart = Math.max(0, Math.min(start, length));
|
|
153
|
+
const relativeEnd = Math.max(relativeStart, Math.min(end, length));
|
|
154
|
+
return Object.freeze({
|
|
155
|
+
file: span.file,
|
|
156
|
+
start: span.start + relativeStart,
|
|
157
|
+
end: span.start + relativeEnd
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function lineColumnOffset(source, line, column) {
|
|
161
|
+
const lineStart = lineStartOffsets(source)[Math.max(0, line - 1)] ?? source.length;
|
|
162
|
+
return Math.min(source.length, lineStart + Math.max(0, column - 1));
|
|
163
|
+
}
|
|
164
|
+
function propertyPath(path, key) {
|
|
165
|
+
return /^[A-Za-z_$][\w$]*$/u.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`;
|
|
166
|
+
}
|
|
167
|
+
function describeValue(value) {
|
|
168
|
+
if (value === void 0) return "undefined";
|
|
169
|
+
if (isFunction(value)) return "function";
|
|
170
|
+
if (isSymbol(value)) return "symbol";
|
|
171
|
+
if (value instanceof Map) return "Map";
|
|
172
|
+
if (value instanceof Set) return "Set";
|
|
173
|
+
if (value instanceof Date) return "Date";
|
|
174
|
+
return isObject(value) ? value.constructor?.name ?? "object" : String(value);
|
|
175
|
+
}
|
|
176
|
+
function lineStartOffsets(source) {
|
|
177
|
+
const offsets = [0];
|
|
178
|
+
for (let index = 0; index < source.length; index++) if (source[index] === "\r") {
|
|
179
|
+
if (source[index + 1] === "\n") index++;
|
|
180
|
+
offsets.push(index + 1);
|
|
181
|
+
} else if (source[index] === "\n") offsets.push(index + 1);
|
|
182
|
+
return offsets;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
export { decodeFrontmatter };
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=frontmatter-decode.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter-decode.mjs","names":["parseToml"],"sources":["../src/frontmatter-decode.ts"],"sourcesContent":["import {\n isBoolean,\n isNumber,\n isString,\n isBigInt,\n isFunction,\n isSymbol,\n isObject,\n isPlainObject,\n} from \"@temelj/value\";\nimport { parse as parseToml, TomlDate, TomlError } from \"smol-toml\";\nimport { parseDocument } from \"yaml\";\n\nimport type { DiagnosticReporter } from \"./diagnostics.ts\";\nimport type { FrontmatterObject, FrontmatterTemporal, FrontmatterValue } from \"./model.ts\";\nimport type { SourceSpan } from \"./source.ts\";\nimport type { FrontmatterFormat } from \"./syntax-options.ts\";\n\ninterface DecodeOptions {\n readonly diagnostics: DiagnosticReporter;\n readonly format: FrontmatterFormat;\n readonly source: string;\n readonly span: SourceSpan;\n}\n\nconst maximumYamlAliases = 100;\n\nconst maximumTomlDepth = 256;\n\nexport function decodeFrontmatter(options: DecodeOptions): FrontmatterObject | undefined {\n return options.format === \"yaml\" ? decodeYaml(options) : decodeToml(options);\n}\n\nfunction decodeYaml(options: DecodeOptions): FrontmatterObject | undefined {\n let document: ReturnType<typeof parseDocument>;\n\n try {\n document = parseDocument(options.source, {\n customTags: [],\n intAsBigInt: true,\n logLevel: \"silent\",\n prettyErrors: false,\n resolveKnownTags: false,\n schema: \"core\",\n strict: true,\n stringKeys: true,\n uniqueKeys: true,\n version: \"1.2\",\n });\n } catch (cause) {\n addParserFailure(options, cause);\n\n return undefined;\n }\n\n for (const warning of document.warnings) {\n options.diagnostics.add({\n code: yamlCode(warning.code),\n message: warning.message,\n severity: \"warning\",\n span: relativeSpan(options.span, warning.pos[0], warning.pos[1]),\n });\n }\n\n for (const error of document.errors) {\n options.diagnostics.add({\n code: yamlCode(error.code),\n message: error.message,\n severity: \"error\",\n span: relativeSpan(options.span, error.pos[0], error.pos[1]),\n });\n }\n\n if (document.errors.length > 0) {\n return undefined;\n }\n\n let parsed: unknown;\n\n try {\n parsed = document.contents === null ? {} : document.toJS({ maxAliasCount: maximumYamlAliases });\n } catch (cause) {\n addParserFailure(options, cause);\n\n return undefined;\n }\n\n return convertRoot(parsed, options);\n}\n\nfunction decodeToml(options: DecodeOptions): FrontmatterObject | undefined {\n let parsed: unknown;\n\n try {\n parsed = parseToml(options.source, {\n integersAsBigInt: \"asNeeded\",\n maxDepth: maximumTomlDepth,\n });\n } catch (cause) {\n if (cause instanceof TomlError) {\n const offset = lineColumnOffset(options.source, cause.line, cause.column);\n options.diagnostics.add({\n code: \"mdx.frontmatter.toml\",\n message: cause.message,\n severity: \"error\",\n span: relativeSpan(options.span, offset, offset + 1),\n });\n } else {\n addParserFailure(options, cause);\n }\n\n return undefined;\n }\n\n return convertRoot(parsed, options);\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- YAML/TOML root input is validated here.\nfunction convertRoot(value: unknown, options: DecodeOptions): FrontmatterObject | undefined {\n if (!isPlainObject(value)) {\n options.diagnostics.add({\n code: \"mdx.frontmatter.root\",\n message: \"FrontmatterNode must contain a mapping at its root\",\n severity: \"error\",\n span: options.span,\n });\n\n return undefined;\n }\n\n return convertObject(value, options, \"$\", new WeakSet<object>());\n}\n\nfunction convertValue(\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- Recursively validates parser values before producing FrontmatterValue.\n value: unknown,\n options: DecodeOptions,\n path: string,\n active: WeakSet<object>,\n): FrontmatterValue | undefined {\n if (value === null || isBoolean(value) || isNumber(value) || isString(value)) {\n return value;\n }\n\n if (isBigInt(value)) {\n return value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER)\n ? Number(value)\n : value;\n }\n\n if (value instanceof TomlDate) {\n return convertTemporal(value);\n }\n\n if (Array.isArray(value)) {\n if (active.has(value)) {\n return invalidValue(options, path, \"cyclic alias\");\n }\n\n active.add(value);\n const converted: FrontmatterValue[] = [];\n\n for (const [index, item] of value.entries()) {\n const result = convertValue(item, options, `${path}[${index}]`, active);\n\n if (result === undefined) {\n return undefined;\n }\n\n converted.push(result);\n }\n\n active.delete(value);\n Object.freeze(converted);\n\n return converted;\n }\n\n if (isPlainObject(value)) {\n return convertObject(value, options, path, active);\n }\n\n return invalidValue(options, path, describeValue(value));\n}\n\nfunction convertObject(\n // oxlint-disable-next-line anti-slop/no-object-parameters -- YAML/TOML mapping boundary; every entry is converted to FrontmatterValue below.\n value: object,\n options: DecodeOptions,\n path: string,\n active: WeakSet<object>,\n): FrontmatterObject | undefined {\n if (active.has(value)) {\n return invalidValue(options, path, \"cyclic alias\");\n }\n\n active.add(value);\n const converted: Record<string, FrontmatterValue> = {};\n\n for (const [key, item] of Object.entries(value)) {\n const itemPath = propertyPath(path, key);\n const result = convertValue(item, options, itemPath, active);\n\n if (result === undefined) {\n return undefined;\n }\n\n Object.defineProperty(converted, key, {\n configurable: false,\n enumerable: true,\n value: result,\n writable: false,\n });\n }\n\n active.delete(value);\n Object.freeze(converted);\n\n return converted;\n}\n\nfunction convertTemporal(value: TomlDate): FrontmatterTemporal {\n const type = value.isDateTime()\n ? value.isLocal()\n ? \"local-date-time\"\n : \"offset-date-time\"\n : value.isDate()\n ? \"local-date\"\n : \"local-time\";\n\n return Object.freeze({ kind: \"temporal\", type, value: value.toISOString() });\n}\n\nfunction invalidValue(options: DecodeOptions, path: string, description: string): undefined {\n options.diagnostics.add({\n code: \"mdx.frontmatter.value\",\n message: `Unsupported frontmatter value at ${path}: ${description}`,\n severity: \"error\",\n span: options.span,\n });\n\n return undefined;\n}\n\nfunction addParserFailure(options: DecodeOptions, cause: unknown): void {\n const message = cause instanceof Error ? cause.message : String(cause);\n options.diagnostics.add({\n code: `mdx.frontmatter.${options.format}`,\n message,\n severity: \"error\",\n span: options.span,\n });\n}\n\nfunction yamlCode(code: string): string {\n return code === \"RESOURCE_EXHAUSTION\" ? \"mdx.frontmatter.resource\" : \"mdx.frontmatter.yaml\";\n}\n\nfunction relativeSpan(span: SourceSpan, start: number, end: number): SourceSpan {\n const length = span.end - span.start;\n const relativeStart = Math.max(0, Math.min(start, length));\n const relativeEnd = Math.max(relativeStart, Math.min(end, length));\n\n return Object.freeze({\n file: span.file,\n start: span.start + relativeStart,\n end: span.start + relativeEnd,\n });\n}\n\nfunction lineColumnOffset(source: string, line: number, column: number): number {\n const lineStart = lineStartOffsets(source)[Math.max(0, line - 1)] ?? source.length;\n\n return Math.min(source.length, lineStart + Math.max(0, column - 1));\n}\n\nfunction propertyPath(path: string, key: string): string {\n return /^[A-Za-z_$][\\w$]*$/u.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`;\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Describes a rejected value at the YAML/TOML validation boundary.\nfunction describeValue(value: unknown): string {\n if (value === undefined) {\n return \"undefined\";\n }\n\n if (isFunction(value)) {\n return \"function\";\n }\n\n if (isSymbol(value)) {\n return \"symbol\";\n }\n\n if (value instanceof Map) {\n return \"Map\";\n }\n\n if (value instanceof Set) {\n return \"Set\";\n }\n\n if (value instanceof Date) {\n return \"Date\";\n }\n\n return isObject(value) ? (value.constructor?.name ?? \"object\") : String(value);\n}\n\nfunction lineStartOffsets(source: string): readonly number[] {\n const offsets = [0];\n\n for (let index = 0; index < source.length; index++) {\n if (source[index] === \"\\r\") {\n if (source[index + 1] === \"\\n\") {\n index++;\n }\n\n offsets.push(index + 1);\n } else if (source[index] === \"\\n\") {\n offsets.push(index + 1);\n }\n }\n\n return offsets;\n}\n"],"mappings":";;;;AAyBA,MAAM,qBAAqB;AAE3B,MAAM,mBAAmB;AAEzB,SAAgB,kBAAkB,SAAuD;CACvF,OAAO,QAAQ,WAAW,SAAS,WAAW,OAAO,IAAI,WAAW,OAAO;AAC7E;AAEA,SAAS,WAAW,SAAuD;CACzE,IAAI;CAEJ,IAAI;EACF,WAAW,cAAc,QAAQ,QAAQ;GACvC,YAAY,CAAC;GACb,aAAa;GACb,UAAU;GACV,cAAc;GACd,kBAAkB;GAClB,QAAQ;GACR,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,SAAS;EACX,CAAC;CACH,SAAS,OAAO;EACd,iBAAiB,SAAS,KAAK;EAE/B;CACF;CAEA,KAAK,MAAM,WAAW,SAAS,UAC7B,QAAQ,YAAY,IAAI;EACtB,MAAM,SAAS,QAAQ,IAAI;EAC3B,SAAS,QAAQ;EACjB,UAAU;EACV,MAAM,aAAa,QAAQ,MAAM,QAAQ,IAAI,IAAI,QAAQ,IAAI,EAAE;CACjE,CAAC;CAGH,KAAK,MAAM,SAAS,SAAS,QAC3B,QAAQ,YAAY,IAAI;EACtB,MAAM,SAAS,MAAM,IAAI;EACzB,SAAS,MAAM;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GT,IAAI,SAAS,KAAK,GAChB,OAAO;CAGT,IAAI,iBAAiB,KACnB,OAAO;CAGT,IAAI,iBAAiB,KACnB,OAAO;CAGT,IAAI,iBAAiB,MACnB,OAAO;CAGT,OAAO,SAAS,KAAK,IAAK,MAAM,aAAa,QAAQ,WAAY,OAAO,KAAK;AAC/E;AAEA,SAAS,iBAAiB,QAAmC;CAC3D,MAAM,UAAU,CAAC,CAAC;CAElB,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SACzC,IAAI,OAAO,WAAW,MAAM;EAC1B,IAAI,OAAO,QAAQ,OAAO,MACxB;EAGF,QAAQ,KAAK,QAAQ,CAAC;CACxB,OAAO,IAAI,OAAO,WAAW,MAC3B,QAAQ,KAAK,QAAQ,CAAC;CAI1B,OAAO;AACT"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SourceRange } from "./ranges.mjs";
|
|
2
|
+
import { SourceFile } from "./source.mjs";
|
|
3
|
+
import { SchemaResult } from "@temelj/standard-schema";
|
|
4
|
+
//#region src/frontmatter-schema.d.ts
|
|
5
|
+
/** Converts Standard Schema failures to the shared frontmatter diagnostics. */
|
|
6
|
+
export declare function frontmatterSchemaValue<T>(result: SchemaResult<T>, file: SourceFile, origin: SourceRange | undefined): T;
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=frontmatter-schema.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter-schema.d.mts","names":[],"sources":["../src/frontmatter-schema.ts"],"mappings":";;;;;wBAWgB,uBAAuB,GACrC,QAAQ,aAAa,IACrB,MAAM,YACN,QAAQ,0BACP"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createDiagnostic } from "./diagnostics.mjs";
|
|
2
|
+
import { FrontmatterError } from "./errors.mjs";
|
|
3
|
+
import { isObject } from "@temelj/value";
|
|
4
|
+
//#region src/frontmatter-schema.ts
|
|
5
|
+
/** Converts Standard Schema failures to the shared frontmatter diagnostics. */
|
|
6
|
+
function frontmatterSchemaValue(result, file, origin) {
|
|
7
|
+
if (result.issues !== void 0) {
|
|
8
|
+
const diagnostics = result.issues.map((issue) => createDiagnostic({
|
|
9
|
+
severity: "error",
|
|
10
|
+
code: "mdx.frontmatter.schema",
|
|
11
|
+
message: formatSchemaIssue(issue),
|
|
12
|
+
span: origin === void 0 ? void 0 : {
|
|
13
|
+
file,
|
|
14
|
+
...origin
|
|
15
|
+
}
|
|
16
|
+
}));
|
|
17
|
+
throw FrontmatterError.schemaValidationFailed(file, diagnostics, result.issues);
|
|
18
|
+
}
|
|
19
|
+
return result.value;
|
|
20
|
+
}
|
|
21
|
+
function formatSchemaIssue(issue) {
|
|
22
|
+
const path = issue.path?.map((part) => String(isObject(part) ? part.key : part)).join(".");
|
|
23
|
+
return path === void 0 || path.length === 0 ? issue.message : `${path}: ${issue.message}`;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { frontmatterSchemaValue };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=frontmatter-schema.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter-schema.mjs","names":[],"sources":["../src/frontmatter-schema.ts"],"sourcesContent":["import type { SchemaIssue, SchemaResult } from \"@temelj/standard-schema\";\n\nimport { isObject } from \"@temelj/value\";\n\nimport type { SourceRange } from \"./ranges.ts\";\nimport type { SourceFile } from \"./source.ts\";\n\nimport { createDiagnostic } from \"./diagnostics.ts\";\nimport { FrontmatterError } from \"./errors.ts\";\n\n/** Converts Standard Schema failures to the shared frontmatter diagnostics. */\nexport function frontmatterSchemaValue<T>(\n result: SchemaResult<T>,\n file: SourceFile,\n origin: SourceRange | undefined,\n): T {\n if (result.issues !== undefined) {\n const diagnostics = result.issues.map((issue) =>\n createDiagnostic({\n severity: \"error\",\n code: \"mdx.frontmatter.schema\",\n message: formatSchemaIssue(issue),\n span: origin === undefined ? undefined : { file, ...origin },\n }),\n );\n\n throw FrontmatterError.schemaValidationFailed(file, diagnostics, result.issues);\n }\n\n return result.value;\n}\n\nfunction formatSchemaIssue(issue: SchemaIssue): string {\n const path = issue.path?.map((part) => String(isObject(part) ? part.key : part)).join(\".\");\n\n return path === undefined || path.length === 0 ? issue.message : `${path}: ${issue.message}`;\n}\n"],"mappings":";;;;;AAWA,SAAgB,uBACd,QACA,MACA,QACG;CACH,IAAI,OAAO,WAAW,KAAA,GAAW;EAC/B,MAAM,cAAc,OAAO,OAAO,KAAK,UACrC,iBAAiB;GACf,UAAU;GACV,MAAM;GACN,SAAS,kBAAkB,KAAK;GAChC,MAAM,WAAW,KAAA,IAAY,KAAA,IAAY;IAAE;IAAM,GAAG;GAAO;EAC7D,CAAC,CACH;EAEA,MAAM,iBAAiB,uBAAuB,MAAM,aAAa,OAAO,MAAM;CAChF;CAEA,OAAO,OAAO;AAChB;AAEA,SAAS,kBAAkB,OAA4B;CACrD,MAAM,OAAO,MAAM,MAAM,KAAK,SAAS,OAAO,SAAS,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG;CAEzF,OAAO,SAAS,KAAA,KAAa,KAAK,WAAW,IAAI,MAAM,UAAU,GAAG,KAAK,IAAI,MAAM;AACrF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FrontmatterFormat, FrontmatterMode } from "./syntax-options.mjs";
|
|
2
|
+
import { FrontmatterObject } from "./model.mjs";
|
|
3
|
+
import { SourceFile } from "./source.mjs";
|
|
4
|
+
import { Diagnostic } from "./diagnostics.mjs";
|
|
5
|
+
import { ParserLimits } from "./parser/config.mjs";
|
|
6
|
+
import { Schema, SchemaOutput } from "@temelj/standard-schema";
|
|
7
|
+
//#region src/frontmatter.d.ts
|
|
8
|
+
export interface FrontmatterParseOptions {
|
|
9
|
+
/** Formats to recognize. Defaults to both YAML and TOML. */
|
|
10
|
+
readonly format?: FrontmatterMode;
|
|
11
|
+
/** Limits the entire input length in UTF-16 code units, without scanning its body. */
|
|
12
|
+
readonly limits?: Pick<ParserLimits, "maximumSourceLength">;
|
|
13
|
+
}
|
|
14
|
+
export interface FrontmatterParseSchemaOptions<TSchema extends Schema> extends FrontmatterParseOptions {
|
|
15
|
+
readonly frontmatterSchema: TSchema;
|
|
16
|
+
}
|
|
17
|
+
export interface FrontmatterParseResult<T = FrontmatterObject> {
|
|
18
|
+
readonly file: SourceFile;
|
|
19
|
+
readonly frontmatter: T;
|
|
20
|
+
/** Undefined when no complete, enabled frontmatter block was found. */
|
|
21
|
+
readonly format: FrontmatterFormat | undefined;
|
|
22
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Reads only the opening frontmatter block and optionally validates its metadata.
|
|
26
|
+
* @throws {ParseError} Invalid YAML or TOML.
|
|
27
|
+
* @throws {FrontmatterError} Schema validation fails.
|
|
28
|
+
* @throws {LimitError | ConfigurationError} Invalid or exceeded source-length limit.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseFrontmatter<TSchema extends Schema>(input: string | SourceFile, options: FrontmatterParseSchemaOptions<TSchema>): Promise<FrontmatterParseResult<SchemaOutput<TSchema>>>;
|
|
31
|
+
export declare function parseFrontmatter(input: string | SourceFile, options?: FrontmatterParseOptions): Promise<FrontmatterParseResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Reads frontmatter synchronously, including synchronous schema validation.
|
|
34
|
+
* @throws {StandardSchemaAsyncValidationError} The schema returns a promise.
|
|
35
|
+
* @throws {ParseError | FrontmatterError | LimitError | ConfigurationError} Parsing fails.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseFrontmatterSync<TSchema extends Schema>(input: string | SourceFile, options: FrontmatterParseSchemaOptions<TSchema>): FrontmatterParseResult<SchemaOutput<TSchema>>;
|
|
38
|
+
export declare function parseFrontmatterSync(input: string | SourceFile, options?: FrontmatterParseOptions): FrontmatterParseResult;
|
|
39
|
+
//#endregion
|
|
40
|
+
//# sourceMappingURL=frontmatter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.d.mts","names":[],"sources":["../src/frontmatter.ts"],"mappings":";;;;;;;iBAmBiB;;WAEN,SAAS;;WAET,SAAS,KAAK;;iBAGR,8BACf,gBAAgB,gBACR;WACC,mBAAmB;;iBAGb,uBAAuB,IAAI;WACjC,MAAM;WACN,aAAa;;WAEb,QAAQ;WACR,sBAAsB;;;;;;;;wBASjB,iBAAiB,gBAAgB,QAC/C,gBAAgB,YAChB,SAAS,8BAA8B,WACtC,QAAQ,uBAAuB,aAAa;wBAC/B,iBACd,gBAAgB,YAChB,UAAU,0BACT,QAAQ;;;;;;wBAwBK,qBAAqB,gBAAgB,QACnD,gBAAgB,YAChB,SAAS,8BAA8B,WACtC,uBAAuB,aAAa;wBACvB,qBACd,gBAAgB,YAChB,UAAU,0BACT"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { DiagnosticBag } from "./diagnostics.mjs";
|
|
2
|
+
import { LimitError, ParseError } from "./errors.mjs";
|
|
3
|
+
import { frontmatterSchemaValue } from "./frontmatter-schema.mjs";
|
|
4
|
+
import { SourceFile, sourceText } from "./source.mjs";
|
|
5
|
+
import { decodeFrontmatter } from "./frontmatter-decode.mjs";
|
|
6
|
+
import { resolveParserLimits } from "./parser/config.mjs";
|
|
7
|
+
import { isPromise } from "@temelj/value";
|
|
8
|
+
import { StandardSchemaAsyncValidationError } from "@temelj/standard-schema";
|
|
9
|
+
//#region src/frontmatter.ts
|
|
10
|
+
async function parseFrontmatter(input, options = {}) {
|
|
11
|
+
const { result, origin } = readFrontmatter(input, options);
|
|
12
|
+
if (options.frontmatterSchema === void 0) return result;
|
|
13
|
+
const validated = await options.frontmatterSchema["~standard"].validate(result.frontmatter);
|
|
14
|
+
return Object.freeze({
|
|
15
|
+
...result,
|
|
16
|
+
frontmatter: frontmatterSchemaValue(validated, result.file, origin)
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function parseFrontmatterSync(input, options = {}) {
|
|
20
|
+
const { result, origin } = readFrontmatter(input, options);
|
|
21
|
+
if (options.frontmatterSchema === void 0) return result;
|
|
22
|
+
const validated = options.frontmatterSchema["~standard"].validate(result.frontmatter);
|
|
23
|
+
if (isPromise(validated)) StandardSchemaAsyncValidationError.unsupported();
|
|
24
|
+
return Object.freeze({
|
|
25
|
+
...result,
|
|
26
|
+
frontmatter: frontmatterSchemaValue(validated, result.file, origin)
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function readFrontmatter(input, options) {
|
|
30
|
+
const file = input instanceof SourceFile ? input : new SourceFile(input);
|
|
31
|
+
const { maximumSourceLength } = resolveParserLimits(options.limits);
|
|
32
|
+
if (file.length > maximumSourceLength) throw LimitError.exceeded(file, "maximumSourceLength", maximumSourceLength, void 0, file.length);
|
|
33
|
+
const source = sourceText(file);
|
|
34
|
+
const opening = readLine(source, 0);
|
|
35
|
+
const fence = source.slice(0, opening.contentEnd).trim();
|
|
36
|
+
const format = fence === "---" ? "yaml" : fence === "+++" ? "toml" : void 0;
|
|
37
|
+
if (format !== void 0 && (options.format === void 0 || options.format === "auto" || options.format === format)) {
|
|
38
|
+
const valueStart = opening.end;
|
|
39
|
+
for (let start = valueStart; start < source.length;) {
|
|
40
|
+
const line = readLine(source, start);
|
|
41
|
+
if (source.slice(start, line.contentEnd).trim() === fence) {
|
|
42
|
+
let valueEnd = start;
|
|
43
|
+
if (valueEnd > valueStart && source.char(valueEnd - 1) === "\n") valueEnd--;
|
|
44
|
+
if (valueEnd > valueStart && source.char(valueEnd - 1) === "\r") valueEnd--;
|
|
45
|
+
const diagnostics = new DiagnosticBag();
|
|
46
|
+
const frontmatter = decodeFrontmatter({
|
|
47
|
+
diagnostics,
|
|
48
|
+
format,
|
|
49
|
+
source: source.slice(valueStart, valueEnd),
|
|
50
|
+
span: {
|
|
51
|
+
file,
|
|
52
|
+
start: valueStart,
|
|
53
|
+
end: valueEnd
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (frontmatter === void 0) {
|
|
57
|
+
const [first, ...rest] = diagnostics.snapshot().filter((diagnostic) => diagnostic.severity === "error");
|
|
58
|
+
if (first === void 0) throw new Error("Invalid frontmatter did not produce an error diagnostic");
|
|
59
|
+
throw ParseError.invalidSyntax(file, [first, ...rest]);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
result: Object.freeze({
|
|
63
|
+
file,
|
|
64
|
+
frontmatter,
|
|
65
|
+
format,
|
|
66
|
+
diagnostics: diagnostics.snapshot()
|
|
67
|
+
}),
|
|
68
|
+
origin: {
|
|
69
|
+
start: source.char(0) === "" ? 1 : 0,
|
|
70
|
+
end: line.end
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
start = line.end;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
result: Object.freeze({
|
|
79
|
+
file,
|
|
80
|
+
frontmatter: Object.freeze({}),
|
|
81
|
+
format: void 0,
|
|
82
|
+
diagnostics: Object.freeze([])
|
|
83
|
+
}),
|
|
84
|
+
origin: void 0
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Reads one physical line without indexing or normalizing the rest of the document. */
|
|
88
|
+
function readLine(source, start) {
|
|
89
|
+
let end = start;
|
|
90
|
+
while (end < source.length) {
|
|
91
|
+
const character = source.char(end);
|
|
92
|
+
if (character === "\n" || character === "\r") {
|
|
93
|
+
const endingLength = character === "\r" && source.char(end + 1) === "\n" ? 2 : 1;
|
|
94
|
+
return {
|
|
95
|
+
contentEnd: end,
|
|
96
|
+
end: end + endingLength
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
end++;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
contentEnd: end,
|
|
103
|
+
end
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { parseFrontmatter, parseFrontmatterSync };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=frontmatter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.mjs","names":[],"sources":["../src/frontmatter.ts"],"sourcesContent":["import type { Schema, SchemaOutput } from \"@temelj/standard-schema\";\n\nimport { StandardSchemaAsyncValidationError } from \"@temelj/standard-schema\";\nimport { isPromise } from \"@temelj/value\";\n\nimport type { Diagnostic } from \"./diagnostics.ts\";\nimport type { FrontmatterObject } from \"./model.ts\";\nimport type { ParserLimits } from \"./parser/config.ts\";\nimport type { SourceRange } from \"./ranges.ts\";\nimport type { SourceText } from \"./source-text.ts\";\nimport type { FrontmatterFormat, FrontmatterMode } from \"./syntax-options.ts\";\n\nimport { DiagnosticBag } from \"./diagnostics.ts\";\nimport { LimitError, ParseError } from \"./errors.ts\";\nimport { decodeFrontmatter } from \"./frontmatter-decode.ts\";\nimport { frontmatterSchemaValue } from \"./frontmatter-schema.ts\";\nimport { resolveParserLimits } from \"./parser/config.ts\";\nimport { SourceFile, sourceText } from \"./source.ts\";\n\nexport interface FrontmatterParseOptions {\n /** Formats to recognize. Defaults to both YAML and TOML. */\n readonly format?: FrontmatterMode;\n /** Limits the entire input length in UTF-16 code units, without scanning its body. */\n readonly limits?: Pick<ParserLimits, \"maximumSourceLength\">;\n}\n\nexport interface FrontmatterParseSchemaOptions<\n TSchema extends Schema,\n> extends FrontmatterParseOptions {\n readonly frontmatterSchema: TSchema;\n}\n\nexport interface FrontmatterParseResult<T = FrontmatterObject> {\n readonly file: SourceFile;\n readonly frontmatter: T;\n /** Undefined when no complete, enabled frontmatter block was found. */\n readonly format: FrontmatterFormat | undefined;\n readonly diagnostics: readonly Diagnostic[];\n}\n\n/**\n * Reads only the opening frontmatter block and optionally validates its metadata.\n * @throws {ParseError} Invalid YAML or TOML.\n * @throws {FrontmatterError} Schema validation fails.\n * @throws {LimitError | ConfigurationError} Invalid or exceeded source-length limit.\n */\nexport function parseFrontmatter<TSchema extends Schema>(\n input: string | SourceFile,\n options: FrontmatterParseSchemaOptions<TSchema>,\n): Promise<FrontmatterParseResult<SchemaOutput<TSchema>>>;\nexport function parseFrontmatter(\n input: string | SourceFile,\n options?: FrontmatterParseOptions,\n): Promise<FrontmatterParseResult>;\nexport async function parseFrontmatter(\n input: string | SourceFile,\n options: FrontmatterParseOptions & { readonly frontmatterSchema?: Schema } = {},\n): Promise<FrontmatterParseResult<unknown>> {\n const { result, origin } = readFrontmatter(input, options);\n\n if (options.frontmatterSchema === undefined) {\n return result;\n }\n\n const validated = await options.frontmatterSchema[\"~standard\"].validate(result.frontmatter);\n\n return Object.freeze({\n ...result,\n frontmatter: frontmatterSchemaValue(validated, result.file, origin),\n });\n}\n\n/**\n * Reads frontmatter synchronously, including synchronous schema validation.\n * @throws {StandardSchemaAsyncValidationError} The schema returns a promise.\n * @throws {ParseError | FrontmatterError | LimitError | ConfigurationError} Parsing fails.\n */\nexport function parseFrontmatterSync<TSchema extends Schema>(\n input: string | SourceFile,\n options: FrontmatterParseSchemaOptions<TSchema>,\n): FrontmatterParseResult<SchemaOutput<TSchema>>;\nexport function parseFrontmatterSync(\n input: string | SourceFile,\n options?: FrontmatterParseOptions,\n): FrontmatterParseResult;\nexport function parseFrontmatterSync(\n input: string | SourceFile,\n options: FrontmatterParseOptions & { readonly frontmatterSchema?: Schema } = {},\n): FrontmatterParseResult<unknown> {\n const { result, origin } = readFrontmatter(input, options);\n\n if (options.frontmatterSchema === undefined) {\n return result;\n }\n\n const validated = options.frontmatterSchema[\"~standard\"].validate(result.frontmatter);\n\n if (isPromise(validated)) {\n StandardSchemaAsyncValidationError.unsupported();\n }\n\n return Object.freeze({\n ...result,\n frontmatter: frontmatterSchemaValue(validated, result.file, origin),\n });\n}\n\ninterface ReadFrontmatterResult {\n readonly result: FrontmatterParseResult;\n readonly origin: SourceRange | undefined;\n}\n\nfunction readFrontmatter(\n input: string | SourceFile,\n options: FrontmatterParseOptions,\n): ReadFrontmatterResult {\n const file = input instanceof SourceFile ? input : new SourceFile(input);\n const { maximumSourceLength } = resolveParserLimits(options.limits);\n\n if (file.length > maximumSourceLength) {\n throw LimitError.exceeded(\n file,\n \"maximumSourceLength\",\n maximumSourceLength,\n undefined,\n file.length,\n );\n }\n\n const source = sourceText(file);\n const opening = readLine(source, 0);\n const fence = source.slice(0, opening.contentEnd).trim();\n const format = fence === \"---\" ? \"yaml\" : fence === \"+++\" ? \"toml\" : undefined;\n\n if (\n format !== undefined &&\n (options.format === undefined || options.format === \"auto\" || options.format === format)\n ) {\n const valueStart = opening.end;\n\n for (let start = valueStart; start < source.length;) {\n const line = readLine(source, start);\n\n if (source.slice(start, line.contentEnd).trim() === fence) {\n let valueEnd = start;\n\n if (valueEnd > valueStart && source.char(valueEnd - 1) === \"\\n\") {\n valueEnd--;\n }\n\n if (valueEnd > valueStart && source.char(valueEnd - 1) === \"\\r\") {\n valueEnd--;\n }\n\n const diagnostics = new DiagnosticBag();\n\n const frontmatter = decodeFrontmatter({\n diagnostics,\n format,\n source: source.slice(valueStart, valueEnd),\n span: { file, start: valueStart, end: valueEnd },\n });\n\n if (frontmatter === undefined) {\n const [first, ...rest] = diagnostics\n .snapshot()\n .filter((diagnostic) => diagnostic.severity === \"error\");\n\n if (first === undefined) {\n throw new Error(\"Invalid frontmatter did not produce an error diagnostic\");\n }\n\n throw ParseError.invalidSyntax(file, [first, ...rest]);\n }\n\n return {\n result: Object.freeze({ file, frontmatter, format, diagnostics: diagnostics.snapshot() }),\n origin: { start: source.char(0) === \"\\uFEFF\" ? 1 : 0, end: line.end },\n };\n }\n\n start = line.end;\n }\n }\n\n return {\n result: Object.freeze({\n file,\n frontmatter: Object.freeze({}),\n format: undefined,\n diagnostics: Object.freeze([]),\n }),\n origin: undefined,\n };\n}\n\ninterface FrontmatterLine {\n readonly contentEnd: number;\n readonly end: number;\n}\n\n/** Reads one physical line without indexing or normalizing the rest of the document. */\nfunction readLine(source: SourceText, start: number): FrontmatterLine {\n let end = start;\n\n while (end < source.length) {\n const character = source.char(end);\n\n if (character === \"\\n\" || character === \"\\r\") {\n const endingLength = character === \"\\r\" && source.char(end + 1) === \"\\n\" ? 2 : 1;\n\n return { contentEnd: end, end: end + endingLength };\n }\n\n end++;\n }\n\n return { contentEnd: end, end };\n}\n"],"mappings":";;;;;;;;;AAsDA,eAAsB,iBACpB,OACA,UAA6E,CAAC,GACpC;CAC1C,MAAM,EAAE,QAAQ,WAAW,gBAAgB,OAAO,OAAO;CAEzD,IAAI,QAAQ,sBAAsB,KAAA,GAChC,OAAO;CAGT,MAAM,YAAY,MAAM,QAAQ,kBAAkB,YAAY,CAAC,SAAS,OAAO,WAAW;CAE1F,OAAO,OAAO,OAAO;EACnB,GAAG;EACH,aAAa,uBAAuB,WAAW,OAAO,MAAM,MAAM;CACpE,CAAC;AACH;AAeA,SAAgB,qBACd,OACA,UAA6E,CAAC,GAC7C;CACjC,MAAM,EAAE,QAAQ,WAAW,gBAAgB,OAAO,OAAO;CAEzD,IAAI,QAAQ,sBAAsB,KAAA,GAChC,OAAO;CAGT,MAAM,YAAY,QAAQ,kBAAkB,YAAY,CAAC,SAAS,OAAO,WAAW;CAEpF,IAAI,UAAU,SAAS,GACrB,mCAAmC,YAAY;CAGjD,OAAO,OAAO,OAAO;EACnB,GAAG;EACH,aAAa,uBAAuB,WAAW,OAAO,MAAM,MAAM;CACpE,CAAC;AACH;AAOA,SAAS,gBACP,OACA,SACuB;CACvB,MAAM,OAAO,iBAAiB,aAAa,QAAQ,IAAI,WAAW,KAAK;CACvE,MAAM,EAAE,wBAAwB,oBAAoB,QAAQ,MAAM;CAElE,IAAI,KAAK,SAAS,qBAChB,MAAM,WAAW,SACf,MACA,uBACA,qBACA,KAAA,GACA,KAAK,MACP;CAGF,MAAM,SAAS,WAAW,IAAI;CAC9B,MAAM,UAAU,SAAS,QAAQ,CAAC;CAClC,MAAM,QAAQ,OAAO,MAAM,GAAG,QAAQ,UAAU,CAAC,CAAC,KAAK;CACvD,MAAM,SAAS,UA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AC;EACD,QAAQ,KAAA;CACV;AACF;;AAQA,SAAS,SAAS,QAAoB,OAAgC;CACpE,IAAI,MAAM;CAEV,OAAO,MAAM,OAAO,QAAQ;EAC1B,MAAM,YAAY,OAAO,KAAK,GAAG;EAEjC,IAAI,cAAc,QAAQ,cAAc,MAAM;GAC5C,MAAM,eAAe,cAAc,QAAQ,OAAO,KAAK,MAAM,CAAC,MAAM,OAAO,IAAI;GAE/E,OAAO;IAAE,YAAY;IAAK,KAAK,MAAM;GAAa;EACpD;EAEA;CACF;CAEA,OAAO;EAAE,YAAY;EAAK;CAAI;AAChC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/heading.d.ts
|
|
2
|
+
export type HeadingDepth = 1 | 2 | 3 | 4 | 5 | 6;
|
|
3
|
+
export declare function isHeadingDepth(value: unknown): value is HeadingDepth;
|
|
4
|
+
export declare function headingDepthForTag(tagName: string): HeadingDepth | undefined;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=heading.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heading.d.mts","names":[],"sources":["../src/heading.ts"],"mappings":";YAAY;wBAEI,eAAe,iBAAiB,SAAS;wBAIzC,mBAAmB,kBAAkB"}
|
package/dist/heading.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/heading.ts
|
|
2
|
+
function isHeadingDepth(value) {
|
|
3
|
+
return value === 1 || value === 2 || value === 3 || value === 4 || value === 5 || value === 6;
|
|
4
|
+
}
|
|
5
|
+
function headingDepthForTag(tagName) {
|
|
6
|
+
switch (tagName) {
|
|
7
|
+
case "h1": return 1;
|
|
8
|
+
case "h2": return 2;
|
|
9
|
+
case "h3": return 3;
|
|
10
|
+
case "h4": return 4;
|
|
11
|
+
case "h5": return 5;
|
|
12
|
+
case "h6": return 6;
|
|
13
|
+
default: return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { headingDepthForTag, isHeadingDepth };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=heading.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heading.mjs","names":[],"sources":["../src/heading.ts"],"sourcesContent":["export type HeadingDepth = 1 | 2 | 3 | 4 | 5 | 6;\n\nexport function isHeadingDepth(value: unknown): value is HeadingDepth {\n return value === 1 || value === 2 || value === 3 || value === 4 || value === 5 || value === 6;\n}\n\nexport function headingDepthForTag(tagName: string): HeadingDepth | undefined {\n switch (tagName) {\n case \"h1\":\n return 1;\n case \"h2\":\n return 2;\n case \"h3\":\n return 3;\n case \"h4\":\n return 4;\n case \"h5\":\n return 5;\n case \"h6\":\n return 6;\n default:\n return undefined;\n }\n}\n"],"mappings":";AAEA,SAAgB,eAAe,OAAuC;CACpE,OAAO,UAAU,KAAK,UAAU,KAAK,UAAU,KAAK,UAAU,KAAK,UAAU,KAAK,UAAU;AAC9F;AAEA,SAAgB,mBAAmB,SAA2C;CAC5E,QAAQ,SAAR;EACE,KAAK,MACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,KAAK,MACH,OAAO;EACT,SACE;CACJ;AACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { HtmlAttributes, HtmlNode } from "./html.mjs";
|
|
2
|
+
//#region src/html-format.d.ts
|
|
3
|
+
export interface HtmlFormatOptions {
|
|
4
|
+
readonly closeSelfClosing?: boolean;
|
|
5
|
+
readonly collapseEmptyAttributes?: boolean;
|
|
6
|
+
readonly preferUnquotedAttributes?: boolean;
|
|
7
|
+
readonly quote?: '"' | "'";
|
|
8
|
+
readonly quoteSmart?: boolean;
|
|
9
|
+
/** Raw HTML is escaped unless it is explicitly trusted. */
|
|
10
|
+
readonly rawHtml?: "escape" | "trusted";
|
|
11
|
+
readonly tightSelfClosing?: boolean;
|
|
12
|
+
readonly voidElements?: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
/** Serializes an HTML tree. JSX renders as its escaped authored fallback. */
|
|
15
|
+
export declare function formatHtml(node: HtmlNode, options?: HtmlFormatOptions): string;
|
|
16
|
+
declare class HtmlFormatter {
|
|
17
|
+
private readonly options;
|
|
18
|
+
private readonly voids;
|
|
19
|
+
constructor(options: HtmlFormatOptions);
|
|
20
|
+
format(node: HtmlNode): string;
|
|
21
|
+
element(tagName: string, values: HtmlAttributes, content: string): string;
|
|
22
|
+
private children;
|
|
23
|
+
private attribute;
|
|
24
|
+
}
|
|
25
|
+
/** Internal formatter for immutable nodes owned by one stream. */
|
|
26
|
+
export declare class CachedHtmlFormatter extends HtmlFormatter {
|
|
27
|
+
#private;
|
|
28
|
+
format(node: HtmlNode): string;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=html-format.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-format.d.mts","names":[],"sources":["../src/html-format.ts"],"mappings":";;iBAQiB;WACN;WACA;WACA;WACA;WACA;;WAEA;WACA;WACA;;;wBAIK,WAAW,MAAM,UAAU,UAAS;cAmC9C;mBACa;mBACA;EAEjB,YAAmB,SAAS;EAQrB,OAAO,MAAM;EAiCb,QAAQ,iBAAiB,QAAQ,gBAAgB;UA8BhD;UAUA;;;qBA0CG,4BAA4B;;EAGvB,OAAO,MAAM"}
|