@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
package/dist/model.mjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { normalizeIdentifier } from "./identifier.mjs";
|
|
2
|
+
//#region src/model.ts
|
|
3
|
+
/** Whether a node can appear where phrasing (inline) content is expected. */
|
|
4
|
+
function isPhrasingContent(node) {
|
|
5
|
+
switch (node.kind) {
|
|
6
|
+
case "text":
|
|
7
|
+
case "emphasis":
|
|
8
|
+
case "strong":
|
|
9
|
+
case "delete":
|
|
10
|
+
case "inlineCode":
|
|
11
|
+
case "hardBreak":
|
|
12
|
+
case "link":
|
|
13
|
+
case "image":
|
|
14
|
+
case "linkReference":
|
|
15
|
+
case "imageReference":
|
|
16
|
+
case "rawHtmlInline":
|
|
17
|
+
case "footnoteReference":
|
|
18
|
+
case "textDirective":
|
|
19
|
+
case "inlineMath":
|
|
20
|
+
case "jsxTextElement":
|
|
21
|
+
case "inlineExpression": return true;
|
|
22
|
+
default: return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Whether a node can appear where flow (block) content is expected. */
|
|
26
|
+
function isFlowContent(node) {
|
|
27
|
+
switch (node.kind) {
|
|
28
|
+
case "paragraph":
|
|
29
|
+
case "heading":
|
|
30
|
+
case "codeBlock":
|
|
31
|
+
case "thematicBreak":
|
|
32
|
+
case "blockquote":
|
|
33
|
+
case "list":
|
|
34
|
+
case "definition":
|
|
35
|
+
case "rawHtmlBlock":
|
|
36
|
+
case "footnoteDefinition":
|
|
37
|
+
case "frontmatter":
|
|
38
|
+
case "leafDirective":
|
|
39
|
+
case "containerDirective":
|
|
40
|
+
case "displayMath":
|
|
41
|
+
case "table":
|
|
42
|
+
case "blockExpression":
|
|
43
|
+
case "esm":
|
|
44
|
+
case "jsxFlowElement": return true;
|
|
45
|
+
default: return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Child nodes in document order, including a directive label before its body. */
|
|
49
|
+
function mdxChildren(node) {
|
|
50
|
+
switch (node.kind) {
|
|
51
|
+
case "textDirective":
|
|
52
|
+
case "leafDirective": return node.label === void 0 ? [] : [node.label];
|
|
53
|
+
case "containerDirective": return node.label === void 0 ? node.children : [node.label, ...node.children];
|
|
54
|
+
default: return "children" in node ? node.children : [];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Semantic text content: what a reader sees, without markup. */
|
|
58
|
+
function nodeText(node) {
|
|
59
|
+
switch (node.kind) {
|
|
60
|
+
case "text":
|
|
61
|
+
case "inlineCode":
|
|
62
|
+
case "inlineMath":
|
|
63
|
+
case "displayMath":
|
|
64
|
+
case "codeBlock":
|
|
65
|
+
case "rawHtmlInline":
|
|
66
|
+
case "rawHtmlBlock": return node.value;
|
|
67
|
+
case "image":
|
|
68
|
+
case "imageReference": return node.alt;
|
|
69
|
+
case "hardBreak": return "\n";
|
|
70
|
+
case "inlineExpression":
|
|
71
|
+
case "blockExpression":
|
|
72
|
+
case "esm":
|
|
73
|
+
case "definition":
|
|
74
|
+
case "frontmatter":
|
|
75
|
+
case "footnoteReference":
|
|
76
|
+
case "thematicBreak": return "";
|
|
77
|
+
case "document":
|
|
78
|
+
case "jsxFlowElement": return node.children.map(nodeText).join("\n\n");
|
|
79
|
+
case "list":
|
|
80
|
+
case "table": return node.children.map(nodeText).join("\n");
|
|
81
|
+
case "tableRow": return node.children.map(nodeText).join(" ");
|
|
82
|
+
default: return mdxChildren(node).map(nodeText).join("");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Indexes the first definition and footnote for each normalized identifier. */
|
|
86
|
+
function indexDocument(document) {
|
|
87
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
88
|
+
const footnotes = /* @__PURE__ */ new Map();
|
|
89
|
+
const pending = [...document.children].reverse();
|
|
90
|
+
for (let node = pending.pop(); node !== void 0; node = pending.pop()) {
|
|
91
|
+
if (node.kind === "definition") {
|
|
92
|
+
const identifier = normalizeIdentifier(node.identifier);
|
|
93
|
+
if (!definitions.has(identifier)) definitions.set(identifier, node);
|
|
94
|
+
} else if (node.kind === "footnoteDefinition") {
|
|
95
|
+
const identifier = normalizeIdentifier(node.identifier);
|
|
96
|
+
if (!footnotes.has(identifier)) footnotes.set(identifier, node);
|
|
97
|
+
}
|
|
98
|
+
const children = mdxChildren(node);
|
|
99
|
+
for (let index = children.length - 1; index >= 0; index--) pending.push(children[index]);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
definitions,
|
|
103
|
+
footnotes
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function documentFrontmatter(document) {
|
|
107
|
+
const first = document.children[0];
|
|
108
|
+
return first?.kind === "frontmatter" ? first : void 0;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { documentFrontmatter, indexDocument, isFlowContent, isPhrasingContent, mdxChildren, nodeText };
|
|
112
|
+
|
|
113
|
+
//# sourceMappingURL=model.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.mjs","names":[],"sources":["../src/model.ts"],"sourcesContent":["import type { HeadingDepth } from \"./heading.ts\";\nimport type { SourceRange } from \"./ranges.ts\";\nimport type { FrontmatterFormat, MathFormat } from \"./syntax-options.ts\";\n\nimport { normalizeIdentifier } from \"./identifier.ts\";\n\n/**\n * Semantic MDX nodes are plain, readonly data. `origin` is a UTF-16 range in the\n * `SourceFile` owned by the outcome that produced the tree.\n */\ninterface NodeBase<TKind extends string> {\n readonly kind: TKind;\n readonly origin?: SourceRange;\n}\n\ninterface ParentBase<TKind extends string, TChild> extends NodeBase<TKind> {\n readonly children: readonly TChild[];\n}\n\nexport interface TextNode extends NodeBase<\"text\"> {\n readonly value: string;\n}\n\nexport type EmphasisNode = ParentBase<\"emphasis\", PhrasingContent>;\n\nexport type StrongNode = ParentBase<\"strong\", PhrasingContent>;\n\nexport type DeleteNode = ParentBase<\"delete\", PhrasingContent>;\n\nexport interface InlineCodeNode extends NodeBase<\"inlineCode\"> {\n readonly value: string;\n}\n\nexport type HardBreakNode = NodeBase<\"hardBreak\">;\n\nexport interface LinkNode extends ParentBase<\"link\", PhrasingContent> {\n readonly url: string;\n readonly title?: string;\n}\n\nexport interface ImageNode extends NodeBase<\"image\"> {\n readonly url: string;\n readonly alt: string;\n readonly title?: string;\n}\n\nexport type ReferenceKind = \"full\" | \"collapsed\" | \"shortcut\";\n\nexport interface LinkReferenceNode extends ParentBase<\"linkReference\", PhrasingContent> {\n /** Normalized with `normalizeIdentifier`. */\n readonly identifier: string;\n readonly referenceKind: ReferenceKind;\n}\n\nexport interface ImageReferenceNode extends NodeBase<\"imageReference\"> {\n /** Normalized with `normalizeIdentifier`. */\n readonly identifier: string;\n readonly alt: string;\n readonly referenceKind: ReferenceKind;\n}\n\nexport interface RawHtmlInlineNode extends NodeBase<\"rawHtmlInline\"> {\n readonly value: string;\n}\n\nexport interface FootnoteReferenceNode extends NodeBase<\"footnoteReference\"> {\n /** Normalized with `normalizeIdentifier`. */\n readonly identifier: string;\n readonly label: string;\n}\n\nexport interface DirectiveAttribute {\n readonly name: string;\n readonly value: string;\n}\n\nexport type DirectiveLabelNode = ParentBase<\"directiveLabel\", PhrasingContent>;\n\ninterface DirectiveBase<TKind extends string> extends NodeBase<TKind> {\n readonly name: string;\n /** Attribute names are unique. */\n readonly attributes: readonly DirectiveAttribute[];\n readonly label?: DirectiveLabelNode;\n}\n\nexport type TextDirectiveNode = DirectiveBase<\"textDirective\">;\n\nexport type LeafDirectiveNode = DirectiveBase<\"leafDirective\">;\n\nexport interface ContainerDirectiveNode extends DirectiveBase<\"containerDirective\"> {\n readonly children: readonly FlowContent[];\n}\n\nexport interface InlineMathNode extends NodeBase<\"inlineMath\"> {\n readonly value: string;\n readonly format: MathFormat;\n}\n\nexport interface DisplayMathNode extends NodeBase<\"displayMath\"> {\n readonly value: string;\n readonly format: MathFormat;\n /** Only dollar math can carry metadata. */\n readonly meta?: string;\n}\n\nexport interface InlineExpressionNode extends NodeBase<\"inlineExpression\"> {\n readonly code: string;\n}\n\nexport interface BlockExpressionNode extends NodeBase<\"blockExpression\"> {\n readonly code: string;\n}\n\nexport interface EsmNode extends NodeBase<\"esm\"> {\n readonly code: string;\n}\n\nexport interface JsxAttributeValueExpression extends NodeBase<\"jsxAttributeValueExpression\"> {\n readonly code: string;\n}\n\nexport type JsxAttributeValue = string | JsxAttributeValueExpression;\n\nexport interface JsxAttribute extends NodeBase<\"jsxAttribute\"> {\n readonly name: string;\n /** An omitted value is the boolean shorthand `<A enabled />`. */\n readonly value?: JsxAttributeValue;\n}\n\nexport interface JsxSpreadAttribute extends NodeBase<\"jsxSpreadAttribute\"> {\n /** The spread argument, without the `...` operator. */\n readonly code: string;\n}\n\nexport type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute;\n\ninterface JsxElementBase<TKind extends string, TChild> extends ParentBase<TKind, TChild> {\n /** `undefined` for fragments. */\n readonly name?: string;\n readonly attributes: readonly JsxAttributeLike[];\n}\n\nexport type JsxTextElementNode = JsxElementBase<\"jsxTextElement\", PhrasingContent>;\n\nexport type JsxFlowElementNode = JsxElementBase<\"jsxFlowElement\", FlowContent>;\n\nexport type ParagraphNode = ParentBase<\"paragraph\", PhrasingContent>;\n\nexport interface HeadingNode extends ParentBase<\"heading\", PhrasingContent> {\n readonly depth: HeadingDepth;\n}\n\nexport interface CodeBlockNode extends NodeBase<\"codeBlock\"> {\n readonly value: string;\n readonly language?: string;\n readonly meta?: string;\n}\n\nexport type ThematicBreakNode = NodeBase<\"thematicBreak\">;\n\nexport type BlockQuoteNode = ParentBase<\"blockquote\", FlowContent>;\n\nexport interface ListItemNode extends ParentBase<\"listItem\", FlowContent> {\n /** `undefined` for an ordinary item, a boolean for a task item. */\n readonly checked?: boolean;\n readonly spread: boolean;\n}\n\nexport interface ListNode extends ParentBase<\"list\", ListItemNode> {\n readonly ordered: boolean;\n readonly spread: boolean;\n readonly start: number;\n}\n\nexport interface DefinitionNode extends NodeBase<\"definition\"> {\n /** Normalized with `normalizeIdentifier`. */\n readonly identifier: string;\n readonly url: string;\n readonly title?: string;\n}\n\nexport interface FootnoteDefinitionNode extends ParentBase<\"footnoteDefinition\", FlowContent> {\n /** Normalized with `normalizeIdentifier`. */\n readonly identifier: string;\n readonly label: string;\n}\n\nexport interface RawHtmlBlockNode extends NodeBase<\"rawHtmlBlock\"> {\n readonly value: string;\n}\n\nexport type FrontmatterValue =\n | null\n | boolean\n | number\n | bigint\n | string\n | FrontmatterTemporal\n | readonly FrontmatterValue[]\n | FrontmatterObject;\n\nexport interface FrontmatterObject {\n readonly [key: string]: FrontmatterValue;\n}\n\nexport type FrontmatterTemporalType =\n | \"offset-date-time\"\n | \"local-date-time\"\n | \"local-date\"\n | \"local-time\";\n\n/** A TOML date or time as an ISO 8601 string. */\nexport interface FrontmatterTemporal {\n readonly kind: \"temporal\";\n readonly type: FrontmatterTemporalType;\n readonly value: string;\n}\n\nexport interface FrontmatterNode extends NodeBase<\"frontmatter\"> {\n readonly format: FrontmatterFormat;\n readonly value: string;\n /** Decoded data. Present when the parser decoded the authored value. */\n readonly data?: FrontmatterObject;\n /** The authored value range, excluding fences. */\n readonly valueOrigin?: SourceRange;\n}\n\nexport type TableAlignment = \"center\" | \"left\" | \"none\" | \"right\";\n\nexport type TableCellNode = ParentBase<\"tableCell\", PhrasingContent>;\n\nexport type TableRowNode = ParentBase<\"tableRow\", TableCellNode>;\n\nexport interface TableNode extends ParentBase<\"table\", TableRowNode> {\n readonly alignments: readonly TableAlignment[];\n}\n\nexport type DocumentNode = ParentBase<\"document\", FlowContent>;\n\nexport type PhrasingContent =\n | TextNode\n | EmphasisNode\n | StrongNode\n | DeleteNode\n | InlineCodeNode\n | HardBreakNode\n | LinkNode\n | ImageNode\n | LinkReferenceNode\n | ImageReferenceNode\n | RawHtmlInlineNode\n | FootnoteReferenceNode\n | TextDirectiveNode\n | InlineMathNode\n | JsxTextElementNode\n | InlineExpressionNode;\n\nexport type FlowContent =\n | ParagraphNode\n | HeadingNode\n | CodeBlockNode\n | ThematicBreakNode\n | BlockQuoteNode\n | ListNode\n | DefinitionNode\n | RawHtmlBlockNode\n | FootnoteDefinitionNode\n | FrontmatterNode\n | LeafDirectiveNode\n | ContainerDirectiveNode\n | DisplayMathNode\n | TableNode\n | BlockExpressionNode\n | EsmNode\n | JsxFlowElementNode;\n\nexport type MdxNode =\n | DocumentNode\n | FlowContent\n | ListItemNode\n | TableRowNode\n | TableCellNode\n | DirectiveLabelNode\n | PhrasingContent;\n\nexport type MdxKind = MdxNode[\"kind\"];\n\nexport type MdxNodeForKind<TKind extends MdxKind> = Extract<MdxNode, { readonly kind: TKind }>;\n\n/** Whether a node can appear where phrasing (inline) content is expected. */\nexport function isPhrasingContent(node: MdxNode): node is PhrasingContent {\n switch (node.kind) {\n case \"text\":\n case \"emphasis\":\n case \"strong\":\n case \"delete\":\n case \"inlineCode\":\n case \"hardBreak\":\n case \"link\":\n case \"image\":\n case \"linkReference\":\n case \"imageReference\":\n case \"rawHtmlInline\":\n case \"footnoteReference\":\n case \"textDirective\":\n case \"inlineMath\":\n case \"jsxTextElement\":\n case \"inlineExpression\":\n return true;\n default:\n return false;\n }\n}\n\n/** Whether a node can appear where flow (block) content is expected. */\nexport function isFlowContent(node: MdxNode): node is FlowContent {\n switch (node.kind) {\n case \"paragraph\":\n case \"heading\":\n case \"codeBlock\":\n case \"thematicBreak\":\n case \"blockquote\":\n case \"list\":\n case \"definition\":\n case \"rawHtmlBlock\":\n case \"footnoteDefinition\":\n case \"frontmatter\":\n case \"leafDirective\":\n case \"containerDirective\":\n case \"displayMath\":\n case \"table\":\n case \"blockExpression\":\n case \"esm\":\n case \"jsxFlowElement\":\n return true;\n default:\n return false;\n }\n}\n\n/** Child nodes in document order, including a directive label before its body. */\nexport function mdxChildren(node: MdxNode): readonly MdxNode[] {\n switch (node.kind) {\n case \"textDirective\":\n case \"leafDirective\":\n return node.label === undefined ? [] : [node.label];\n case \"containerDirective\":\n return node.label === undefined ? node.children : [node.label, ...node.children];\n default:\n return \"children\" in node ? node.children : [];\n }\n}\n\n/** Semantic text content: what a reader sees, without markup. */\nexport function nodeText(node: MdxNode): string {\n switch (node.kind) {\n case \"text\":\n case \"inlineCode\":\n case \"inlineMath\":\n case \"displayMath\":\n case \"codeBlock\":\n case \"rawHtmlInline\":\n case \"rawHtmlBlock\":\n return node.value;\n case \"image\":\n case \"imageReference\":\n return node.alt;\n case \"hardBreak\":\n return \"\\n\";\n case \"inlineExpression\":\n case \"blockExpression\":\n case \"esm\":\n case \"definition\":\n case \"frontmatter\":\n case \"footnoteReference\":\n case \"thematicBreak\":\n return \"\";\n case \"document\":\n case \"jsxFlowElement\":\n return node.children.map(nodeText).join(\"\\n\\n\");\n case \"list\":\n case \"table\":\n return node.children.map(nodeText).join(\"\\n\");\n case \"tableRow\":\n return node.children.map(nodeText).join(\"\\t\");\n default:\n return mdxChildren(node).map(nodeText).join(\"\");\n }\n}\n\nexport interface DocumentIndex {\n readonly definitions: ReadonlyMap<string, DefinitionNode>;\n readonly footnotes: ReadonlyMap<string, FootnoteDefinitionNode>;\n}\n\n/** Indexes the first definition and footnote for each normalized identifier. */\nexport function indexDocument(document: DocumentNode): DocumentIndex {\n const definitions = new Map<string, DefinitionNode>();\n const footnotes = new Map<string, FootnoteDefinitionNode>();\n const pending: MdxNode[] = [...document.children].reverse();\n\n for (let node = pending.pop(); node !== undefined; node = pending.pop()) {\n if (node.kind === \"definition\") {\n const identifier = normalizeIdentifier(node.identifier);\n\n if (!definitions.has(identifier)) {\n definitions.set(identifier, node);\n }\n } else if (node.kind === \"footnoteDefinition\") {\n const identifier = normalizeIdentifier(node.identifier);\n\n if (!footnotes.has(identifier)) {\n footnotes.set(identifier, node);\n }\n }\n\n const children = mdxChildren(node);\n\n for (let index = children.length - 1; index >= 0; index--) {\n pending.push(children[index]);\n }\n }\n\n return { definitions, footnotes };\n}\n\nexport function documentFrontmatter(document: DocumentNode): FrontmatterNode | undefined {\n const first = document.children[0];\n\n return first?.kind === \"frontmatter\" ? first : undefined;\n}\n"],"mappings":";;;AAkSA,SAAgB,kBAAkB,MAAwC;CACxE,QAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EAC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C9C,SACE,OAAO,YAAY,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,KAAK,EAAE;CAClD;AACF;;AAQA,SAAgB,cAAc,UAAuC;CACnE,MAAM,8BAAc,IAAI,IAA4B;CACpD,MAAM,4BAAY,IAAI,IAAoC;CAC1D,MAAM,UAAqB,CAAC,GAAG,SAAS,QAAQ,CAAC,CAAC,QAAQ;CAE1D,KAAK,IAAI,OAAO,QAAQ,IAAI,GAAG,SAAS,KAAA,GAAW,OAAO,QAAQ,IAAI,GAAG;EACvE,IAAI,KAAK,SAAS,cAAc;GAC9B,MAAM,aAAa,oBAAoB,KAAK,UAAU;GAEtD,IAAI,CAAC,YAAY,IAAI,UAAU,GAC7B,YAAY,IAAI,YAAY,IAAI;EAEpC,OAAO,IAAI,KAAK,SAAS,sBAAsB;GAC7C,MAAM,aAAa,oBAAoB,KAAK,UAAU;GAEtD,IAAI,CAAC,UAAU,IAAI,UAAU,GAC3B,UAAU,IAAI,YAAY,IAAI;EAElC;EAEA,MAAM,WAAW,YAAY,IAAI;EAEjC,KAAK,IAAI,QAAQ,SAAS,SAAS,GAAG,SAAS,GAAG,SAChD,QAAQ,KAAK,SAAS,MAAM;CAEhC;CAEA,OAAO;EAAE;EAAa;CAAU;AAClC;AAEA,SAAgB,oBAAoB,UAAqD;CACvF,MAAM,QAAQ,SAAS,SAAS;CAEhC,OAAO,OAAO,SAAS,gBAAgB,QAAQ,KAAA;AACjD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SourceText } from "../source-text.mjs";
|
|
2
|
+
import { PhysicalLine } from "../source.mjs";
|
|
3
|
+
import { ContainerFrame } from "./block-syntax.mjs";
|
|
4
|
+
//#region src/parser/block-container-recognizers.d.ts
|
|
5
|
+
export interface QuoteMarker {
|
|
6
|
+
readonly markerStart: number;
|
|
7
|
+
readonly markerEnd: number;
|
|
8
|
+
readonly contentStart: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function blockQuoteMarker(source: SourceText, end: number, start: number): QuoteMarker | undefined;
|
|
11
|
+
export interface FootnoteMarker {
|
|
12
|
+
readonly markerStart: number;
|
|
13
|
+
readonly markerEnd: number;
|
|
14
|
+
readonly contentStart: number;
|
|
15
|
+
readonly identifier: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function footnoteMarker(source: SourceText, end: number, start: number): FootnoteMarker | undefined;
|
|
18
|
+
export interface ListMarker {
|
|
19
|
+
readonly markerStart: number;
|
|
20
|
+
readonly markerEnd: number;
|
|
21
|
+
readonly markerCharacter: "." | ")" | "*" | "+" | "-";
|
|
22
|
+
readonly ordered: boolean;
|
|
23
|
+
readonly start: number | undefined;
|
|
24
|
+
readonly contentIndent: number;
|
|
25
|
+
readonly contentStart: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function listMarker(source: SourceText, end: number, start: number, interruptingParagraph?: boolean): ListMarker | undefined;
|
|
28
|
+
export declare function isSiblingListItem(source: SourceText, line: PhysicalLine, frame: Extract<ContainerFrame, {
|
|
29
|
+
kind: "listItem";
|
|
30
|
+
}>): boolean;
|
|
31
|
+
export interface TaskMarker {
|
|
32
|
+
readonly checked: boolean;
|
|
33
|
+
readonly contentStart: number;
|
|
34
|
+
readonly frame: Extract<ContainerFrame, {
|
|
35
|
+
kind: "listItem";
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export declare function taskListMarker(source: SourceText, line: PhysicalLine, containers: readonly ContainerFrame[], continuingParagraph: boolean): TaskMarker | undefined;
|
|
39
|
+
//#endregion
|
|
40
|
+
//# sourceMappingURL=block-container-recognizers.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-container-recognizers.d.mts","names":[],"sources":["../../src/parser/block-container-recognizers.ts"],"mappings":";;;;iBAOiB;WACN;WACA;WACA;;wBAGK,iBACd,QAAQ,YACR,aACA,gBACC;iBAac;WACN;WACA;WACA;WACA;;wBAGK,eACd,QAAQ,YACR,aACA,gBACC;iBA8Bc;WACN;WACA;WACA;WACA;WACA;WACA;WACA;;wBAGK,WACd,QAAQ,YACR,aACA,eACA,kCACC;wBAkEa,kBACd,QAAQ,YACR,MAAM,cACN,OAAO,QAAQ;EAAkB;;iBAWlB;WACN;WACA;WACA,OAAO,QAAQ;IAAkB;;;wBAG5B,eACd,QAAQ,YACR,MAAM,cACN,qBAAqB,kBACrB,+BACC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { normalizeIdentifier } from "../identifier.mjs";
|
|
2
|
+
import { consumeIndent, findUnescaped, isAsciiDigit, isBlank, isSpaceOrTab } from "./characters.mjs";
|
|
3
|
+
//#region src/parser/block-container-recognizers.ts
|
|
4
|
+
function blockQuoteMarker(source, end, start) {
|
|
5
|
+
const indent = consumeIndent(source, start, end, 3);
|
|
6
|
+
if (source.char(indent.offset) !== ">") return;
|
|
7
|
+
const markerEnd = indent.offset + 1;
|
|
8
|
+
return {
|
|
9
|
+
markerStart: start,
|
|
10
|
+
markerEnd,
|
|
11
|
+
contentStart: isSpaceOrTab(source.char(markerEnd)) ? markerEnd + 1 : markerEnd
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function footnoteMarker(source, end, start) {
|
|
15
|
+
const indent = consumeIndent(source, start, end, 3);
|
|
16
|
+
const markerStart = start;
|
|
17
|
+
const labelStart = indent.offset;
|
|
18
|
+
if (source.slice(labelStart, labelStart + 2) !== "[^") return;
|
|
19
|
+
const labelEnd = findUnescaped(source, "]", labelStart + 2, end);
|
|
20
|
+
if (labelEnd === void 0 || source.char(labelEnd + 1) !== ":" || labelEnd === labelStart + 2) return;
|
|
21
|
+
const markerEnd = labelEnd + 2;
|
|
22
|
+
let contentStart = markerEnd;
|
|
23
|
+
while (contentStart < end && isSpaceOrTab(source.char(contentStart))) contentStart++;
|
|
24
|
+
return {
|
|
25
|
+
markerStart,
|
|
26
|
+
markerEnd,
|
|
27
|
+
contentStart,
|
|
28
|
+
identifier: normalizeIdentifier(source.slice(labelStart + 2, labelEnd))
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function listMarker(source, end, start, interruptingParagraph = false) {
|
|
32
|
+
let offset = consumeIndent(source, start, end, 3).offset;
|
|
33
|
+
const first = source.char(offset);
|
|
34
|
+
let markerCharacter;
|
|
35
|
+
let ordered = false;
|
|
36
|
+
let listStart;
|
|
37
|
+
if (first === "*" || first === "+" || first === "-") {
|
|
38
|
+
markerCharacter = first;
|
|
39
|
+
offset++;
|
|
40
|
+
} else {
|
|
41
|
+
const numberStart = offset;
|
|
42
|
+
while (offset < end && offset - numberStart < 9 && isAsciiDigit(source.char(offset))) offset++;
|
|
43
|
+
const delimiter = source.char(offset);
|
|
44
|
+
if (offset === numberStart || delimiter !== "." && delimiter !== ")") return;
|
|
45
|
+
listStart = Number(source.slice(numberStart, offset));
|
|
46
|
+
if (interruptingParagraph && listStart !== 1) return;
|
|
47
|
+
markerCharacter = delimiter;
|
|
48
|
+
ordered = true;
|
|
49
|
+
offset++;
|
|
50
|
+
}
|
|
51
|
+
if (offset < end && !isSpaceOrTab(source.char(offset))) return;
|
|
52
|
+
const markerEnd = offset;
|
|
53
|
+
if (interruptingParagraph && isBlank(source.slice(markerEnd, end))) return;
|
|
54
|
+
const padding = consumeIndent(source, offset, end, 4);
|
|
55
|
+
const contentIndent = padding.columns === 0 || padding.columns > 4 ? markerEnd - start + 1 : markerEnd - start + padding.columns;
|
|
56
|
+
const contentStart = padding.columns === 0 ? markerEnd : padding.offset;
|
|
57
|
+
return {
|
|
58
|
+
markerStart: start,
|
|
59
|
+
markerEnd,
|
|
60
|
+
markerCharacter,
|
|
61
|
+
ordered,
|
|
62
|
+
start: listStart,
|
|
63
|
+
contentIndent,
|
|
64
|
+
contentStart
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function isSiblingListItem(source, line, frame) {
|
|
68
|
+
const marker = listMarker(source, line.content.end, line.content.start);
|
|
69
|
+
return marker !== void 0 && marker.ordered === frame.ordered && marker.markerCharacter === frame.markerCharacter;
|
|
70
|
+
}
|
|
71
|
+
function taskListMarker(source, line, containers, continuingParagraph) {
|
|
72
|
+
const frame = containers.at(-1);
|
|
73
|
+
if (continuingParagraph || frame?.kind !== "listItem" || frame.checked !== void 0 || frame.children.length > 0) return;
|
|
74
|
+
const start = line.content.start;
|
|
75
|
+
const marker = source.slice(start, start + 3);
|
|
76
|
+
if (marker !== "[ ]" && marker.toLowerCase() !== "[x]") return;
|
|
77
|
+
const after = source.char(start + 3);
|
|
78
|
+
if (start + 3 < line.content.end && !isSpaceOrTab(after)) return;
|
|
79
|
+
let contentStart = start + 3;
|
|
80
|
+
while (contentStart < line.content.end && isSpaceOrTab(source.char(contentStart))) contentStart++;
|
|
81
|
+
return {
|
|
82
|
+
checked: marker !== "[ ]",
|
|
83
|
+
contentStart,
|
|
84
|
+
frame
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { blockQuoteMarker, footnoteMarker, isSiblingListItem, listMarker, taskListMarker };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=block-container-recognizers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-container-recognizers.mjs","names":[],"sources":["../../src/parser/block-container-recognizers.ts"],"sourcesContent":["import type { SourceText } from \"../source-text.ts\";\nimport type { PhysicalLine } from \"../source.ts\";\nimport type { ContainerFrame } from \"./block-syntax.ts\";\n\nimport { normalizeIdentifier } from \"../identifier.ts\";\nimport { consumeIndent, findUnescaped, isAsciiDigit, isBlank, isSpaceOrTab } from \"./characters.ts\";\n\nexport interface QuoteMarker {\n readonly markerStart: number;\n readonly markerEnd: number;\n readonly contentStart: number;\n}\n\nexport function blockQuoteMarker(\n source: SourceText,\n end: number,\n start: number,\n): QuoteMarker | undefined {\n const indent = consumeIndent(source, start, end, 3);\n\n if (source.char(indent.offset) !== \">\") {\n return;\n }\n\n const markerEnd = indent.offset + 1;\n const contentStart = isSpaceOrTab(source.char(markerEnd)) ? markerEnd + 1 : markerEnd;\n\n return { markerStart: start, markerEnd, contentStart };\n}\n\nexport interface FootnoteMarker {\n readonly markerStart: number;\n readonly markerEnd: number;\n readonly contentStart: number;\n readonly identifier: string;\n}\n\nexport function footnoteMarker(\n source: SourceText,\n end: number,\n start: number,\n): FootnoteMarker | undefined {\n const indent = consumeIndent(source, start, end, 3);\n const markerStart = start;\n const labelStart = indent.offset;\n\n if (source.slice(labelStart, labelStart + 2) !== \"[^\") {\n return;\n }\n\n const labelEnd = findUnescaped(source, \"]\", labelStart + 2, end);\n\n if (labelEnd === undefined || source.char(labelEnd + 1) !== \":\" || labelEnd === labelStart + 2) {\n return;\n }\n\n const markerEnd = labelEnd + 2;\n let contentStart = markerEnd;\n\n while (contentStart < end && isSpaceOrTab(source.char(contentStart))) {\n contentStart++;\n }\n\n return {\n markerStart,\n markerEnd,\n contentStart,\n identifier: normalizeIdentifier(source.slice(labelStart + 2, labelEnd)),\n };\n}\n\nexport interface ListMarker {\n readonly markerStart: number;\n readonly markerEnd: number;\n readonly markerCharacter: \".\" | \")\" | \"*\" | \"+\" | \"-\";\n readonly ordered: boolean;\n readonly start: number | undefined;\n readonly contentIndent: number;\n readonly contentStart: number;\n}\n\nexport function listMarker(\n source: SourceText,\n end: number,\n start: number,\n interruptingParagraph = false,\n): ListMarker | undefined {\n const indent = consumeIndent(source, start, end, 3);\n let offset = indent.offset;\n const first = source.char(offset);\n let markerCharacter: ListMarker[\"markerCharacter\"];\n let ordered = false;\n let listStart: number | undefined;\n\n if (first === \"*\" || first === \"+\" || first === \"-\") {\n markerCharacter = first;\n offset++;\n } else {\n const numberStart = offset;\n\n while (offset < end && offset - numberStart < 9 && isAsciiDigit(source.char(offset))) {\n offset++;\n }\n\n const delimiter = source.char(offset);\n\n if (offset === numberStart || (delimiter !== \".\" && delimiter !== \")\")) {\n return;\n }\n\n listStart = Number(source.slice(numberStart, offset));\n\n if (interruptingParagraph && listStart !== 1) {\n return;\n }\n\n markerCharacter = delimiter;\n ordered = true;\n offset++;\n }\n\n if (offset < end && !isSpaceOrTab(source.char(offset))) {\n return;\n }\n\n const markerEnd = offset;\n\n // An empty list item cannot interrupt a paragraph.\n if (interruptingParagraph && isBlank(source.slice(markerEnd, end))) {\n return;\n }\n\n const padding = consumeIndent(source, offset, end, 4);\n\n const contentIndent =\n padding.columns === 0 || padding.columns > 4\n ? markerEnd - start + 1\n : markerEnd - start + padding.columns;\n\n const contentStart = padding.columns === 0 ? markerEnd : padding.offset;\n\n return {\n markerStart: start,\n markerEnd,\n markerCharacter,\n ordered,\n start: listStart,\n contentIndent,\n contentStart,\n };\n}\n\nexport function isSiblingListItem(\n source: SourceText,\n line: PhysicalLine,\n frame: Extract<ContainerFrame, { kind: \"listItem\" }>,\n): boolean {\n const marker = listMarker(source, line.content.end, line.content.start);\n\n return (\n marker !== undefined &&\n marker.ordered === frame.ordered &&\n marker.markerCharacter === frame.markerCharacter\n );\n}\n\nexport interface TaskMarker {\n readonly checked: boolean;\n readonly contentStart: number;\n readonly frame: Extract<ContainerFrame, { kind: \"listItem\" }>;\n}\n\nexport function taskListMarker(\n source: SourceText,\n line: PhysicalLine,\n containers: readonly ContainerFrame[],\n continuingParagraph: boolean,\n): TaskMarker | undefined {\n const frame = containers.at(-1);\n\n if (\n continuingParagraph ||\n frame?.kind !== \"listItem\" ||\n frame.checked !== undefined ||\n frame.children.length > 0\n ) {\n return;\n }\n\n const start = line.content.start;\n const marker = source.slice(start, start + 3);\n\n if (marker !== \"[ ]\" && marker.toLowerCase() !== \"[x]\") {\n return;\n }\n\n const after = source.char(start + 3);\n\n if (start + 3 < line.content.end && !isSpaceOrTab(after)) {\n return;\n }\n\n let contentStart = start + 3;\n\n while (contentStart < line.content.end && isSpaceOrTab(source.char(contentStart))) {\n contentStart++;\n }\n\n return { checked: marker !== \"[ ]\", contentStart, frame };\n}\n"],"mappings":";;;AAaA,SAAgB,iBACd,QACA,KACA,OACyB;CACzB,MAAM,SAAS,cAAc,QAAQ,OAAO,KAAK,CAAC;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@
|
|
|
1
|
+
import { ResolvedSyntaxOptions } from "../syntax-options.mjs";
|
|
2
|
+
import { SourceText } from "../source-text.mjs";
|
|
3
|
+
import { PhysicalLine } from "../source.mjs";
|
|
4
|
+
import { InlineSegment } from "./inline-input.mjs";
|
|
5
|
+
import { BlockSyntax, DirectiveAttributeSyntax } from "./block-syntax.mjs";
|
|
6
|
+
import { RecognizerResult } from "./recognizer.mjs";
|
|
7
|
+
//#region src/parser/block-directive-recognizers.d.ts
|
|
8
|
+
export interface DirectiveContainerMarker {
|
|
9
|
+
readonly attributes: readonly DirectiveAttributeSyntax[];
|
|
10
|
+
readonly fenceLength: number;
|
|
11
|
+
readonly label: readonly InlineSegment[] | undefined;
|
|
12
|
+
readonly markerEnd: number;
|
|
13
|
+
readonly markerStart: number;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function directiveContainerMarker(source: SourceText, end: number, start: number): DirectiveContainerMarker | undefined;
|
|
17
|
+
export declare function recognizeLeafDirective(source: SourceText, line: PhysicalLine, syntax: ResolvedSyntaxOptions): RecognizerResult<Extract<BlockSyntax, {
|
|
18
|
+
kind: "leafDirective";
|
|
19
|
+
}>>;
|
|
20
|
+
export declare function isClosingDirectiveFence(source: SourceText, line: PhysicalLine, start: number, minimumFenceLength: number): boolean;
|
|
21
|
+
//#endregion
|
|
22
|
+
//# sourceMappingURL=block-directive-recognizers.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-directive-recognizers.d.mts","names":[],"sources":["../../src/parser/block-directive-recognizers.ts"],"mappings":";;;;;;;iBAYiB;WACN,qBAAqB;WACrB;WACA,gBAAgB;WAChB;WACA;WACA;;wBAGK,yBACd,QAAQ,YACR,aACA,gBACC;wBA4Ga,uBACd,QAAQ,YACR,MAAM,cACN,QAAQ,wBACP,iBAAiB,QAAQ;EAAe;;wBAM3B,wBACd,QAAQ,YACR,MAAM,cACN,eACA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { sourceRange } from "../ranges.mjs";
|
|
2
|
+
import { consumeIndent, findUnescaped, isBlank, isSpaceOrTab } from "./characters.mjs";
|
|
3
|
+
import { parseDirectiveAttributes } from "./directive-attributes.mjs";
|
|
4
|
+
import { matched, noMatch } from "./recognizer.mjs";
|
|
5
|
+
//#region src/parser/block-directive-recognizers.ts
|
|
6
|
+
function directiveContainerMarker(source, end, start) {
|
|
7
|
+
const markerStart = consumeIndent(source, start, end, 3).offset;
|
|
8
|
+
let markerEnd = markerStart;
|
|
9
|
+
while (source.char(markerEnd) === ":") markerEnd++;
|
|
10
|
+
if (markerEnd - markerStart < 3) return;
|
|
11
|
+
const name = /^[A-Za-z][\w-]*/u.exec(source.slice(markerEnd, end))?.[0];
|
|
12
|
+
if (name === void 0) return;
|
|
13
|
+
const tail = directiveTail(source, markerEnd + name.length, end);
|
|
14
|
+
if (tail === void 0) return;
|
|
15
|
+
return {
|
|
16
|
+
attributes: tail.attributes,
|
|
17
|
+
fenceLength: markerEnd - markerStart,
|
|
18
|
+
label: tail.label,
|
|
19
|
+
markerEnd,
|
|
20
|
+
markerStart,
|
|
21
|
+
name
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function directiveTail(source, start, end) {
|
|
25
|
+
let cursor = start;
|
|
26
|
+
let label;
|
|
27
|
+
if (source.char(cursor) === "[") {
|
|
28
|
+
const close = findUnescaped(source, "]", cursor + 1, end);
|
|
29
|
+
if (close === void 0) return;
|
|
30
|
+
label = [{
|
|
31
|
+
kind: "source",
|
|
32
|
+
range: sourceRange(cursor + 1, close)
|
|
33
|
+
}];
|
|
34
|
+
cursor = close + 1;
|
|
35
|
+
}
|
|
36
|
+
let attributes = [];
|
|
37
|
+
if (source.char(cursor) === "{") {
|
|
38
|
+
const close = findUnescaped(source, "}", cursor + 1, end);
|
|
39
|
+
if (close === void 0) return;
|
|
40
|
+
attributes = parseDirectiveAttributes(source.slice(cursor + 1, close));
|
|
41
|
+
cursor = close + 1;
|
|
42
|
+
}
|
|
43
|
+
while (cursor < end && isSpaceOrTab(source.char(cursor))) cursor++;
|
|
44
|
+
return cursor === end ? {
|
|
45
|
+
attributes,
|
|
46
|
+
label
|
|
47
|
+
} : void 0;
|
|
48
|
+
}
|
|
49
|
+
function matchLeafDirective(source, line, syntax) {
|
|
50
|
+
if (!syntax.directives) return;
|
|
51
|
+
const start = consumeIndent(source, line.content.start, line.content.end, 3).offset;
|
|
52
|
+
if (!source.startsWith("::", start) || source.char(start + 2) === ":") return;
|
|
53
|
+
const name = /^[A-Za-z][\w-]*/u.exec(source.slice(start + 2, line.content.end))?.[0];
|
|
54
|
+
if (name === void 0) return;
|
|
55
|
+
const tail = directiveTail(source, start + 2 + name.length, line.content.end);
|
|
56
|
+
return tail === void 0 ? void 0 : {
|
|
57
|
+
kind: "leafDirective",
|
|
58
|
+
range: sourceRange(line.range.start, line.content.end),
|
|
59
|
+
name,
|
|
60
|
+
label: tail.label,
|
|
61
|
+
attributes: tail.attributes
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function recognizeLeafDirective(source, line, syntax) {
|
|
65
|
+
const match = matchLeafDirective(source, line, syntax);
|
|
66
|
+
return match === void 0 ? noMatch : matched(match);
|
|
67
|
+
}
|
|
68
|
+
function isClosingDirectiveFence(source, line, start, minimumFenceLength) {
|
|
69
|
+
const markerStart = consumeIndent(source, start, line.content.end, 3).offset;
|
|
70
|
+
let markerEnd = markerStart;
|
|
71
|
+
while (source.char(markerEnd) === ":") markerEnd++;
|
|
72
|
+
return markerEnd - markerStart >= minimumFenceLength && isBlank(source.slice(markerEnd, line.content.end));
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { directiveContainerMarker, isClosingDirectiveFence, recognizeLeafDirective };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=block-directive-recognizers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-directive-recognizers.mjs","names":[],"sources":["../../src/parser/block-directive-recognizers.ts"],"sourcesContent":["import type { SourceText } from \"../source-text.ts\";\nimport type { PhysicalLine } from \"../source.ts\";\nimport type { ResolvedSyntaxOptions } from \"../syntax-options.ts\";\nimport type { BlockSyntax, DirectiveAttributeSyntax } from \"./block-syntax.ts\";\nimport type { InlineSegment } from \"./inline-input.ts\";\nimport type { RecognizerResult } from \"./recognizer.ts\";\n\nimport { sourceRange } from \"../ranges.ts\";\nimport { consumeIndent, findUnescaped, isBlank, isSpaceOrTab } from \"./characters.ts\";\nimport { parseDirectiveAttributes } from \"./directive-attributes.ts\";\nimport { matched, noMatch } from \"./recognizer.ts\";\n\nexport interface DirectiveContainerMarker {\n readonly attributes: readonly DirectiveAttributeSyntax[];\n readonly fenceLength: number;\n readonly label: readonly InlineSegment[] | undefined;\n readonly markerEnd: number;\n readonly markerStart: number;\n readonly name: string;\n}\n\nexport function directiveContainerMarker(\n source: SourceText,\n end: number,\n start: number,\n): DirectiveContainerMarker | undefined {\n const markerStart = consumeIndent(source, start, end, 3).offset;\n let markerEnd = markerStart;\n\n while (source.char(markerEnd) === \":\") {\n markerEnd++;\n }\n\n if (markerEnd - markerStart < 3) {\n return;\n }\n\n const name = /^[A-Za-z][\\w-]*/u.exec(source.slice(markerEnd, end))?.[0];\n\n if (name === undefined) {\n return;\n }\n\n const tail = directiveTail(source, markerEnd + name.length, end);\n\n if (tail === undefined) {\n return;\n }\n\n return {\n attributes: tail.attributes,\n fenceLength: markerEnd - markerStart,\n label: tail.label,\n markerEnd,\n markerStart,\n name,\n };\n}\n\ninterface DirectiveTail {\n readonly attributes: readonly DirectiveAttributeSyntax[];\n readonly label: readonly InlineSegment[] | undefined;\n}\n\nfunction directiveTail(source: SourceText, start: number, end: number): DirectiveTail | undefined {\n let cursor = start;\n let label: readonly InlineSegment[] | undefined;\n\n if (source.char(cursor) === \"[\") {\n const close = findUnescaped(source, \"]\", cursor + 1, end);\n\n if (close === undefined) {\n return;\n }\n\n label = [{ kind: \"source\", range: sourceRange(cursor + 1, close) }];\n cursor = close + 1;\n }\n\n let attributes: readonly DirectiveAttributeSyntax[] = [];\n\n if (source.char(cursor) === \"{\") {\n const close = findUnescaped(source, \"}\", cursor + 1, end);\n\n if (close === undefined) {\n return;\n }\n\n attributes = parseDirectiveAttributes(source.slice(cursor + 1, close));\n cursor = close + 1;\n }\n\n while (cursor < end && isSpaceOrTab(source.char(cursor))) {\n cursor++;\n }\n\n return cursor === end ? { attributes, label } : undefined;\n}\n\nfunction matchLeafDirective(\n source: SourceText,\n line: PhysicalLine,\n syntax: ResolvedSyntaxOptions,\n): Extract<BlockSyntax, { kind: \"leafDirective\" }> | undefined {\n if (!syntax.directives) {\n return;\n }\n\n const start = consumeIndent(source, line.content.start, line.content.end, 3).offset;\n\n if (!source.startsWith(\"::\", start) || source.char(start + 2) === \":\") {\n return;\n }\n\n const name = /^[A-Za-z][\\w-]*/u.exec(source.slice(start + 2, line.content.end))?.[0];\n\n if (name === undefined) {\n return;\n }\n\n const tail = directiveTail(source, start + 2 + name.length, line.content.end);\n\n return tail === undefined\n ? undefined\n : {\n kind: \"leafDirective\",\n range: sourceRange(line.range.start, line.content.end),\n name,\n label: tail.label,\n attributes: tail.attributes,\n };\n}\n\nexport function recognizeLeafDirective(\n source: SourceText,\n line: PhysicalLine,\n syntax: ResolvedSyntaxOptions,\n): RecognizerResult<Extract<BlockSyntax, { kind: \"leafDirective\" }>> {\n const match = matchLeafDirective(source, line, syntax);\n\n return match === undefined ? noMatch : matched(match);\n}\n\nexport function isClosingDirectiveFence(\n source: SourceText,\n line: PhysicalLine,\n start: number,\n minimumFenceLength: number,\n): boolean {\n const markerStart = consumeIndent(source, start, line.content.end, 3).offset;\n let markerEnd = markerStart;\n\n while (source.char(markerEnd) === \":\") {\n markerEnd++;\n }\n\n return (\n markerEnd - markerStart >= minimumFenceLength &&\n isBlank(source.slice(markerEnd, line.content.end))\n );\n}\n"],"mappings":";;;;;AAqBA,SAAgB,yBACd,QACA,KACA,OACsC;CACtC,M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AAC,CAAC;CAE7E,IAAI,CAAC,OAAO,WAAW,MAAM,KAAK,KAAK,OAAO,KAAK,QAAQ,CAAC,MAAM,KAChE;CAGF,MAAM,OAAO,mBAAmB,KAAK,OAAO,MAAM,QAAQ,GAAG,KAAK,QAAQ,GAAG,CAAC,CAAC,GAAG;CAElF,IAAI,SAAS,KAAA,GACX;CAGF,MAAM,OAAO,cAAc,QAAQ,QAAQ,IAAI,KAAK,QAAQ,KAAK,QAAQ,GAAG;CAE5E,OAAO,SAAS,KAAA,IACZ,KAAA,IACA;EACE,MAAM;EACN,OAAO,YAAY,KAAK,MAAM,OAAO,KAAK,QAAQ,GAAG;EACrD;EACA,OAAO,KAAK;EACZ,YAAY,KAAK;CACnB;AACN;AAEA,SAAgB,uBACd,QACA,MACA,QACmE;CACnE,MAAM,QAAQ,mBAAmB,QAAQ,MAAM,MAAM;CAErD,OAAO,UAAU,KAAA,IAAY,UAAU,QAAQ,KAAK;AACtD;AAEA,SAAgB,wBACd,QACA,MACA,OACA,oBACS;CACT,MAAM,cAAc,cAAc,QAAQ,OAAO,KAAK,QAAQ,KAAK,CAAC,CAAC,CAAC;CACtE,IAAI,YAAY;CAEhB,OAAO,OAAO,KAAK,SAAS,MAAM,KAChC;CAGF,OACE,YAAY,eAAe,sBAC3B,QAAQ,OAAO,MAAM,WAAW,KAAK,QAAQ,GAAG,CAAC;AAErD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SourceRange } from "../ranges.mjs";
|
|
2
|
+
import { ResolvedSyntaxOptions } from "../syntax-options.mjs";
|
|
3
|
+
import { SourceText } from "../source-text.mjs";
|
|
4
|
+
import { PhysicalLine } from "../source.mjs";
|
|
5
|
+
import { BlockSyntax, OpenLeaf, TableRowSyntax } from "./block-syntax.mjs";
|
|
6
|
+
import { RecognizerResult } from "./recognizer.mjs";
|
|
7
|
+
//#region src/parser/block-leaf-recognizers.d.ts
|
|
8
|
+
interface RecognizedCompleteBlock {
|
|
9
|
+
readonly kind: "block";
|
|
10
|
+
readonly block: BlockSyntax;
|
|
11
|
+
}
|
|
12
|
+
interface RecognizedOpenLeaf {
|
|
13
|
+
readonly kind: "openLeaf";
|
|
14
|
+
readonly leaf: Extract<OpenLeaf, {
|
|
15
|
+
kind: "fencedCode" | "html";
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
type RecognizedBlock = RecognizedCompleteBlock | RecognizedOpenLeaf;
|
|
19
|
+
type BlockRecognizer = (source: SourceText, line: PhysicalLine) => RecognizerResult<RecognizedBlock>;
|
|
20
|
+
export declare const recognizeRawHtml: BlockRecognizer;
|
|
21
|
+
export declare function recognizeFrontmatter(source: SourceText, line: PhysicalLine, syntax: ResolvedSyntaxOptions): RecognizerResult<Extract<OpenLeaf, {
|
|
22
|
+
kind: "frontmatter";
|
|
23
|
+
}>>;
|
|
24
|
+
export declare function recognizeMathFence(source: SourceText, line: PhysicalLine, syntax: ResolvedSyntaxOptions): RecognizerResult<Extract<OpenLeaf, {
|
|
25
|
+
kind: "math";
|
|
26
|
+
}>>;
|
|
27
|
+
export declare function recognizeSameLineMath(source: SourceText, line: PhysicalLine, syntax: ResolvedSyntaxOptions): RecognizerResult<Extract<BlockSyntax, {
|
|
28
|
+
kind: "math";
|
|
29
|
+
}>>;
|
|
30
|
+
export declare function trimLineEndingOffset(source: SourceText, end: number): number;
|
|
31
|
+
export declare function isClosingMathFence(source: SourceText, line: PhysicalLine, active: Extract<OpenLeaf, {
|
|
32
|
+
kind: "math";
|
|
33
|
+
}>): boolean;
|
|
34
|
+
export declare const recognizeDefinition: BlockRecognizer;
|
|
35
|
+
export declare const recognizeAtxHeading: BlockRecognizer;
|
|
36
|
+
export declare const recognizeThematicBreak: BlockRecognizer;
|
|
37
|
+
export declare const recognizeFence: BlockRecognizer;
|
|
38
|
+
export declare function recognizeTable(source: SourceText, line: PhysicalLine, paragraph: Extract<OpenLeaf, {
|
|
39
|
+
kind: "paragraph";
|
|
40
|
+
}>): RecognizerResult<Extract<OpenLeaf, {
|
|
41
|
+
kind: "table";
|
|
42
|
+
}>>;
|
|
43
|
+
export declare function tableRow(source: SourceText, range: SourceRange): TableRowSyntax;
|
|
44
|
+
export declare function recognizeSetext(source: SourceText, line: PhysicalLine, paragraph: Extract<OpenLeaf, {
|
|
45
|
+
kind: "paragraph";
|
|
46
|
+
}>): RecognizerResult<BlockSyntax>;
|
|
47
|
+
export declare function isClosingFence(source: SourceText, line: PhysicalLine, active: Extract<OpenLeaf, {
|
|
48
|
+
kind: "fencedCode";
|
|
49
|
+
}>): boolean;
|
|
50
|
+
export declare function interruptsParagraph(source: SourceText, line: PhysicalLine): boolean;
|
|
51
|
+
//#endregion
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=block-leaf-recognizers.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-leaf-recognizers.d.mts","names":[],"sources":["../../src/parser/block-leaf-recognizers.ts"],"mappings":";;;;;;;UAmBU;WACC;WACA,OAAO;;UAGR;WACC;WACA,MAAM,QAAQ;IAAY;;;KAGhC,kBAAkB,0BAA0B;KAE5C,mBACH,QAAQ,YACR,MAAM,iBACH,iBAAiB;qBAET,kBAAkB;wBAiEf,qBACd,QAAQ,YACR,MAAM,cACN,QAAQ,wBACP,iBAAiB,QAAQ;EAAY;;wBAoExB,mBACd,QAAQ,YACR,MAAM,cACN,QAAQ,wBACP,iBAAiB,QAAQ;EAAY;;wBAiFxB,sBACd,QAAQ,YACR,MAAM,cACN,QAAQ,wBACP,iBAAiB,QAAQ;EAAe;;wBAM3B,qBAAqB,QAAQ,YAAY;wBAQzC,mBACd,QAAQ,YACR,MAAM,cACN,QAAQ,QAAQ;EAAY;;qBA8BjB,qBAAqB;qBAkIrB,qBAAqB;qBA8DrB,wBAAwB;qBAgCxB,gBAAgB;wBA4Db,eACd,QAAQ,YACR,MAAM,cACN,WAAW,QAAQ;EAAY;KAC9B,iBAAiB,QAAQ;EAAY;;wBAqDxB,SAAS,QAAQ,YAAY,OAAO,cAAc;wBAqElD,gBACd,QAAQ,YACR,MAAM,cACN,WAAW,QAAQ;EAAY;KAC9B,iBAAiB;wBA+BJ,eACd,QAAQ,YACR,MAAM,cACN,QAAQ,QAAQ;EAAY;;wBA0Bd,oBAAoB,QAAQ,YAAY,MAAM"}
|