@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,199 @@
|
|
|
1
|
+
import { JavaScriptScanner } from "./javascript-scanner.mjs";
|
|
2
|
+
//#region src/parser/embedded-scanner.ts
|
|
3
|
+
/** Retained structural boundary state for one MDX JSX flow element or fragment. */
|
|
4
|
+
var JsxBoundaryScanner = class JsxBoundaryScanner {
|
|
5
|
+
#elements = [];
|
|
6
|
+
#closing = false;
|
|
7
|
+
#expression;
|
|
8
|
+
#name = "";
|
|
9
|
+
#readingName = false;
|
|
10
|
+
#rootOpened = false;
|
|
11
|
+
#state = "children";
|
|
12
|
+
#opening = new JsxOpeningScanner();
|
|
13
|
+
append(text) {
|
|
14
|
+
this.#opening.append(text);
|
|
15
|
+
for (let index = 0; index < text.length; index++) {
|
|
16
|
+
const character = text[index];
|
|
17
|
+
if (this.#expression !== void 0) {
|
|
18
|
+
const expression = this.#expression.append(text.slice(index));
|
|
19
|
+
if (expression.kind === "invalid") return {
|
|
20
|
+
kind: "invalid",
|
|
21
|
+
offset: index + expression.offset
|
|
22
|
+
};
|
|
23
|
+
if (expression.kind === "open") return expression;
|
|
24
|
+
index += expression.offset - 1;
|
|
25
|
+
this.#expression = void 0;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (this.#state === "singleQuotedAttribute" || this.#state === "doubleQuotedAttribute") {
|
|
29
|
+
if (this.#state === "singleQuotedAttribute" && character === "'" || this.#state === "doubleQuotedAttribute" && character === "\"") this.#state = "tag";
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (this.#state === "children") {
|
|
33
|
+
if (character === "{") this.#expression = new JavaScriptScanner("}");
|
|
34
|
+
else if (character === "<") {
|
|
35
|
+
this.#state = "tag";
|
|
36
|
+
this.#closing = text[index + 1] === "/";
|
|
37
|
+
this.#name = "";
|
|
38
|
+
this.#readingName = true;
|
|
39
|
+
if (this.#closing) index++;
|
|
40
|
+
}
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (character === "'" || character === "\"") this.#state = character === "'" ? "singleQuotedAttribute" : "doubleQuotedAttribute";
|
|
44
|
+
else if (character === "{") this.#expression = new JavaScriptScanner("}");
|
|
45
|
+
else if (character === ">") {
|
|
46
|
+
const selfClosing = text[index - 1] === "/";
|
|
47
|
+
if (this.#closing) {
|
|
48
|
+
const expected = this.#elements.pop();
|
|
49
|
+
if (expected === void 0 || expected !== this.#name) return {
|
|
50
|
+
kind: "invalid",
|
|
51
|
+
offset: index
|
|
52
|
+
};
|
|
53
|
+
} else if (!selfClosing) this.#elements.push(this.#name);
|
|
54
|
+
this.#rootOpened = true;
|
|
55
|
+
this.#state = "children";
|
|
56
|
+
if (this.#elements.length === 0) return {
|
|
57
|
+
kind: "closed",
|
|
58
|
+
offset: index + 1
|
|
59
|
+
};
|
|
60
|
+
} else if (this.#readingName && isJsxNameCharacter(character)) this.#name += character;
|
|
61
|
+
else if ((character === " " || character === " ") && this.#name !== "") this.#readingName = false;
|
|
62
|
+
else if (this.#name === "" && character !== " " && character !== " ") return {
|
|
63
|
+
kind: "invalid",
|
|
64
|
+
offset: index
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return { kind: "open" };
|
|
68
|
+
}
|
|
69
|
+
clone() {
|
|
70
|
+
const copy = new JsxBoundaryScanner();
|
|
71
|
+
copy.#elements.push(...this.#elements);
|
|
72
|
+
copy.#closing = this.#closing;
|
|
73
|
+
copy.#expression = this.#expression?.clone();
|
|
74
|
+
copy.#name = this.#name;
|
|
75
|
+
copy.#readingName = this.#readingName;
|
|
76
|
+
copy.#rootOpened = this.#rootOpened;
|
|
77
|
+
copy.#state = this.#state;
|
|
78
|
+
copy.#opening = this.#opening.clone();
|
|
79
|
+
return copy;
|
|
80
|
+
}
|
|
81
|
+
opening() {
|
|
82
|
+
return this.#opening.snapshot();
|
|
83
|
+
}
|
|
84
|
+
get validPrefix() {
|
|
85
|
+
return this.#rootOpened || this.#state === "tag";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
function isJsxNameCharacter(character) {
|
|
89
|
+
return /[\w:.-]/u.test(character);
|
|
90
|
+
}
|
|
91
|
+
/** Only publishes attributes after their lexical boundary is unambiguous. */
|
|
92
|
+
const reservedJsxProps = /* @__PURE__ */ new Set([
|
|
93
|
+
"children",
|
|
94
|
+
"key",
|
|
95
|
+
"node",
|
|
96
|
+
"ref"
|
|
97
|
+
]);
|
|
98
|
+
var JsxOpeningScanner = class JsxOpeningScanner {
|
|
99
|
+
#state = "start";
|
|
100
|
+
#name = "";
|
|
101
|
+
#committedName;
|
|
102
|
+
#attribute = "";
|
|
103
|
+
#value = "";
|
|
104
|
+
#attributes = /* @__PURE__ */ new Map();
|
|
105
|
+
#offset = 0;
|
|
106
|
+
#end;
|
|
107
|
+
append(text) {
|
|
108
|
+
for (const character of text) {
|
|
109
|
+
this.#offset += character.length;
|
|
110
|
+
this.character(character);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
character(character) {
|
|
114
|
+
if (this.#state === "unsafe") return;
|
|
115
|
+
if (this.#state === "closed") return;
|
|
116
|
+
if (this.#state === "single" || this.#state === "double") {
|
|
117
|
+
if (character === (this.#state === "single" ? "'" : "\"")) {
|
|
118
|
+
this.#attributes.set(this.#attribute, this.#value);
|
|
119
|
+
this.#state = "between";
|
|
120
|
+
} else this.#value += character;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (this.#state === "start") {
|
|
124
|
+
this.#state = character === "<" ? "name" : "unsafe";
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (this.#state === "name") {
|
|
128
|
+
if (/[$\w:.-]/u.test(character)) {
|
|
129
|
+
this.#name += character;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (this.#name.length === 0 || !/[\s/>]/u.test(character)) {
|
|
133
|
+
this.#state = "unsafe";
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.#committedName = this.#name;
|
|
137
|
+
this.#state = "between";
|
|
138
|
+
}
|
|
139
|
+
if (this.#state === "attribute") {
|
|
140
|
+
if (/[$\w:.-]/u.test(character)) {
|
|
141
|
+
this.#attribute += character;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (reservedJsxProps.has(this.#attribute)) {
|
|
145
|
+
this.#state = "unsafe";
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
this.#state = "afterAttribute";
|
|
149
|
+
}
|
|
150
|
+
if (this.#state === "afterAttribute") {
|
|
151
|
+
if (/\s/u.test(character)) return;
|
|
152
|
+
if (character === "=") {
|
|
153
|
+
this.#state = "value";
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
this.#attributes.set(this.#attribute, true);
|
|
157
|
+
this.#state = "between";
|
|
158
|
+
}
|
|
159
|
+
if (this.#state === "value") {
|
|
160
|
+
if (/\s/u.test(character)) return;
|
|
161
|
+
this.#value = "";
|
|
162
|
+
this.#state = character === "'" ? "single" : character === "\"" ? "double" : "unsafe";
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (character === ">") {
|
|
166
|
+
this.#end = this.#offset;
|
|
167
|
+
this.#state = "closed";
|
|
168
|
+
} else if (this.#state === "slash") this.#state = "unsafe";
|
|
169
|
+
else if (character === "/") this.#state = "slash";
|
|
170
|
+
else if (!/\s/u.test(character)) {
|
|
171
|
+
this.#attribute = character;
|
|
172
|
+
this.#state = /[$A-Za-z_]/u.test(character) ? "attribute" : "unsafe";
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
snapshot() {
|
|
176
|
+
return Object.freeze({
|
|
177
|
+
name: this.#committedName,
|
|
178
|
+
attributes: Object.freeze(Object.fromEntries(this.#attributes)),
|
|
179
|
+
safe: this.#state !== "unsafe" && !(this.#state === "attribute" && reservedJsxProps.has(this.#attribute)),
|
|
180
|
+
end: this.#end
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
clone() {
|
|
184
|
+
const copy = new JsxOpeningScanner();
|
|
185
|
+
copy.#state = this.#state;
|
|
186
|
+
copy.#name = this.#name;
|
|
187
|
+
copy.#committedName = this.#committedName;
|
|
188
|
+
copy.#attribute = this.#attribute;
|
|
189
|
+
copy.#value = this.#value;
|
|
190
|
+
copy.#attributes = new Map(this.#attributes);
|
|
191
|
+
copy.#offset = this.#offset;
|
|
192
|
+
copy.#end = this.#end;
|
|
193
|
+
return copy;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
//#endregion
|
|
197
|
+
export { JsxBoundaryScanner };
|
|
198
|
+
|
|
199
|
+
//# sourceMappingURL=embedded-scanner.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded-scanner.mjs","names":[],"sources":["../../src/parser/embedded-scanner.ts"],"sourcesContent":["import { JavaScriptScanner, type EmbeddedScannerResult } from \"./javascript-scanner.ts\";\n\ntype JsxState = \"children\" | \"tag\" | \"singleQuotedAttribute\" | \"doubleQuotedAttribute\";\n\n/** Retained structural boundary state for one MDX JSX flow element or fragment. */\nexport class JsxBoundaryScanner {\n readonly #elements: string[] = [];\n #closing = false;\n #expression: JavaScriptScanner | undefined;\n #name = \"\";\n #readingName = false;\n #rootOpened = false;\n #state: JsxState = \"children\";\n #opening = new JsxOpeningScanner();\n\n public append(text: string): EmbeddedScannerResult {\n this.#opening.append(text);\n\n for (let index = 0; index < text.length; index++) {\n const character = text[index];\n\n if (this.#expression !== undefined) {\n const expression = this.#expression.append(text.slice(index));\n\n if (expression.kind === \"invalid\") {\n return { kind: \"invalid\", offset: index + expression.offset };\n }\n\n if (expression.kind === \"open\") {\n return expression;\n }\n\n index += expression.offset - 1;\n this.#expression = undefined;\n continue;\n }\n\n if (this.#state === \"singleQuotedAttribute\" || this.#state === \"doubleQuotedAttribute\") {\n if (\n (this.#state === \"singleQuotedAttribute\" && character === \"'\") ||\n (this.#state === \"doubleQuotedAttribute\" && character === '\"')\n ) {\n this.#state = \"tag\";\n }\n\n continue;\n }\n\n if (this.#state === \"children\") {\n if (character === \"{\") {\n this.#expression = new JavaScriptScanner(\"}\");\n } else if (character === \"<\") {\n this.#state = \"tag\";\n this.#closing = text[index + 1] === \"/\";\n this.#name = \"\";\n this.#readingName = true;\n\n if (this.#closing) {\n index++;\n }\n }\n\n continue;\n }\n\n if (character === \"'\" || character === '\"') {\n this.#state = character === \"'\" ? \"singleQuotedAttribute\" : \"doubleQuotedAttribute\";\n } else if (character === \"{\") {\n this.#expression = new JavaScriptScanner(\"}\");\n } else if (character === \">\") {\n const selfClosing = text[index - 1] === \"/\";\n\n if (this.#closing) {\n const expected = this.#elements.pop();\n\n if (expected === undefined || expected !== this.#name) {\n return { kind: \"invalid\", offset: index };\n }\n } else if (!selfClosing) {\n this.#elements.push(this.#name);\n }\n\n this.#rootOpened = true;\n this.#state = \"children\";\n\n if (this.#elements.length === 0) {\n return { kind: \"closed\", offset: index + 1 };\n }\n } else if (this.#readingName && isJsxNameCharacter(character)) {\n this.#name += character;\n } else if ((character === \" \" || character === \"\\t\") && this.#name !== \"\") {\n this.#readingName = false;\n } else if (this.#name === \"\" && character !== \" \" && character !== \"\\t\") {\n return { kind: \"invalid\", offset: index };\n }\n }\n\n return { kind: \"open\" };\n }\n\n public clone(): JsxBoundaryScanner {\n const copy = new JsxBoundaryScanner();\n copy.#elements.push(...this.#elements);\n copy.#closing = this.#closing;\n copy.#expression = this.#expression?.clone();\n copy.#name = this.#name;\n copy.#readingName = this.#readingName;\n copy.#rootOpened = this.#rootOpened;\n copy.#state = this.#state;\n copy.#opening = this.#opening.clone();\n\n return copy;\n }\n\n public opening(): CommittedJsxOpening {\n return this.#opening.snapshot();\n }\n\n public get validPrefix(): boolean {\n return this.#rootOpened || this.#state === \"tag\";\n }\n}\n\nfunction isJsxNameCharacter(character: string): boolean {\n return /[\\w:.-]/u.test(character);\n}\n\nexport interface CommittedJsxOpening {\n readonly name: string | undefined;\n readonly attributes: Readonly<Record<string, boolean | string>>;\n readonly safe: boolean;\n readonly end: number | undefined;\n}\n\ntype OpeningState =\n | \"start\"\n | \"name\"\n | \"between\"\n | \"attribute\"\n | \"afterAttribute\"\n | \"value\"\n | \"single\"\n | \"double\"\n | \"slash\"\n | \"closed\"\n | \"unsafe\";\n\n/** Only publishes attributes after their lexical boundary is unambiguous. */\n// Props that renderers own; authored values would replace them.\nconst reservedJsxProps: ReadonlySet<string> = new Set([\"children\", \"key\", \"node\", \"ref\"]);\n\nclass JsxOpeningScanner {\n #state: OpeningState = \"start\";\n #name = \"\";\n #committedName: string | undefined;\n #attribute = \"\";\n #value = \"\";\n #attributes = new Map<string, boolean | string>();\n #offset = 0;\n #end: number | undefined;\n\n public append(text: string): void {\n for (const character of text) {\n this.#offset += character.length;\n this.character(character);\n }\n }\n\n private character(character: string): void {\n if (this.#state === \"unsafe\") {\n return;\n }\n\n // Children never execute while pending, so they cannot affect opening safety.\n if (this.#state === \"closed\") {\n return;\n }\n\n if (this.#state === \"single\" || this.#state === \"double\") {\n if (character === (this.#state === \"single\" ? \"'\" : '\"')) {\n this.#attributes.set(this.#attribute, this.#value);\n this.#state = \"between\";\n } else {\n this.#value += character;\n }\n\n return;\n }\n\n if (this.#state === \"start\") {\n this.#state = character === \"<\" ? \"name\" : \"unsafe\";\n\n return;\n }\n\n if (this.#state === \"name\") {\n if (/[$\\w:.-]/u.test(character)) {\n this.#name += character;\n\n return;\n }\n\n if (this.#name.length === 0 || !/[\\s/>]/u.test(character)) {\n this.#state = \"unsafe\";\n\n return;\n }\n\n this.#committedName = this.#name;\n this.#state = \"between\";\n }\n\n if (this.#state === \"attribute\") {\n if (/[$\\w:.-]/u.test(character)) {\n this.#attribute += character;\n\n return;\n }\n\n if (reservedJsxProps.has(this.#attribute)) {\n this.#state = \"unsafe\";\n\n return;\n }\n\n this.#state = \"afterAttribute\";\n }\n\n if (this.#state === \"afterAttribute\") {\n if (/\\s/u.test(character)) {\n return;\n }\n\n if (character === \"=\") {\n this.#state = \"value\";\n\n return;\n }\n\n this.#attributes.set(this.#attribute, true);\n this.#state = \"between\";\n }\n\n if (this.#state === \"value\") {\n if (/\\s/u.test(character)) {\n return;\n }\n\n this.#value = \"\";\n this.#state = character === \"'\" ? \"single\" : character === '\"' ? \"double\" : \"unsafe\";\n\n return;\n }\n\n if (character === \">\") {\n this.#end = this.#offset;\n this.#state = \"closed\";\n } else if (this.#state === \"slash\") {\n this.#state = \"unsafe\";\n } else if (character === \"/\") {\n this.#state = \"slash\";\n } else if (!/\\s/u.test(character)) {\n this.#attribute = character;\n this.#state = /[$A-Za-z_]/u.test(character) ? \"attribute\" : \"unsafe\";\n }\n }\n\n public snapshot(): CommittedJsxOpening {\n return Object.freeze({\n name: this.#committedName,\n attributes: Object.freeze(Object.fromEntries(this.#attributes)),\n safe:\n this.#state !== \"unsafe\" &&\n !(this.#state === \"attribute\" && reservedJsxProps.has(this.#attribute)),\n end: this.#end,\n });\n }\n\n public clone(): JsxOpeningScanner {\n const copy = new JsxOpeningScanner();\n copy.#state = this.#state;\n copy.#name = this.#name;\n copy.#committedName = this.#committedName;\n copy.#attribute = this.#attribute;\n copy.#value = this.#value;\n copy.#attributes = new Map(this.#attributes);\n copy.#offset = this.#offset;\n copy.#end = this.#end;\n\n return copy;\n }\n}\n"],"mappings":";;;AAKA,IAAa,qBAAb,MAAa,mBAAmB;CAC9B,YAA+B,CAAC;CAChC,WAAW;CACX;CACA,QAAQ;CACR,eAAe;CACf,cAAc;CACd,SAAmB;CACnB,WAAW,IAAI,kBAAkB;CAEjC,OAAc,MAAqC;EACjD,KAAK,SAAS,OAAO,IAAI;EAEzB,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS;GAChD,MAAM,YAAY,KAAK;GAEvB,IAAI,KAAK,gBAAgB,KAAA,GAAW;IAClC,MAAM,aAAa,KAAK,YAAY,OAAO,KAAK,MAAM,KAAK,CAAC;IAE5D,IAAI,WAAW,SAAS,WACtB,OAAO;KAAE,MAAM;KAAW,QAAQ,QAAQ,WAAW;IAAO;IAG9D,IAAI,WAAW,SAAS,QACtB,OAAO;IAGT,SAAS,WAAW,SAAS;IAC7B,KAAK,cAAc,KAAA;IACnB;GACF;GAEA,IAAI,KAAK,WAAW,2BAA2B,KAAK,WAAW,yBAAyB;IACtF,IACG,KAAK,WAAW,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AK;EACnB,KAAK,cAAc,IAAI,IAAI,KAAK,WAAW;EAC3C,KAAK,UAAU,KAAK;EACpB,KAAK,OAAO,KAAK;EAEjB,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SourceText } from "../source-text.mjs";
|
|
2
|
+
import { InlineInput } from "./inline-input.mjs";
|
|
3
|
+
import { InlineMatch } from "./inline-output.mjs";
|
|
4
|
+
//#region src/parser/inline-autolink.d.ts
|
|
5
|
+
export declare function matchLiteralAutolink(input: InlineInput, value: SourceText, start: number): InlineMatch | undefined;
|
|
6
|
+
//#endregion
|
|
7
|
+
//# sourceMappingURL=inline-autolink.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-autolink.d.mts","names":[],"sources":["../../src/parser/inline-autolink.ts"],"mappings":";;;;wBAQgB,qBACd,OAAO,aACP,OAAO,YACP,gBACC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { textNode } from "./inline-output.mjs";
|
|
2
|
+
//#region src/parser/inline-autolink.ts
|
|
3
|
+
function matchLiteralAutolink(input, value, start) {
|
|
4
|
+
const character = value.char(start);
|
|
5
|
+
if (character === void 0 || !(character >= "a" && character <= "z" || character >= "A" && character <= "Z" || character >= "0" && character <= "9" || character === "_" || character === "." || character === "+" || character === "-")) return;
|
|
6
|
+
const before = value.char(start - 1);
|
|
7
|
+
if (before !== void 0 && (before >= "a" && before <= "z" || before >= "A" && before <= "Z" || before >= "0" && before <= "9" || before === "_" || before > "" && /[\p{L}\p{N}_]/u.test(before))) return;
|
|
8
|
+
const rest = value.slice(start);
|
|
9
|
+
const url = /^(?:https?:\/\/|www\.)[^\s<>]+/iu.exec(rest)?.[0];
|
|
10
|
+
const email = /^[\w.+-]+@[A-Za-z\d-]+(?:\.[A-Za-z\d-]+)+/u.exec(rest)?.[0];
|
|
11
|
+
let label = url ?? email;
|
|
12
|
+
if (label === void 0) return;
|
|
13
|
+
if (url !== void 0) label = trimAutolinkPunctuation(label);
|
|
14
|
+
if (label === "") return;
|
|
15
|
+
const end = start + label.length;
|
|
16
|
+
const destination = email !== void 0 ? `mailto:${label}` : label.startsWith("www.") ? `http://${label}` : label;
|
|
17
|
+
return {
|
|
18
|
+
end,
|
|
19
|
+
node: {
|
|
20
|
+
kind: "link",
|
|
21
|
+
range: input.sourceRange(start, end),
|
|
22
|
+
destination,
|
|
23
|
+
title: void 0,
|
|
24
|
+
children: [textNode(input, value, start, end)]
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function trimAutolinkPunctuation(value) {
|
|
29
|
+
let end = value.length;
|
|
30
|
+
while (end > 0 && /[!"'*,.:;?]/u.test(value[end - 1])) end--;
|
|
31
|
+
while (end > 0 && value[end - 1] === ")" && countCharacter(value.slice(0, end), ")") > countCharacter(value.slice(0, end), "(")) end--;
|
|
32
|
+
return value.slice(0, end);
|
|
33
|
+
}
|
|
34
|
+
function countCharacter(value, character) {
|
|
35
|
+
let count = 0;
|
|
36
|
+
for (const candidate of value) if (candidate === character) count++;
|
|
37
|
+
return count;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { matchLiteralAutolink };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=inline-autolink.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-autolink.mjs","names":[],"sources":["../../src/parser/inline-autolink.ts"],"sourcesContent":["import type { SourceText } from \"../source-text.ts\";\nimport type { InlineInput } from \"./inline-input.ts\";\nimport type { InlineMatch } from \"./inline-output.ts\";\n\nimport { textNode } from \"./inline-output.ts\";\n\n// Literal autolinks: URLs, `www.` links, and email addresses.\n\nexport function matchLiteralAutolink(\n input: InlineInput,\n value: SourceText,\n start: number,\n): InlineMatch | undefined {\n const character = value.char(start);\n\n // Literal links start with an ASCII email character or an HTTP/www prefix.\n if (\n character === undefined ||\n !(\n (character >= \"a\" && character <= \"z\") ||\n (character >= \"A\" && character <= \"Z\") ||\n (character >= \"0\" && character <= \"9\") ||\n character === \"_\" ||\n character === \".\" ||\n character === \"+\" ||\n character === \"-\"\n )\n ) {\n return;\n }\n\n const before = value.char(start - 1);\n\n if (\n before !== undefined &&\n ((before >= \"a\" && before <= \"z\") ||\n (before >= \"A\" && before <= \"Z\") ||\n (before >= \"0\" && before <= \"9\") ||\n before === \"_\" ||\n (before > \"\\x7f\" && /[\\p{L}\\p{N}_]/u.test(before)))\n ) {\n return;\n }\n\n const rest = value.slice(start);\n const url = /^(?:https?:\\/\\/|www\\.)[^\\s<>]+/iu.exec(rest)?.[0];\n const email = /^[\\w.+-]+@[A-Za-z\\d-]+(?:\\.[A-Za-z\\d-]+)+/u.exec(rest)?.[0];\n let label = url ?? email;\n\n if (label === undefined) {\n return;\n }\n\n if (url !== undefined) {\n label = trimAutolinkPunctuation(label);\n }\n\n if (label === \"\") {\n return;\n }\n\n const end = start + label.length;\n\n const destination =\n email !== undefined ? `mailto:${label}` : label.startsWith(\"www.\") ? `http://${label}` : label;\n\n return {\n end,\n node: {\n kind: \"link\",\n range: input.sourceRange(start, end),\n destination,\n title: undefined,\n children: [textNode(input, value, start, end)],\n },\n };\n}\n\nfunction trimAutolinkPunctuation(value: string): string {\n let end = value.length;\n\n while (end > 0 && /[!\"'*,.:;?]/u.test(value[end - 1])) {\n end--;\n }\n\n while (\n end > 0 &&\n value[end - 1] === \")\" &&\n countCharacter(value.slice(0, end), \")\") > countCharacter(value.slice(0, end), \"(\")\n ) {\n end--;\n }\n\n return value.slice(0, end);\n}\n\nfunction countCharacter(value: string, character: string): number {\n let count = 0;\n\n for (const candidate of value) {\n if (candidate === character) {\n count++;\n }\n }\n\n return count;\n}\n"],"mappings":";;AAQA,SAAgB,qBACd,OACA,OACA,OACyB;CACzB,MAAM,YAAY,MAAM,KAAK,KAAK;CAGlC,IACE,cAAc,KAAA,KACd,EACG,aAAa,OAAO,aAAa,OACjC,aAAa,OAAO,aAAa,OACjC,aAAa,O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ACT"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SourceText } from "../source-text.mjs";
|
|
2
|
+
import { InlineInput } from "./inline-input.mjs";
|
|
3
|
+
import { InlineMatch } from "./inline-output.mjs";
|
|
4
|
+
//#region src/parser/inline-character-reference.d.ts
|
|
5
|
+
export declare function characterReference(input: InlineInput, value: SourceText, start: number): InlineMatch | undefined;
|
|
6
|
+
//#endregion
|
|
7
|
+
//# sourceMappingURL=inline-character-reference.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-character-reference.d.mts","names":[],"sources":["../../src/parser/inline-character-reference.ts"],"mappings":";;;;wBAWgB,mBACd,OAAO,aACP,OAAO,YACP,gBACC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { decodeNamedCharacterReference, decodeNumericCharacterReference } from "../character-reference.mjs";
|
|
2
|
+
//#region src/parser/inline-character-reference.ts
|
|
3
|
+
function characterReference(input, value, start) {
|
|
4
|
+
const match = /^&(#(?:\d{1,7}|[xX][\dA-Fa-f]{1,6})|[A-Za-z][\dA-Za-z]{1,30});/u.exec(value.slice(start));
|
|
5
|
+
if (match === null) return;
|
|
6
|
+
const body = match[1];
|
|
7
|
+
const decoded = body.startsWith("#") ? decodeNumericCharacterReference(body.slice(body[1] === "x" || body[1] === "X" ? 2 : 1), body[1] === "x" || body[1] === "X" ? 16 : 10) : decodeNamedCharacterReference(body);
|
|
8
|
+
if (decoded === void 0) return;
|
|
9
|
+
const end = start + match[0].length;
|
|
10
|
+
return {
|
|
11
|
+
end,
|
|
12
|
+
node: {
|
|
13
|
+
kind: "text",
|
|
14
|
+
range: input.sourceRange(start, end),
|
|
15
|
+
value: decoded
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { characterReference };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=inline-character-reference.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-character-reference.mjs","names":[],"sources":["../../src/parser/inline-character-reference.ts"],"sourcesContent":["import type { SourceText } from \"../source-text.ts\";\nimport type { InlineInput } from \"./inline-input.ts\";\nimport type { InlineMatch } from \"./inline-output.ts\";\n\nimport {\n decodeNamedCharacterReference,\n decodeNumericCharacterReference,\n} from \"../character-reference.ts\";\n\n// Character references.\n\nexport function characterReference(\n input: InlineInput,\n value: SourceText,\n start: number,\n): InlineMatch | undefined {\n const match = /^&(#(?:\\d{1,7}|[xX][\\dA-Fa-f]{1,6})|[A-Za-z][\\dA-Za-z]{1,30});/u.exec(\n value.slice(start),\n );\n\n if (match === null) {\n return;\n }\n\n const body = match[1];\n\n const decoded = body.startsWith(\"#\")\n ? decodeNumericCharacterReference(\n body.slice(body[1] === \"x\" || body[1] === \"X\" ? 2 : 1),\n body[1] === \"x\" || body[1] === \"X\" ? 16 : 10,\n )\n : decodeNamedCharacterReference(body);\n\n if (decoded === undefined) {\n return;\n }\n\n const end = start + match[0].length;\n\n return {\n end,\n node: { kind: \"text\", range: input.sourceRange(start, end), value: decoded },\n };\n}\n"],"mappings":";;AAWA,SAAgB,mBACd,OACA,OACA,OACyB;CACzB,MAAM,QAAQ,kEAAkE,KAC9E,MAAM,MAAM,KAAK,CACnB;CAEA,IAAI,UAAU,MACZ;CAGF,MAAM,OAAO,MAAM;CAEnB,MAAM,UAAU,KAAK,WAAW,GAAG,IAC/B,gCACE,KAAK,MAAM,KAAK,OAAO,OAAO,KAAK,OAAO,MAAM,IAAI,CAAC,GACrD,KAAK,OAAO,OAAO,KAAK,OAAO,MAAM,KAAK,EAC5C,IACA,8BAA8B,IAAI;CAEtC,IAAI,YAAY,KAAA,GACd;CAGF,MAAM,MAAM,QAAQ,MAAM,EAAE,CAAC;CAE7B,OAAO;EACL;EACA,MAAM;GAAE,MAAM;GAAQ,OAAO,MAAM,YAAY,OAAO,GAAG;GAAG,OAAO;EAAQ;CAC7E;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SourceText } from "../source-text.mjs";
|
|
2
|
+
import { InlineInput } from "./inline-input.mjs";
|
|
3
|
+
import { InlineMatch } from "./inline-output.mjs";
|
|
4
|
+
//#region src/parser/inline-code.d.ts
|
|
5
|
+
export declare function codeSpan(input: InlineInput, value: SourceText, start: number): InlineMatch | undefined;
|
|
6
|
+
//#endregion
|
|
7
|
+
//# sourceMappingURL=inline-code.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-code.d.mts","names":[],"sources":["../../src/parser/inline-code.ts"],"mappings":";;;;wBAQgB,SACd,OAAO,aACP,OAAO,YACP,gBACC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { markerRunEnd } from "./inline-output.mjs";
|
|
2
|
+
//#region src/parser/inline-code.ts
|
|
3
|
+
function codeSpan(input, value, start) {
|
|
4
|
+
const openerEnd = markerRunEnd(value, start, "`");
|
|
5
|
+
const size = openerEnd - start;
|
|
6
|
+
let search = openerEnd;
|
|
7
|
+
while (search < value.length) {
|
|
8
|
+
const candidate = value.indexOf("`", search);
|
|
9
|
+
if (candidate === -1) return;
|
|
10
|
+
const end = markerRunEnd(value, candidate, "`");
|
|
11
|
+
if (end - candidate === size) {
|
|
12
|
+
let code = value.slice(openerEnd, candidate).replace(/\r\n|[\r\n]/gu, " ");
|
|
13
|
+
if (/^ .* $/u.test(code) && /[^ ]/u.test(code)) code = code.slice(1, -1);
|
|
14
|
+
return {
|
|
15
|
+
end,
|
|
16
|
+
node: {
|
|
17
|
+
kind: "code",
|
|
18
|
+
range: input.sourceRange(start, end),
|
|
19
|
+
value: code
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
search = end;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { codeSpan };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=inline-code.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-code.mjs","names":[],"sources":["../../src/parser/inline-code.ts"],"sourcesContent":["import type { SourceText } from \"../source-text.ts\";\nimport type { InlineInput } from \"./inline-input.ts\";\nimport type { InlineMatch } from \"./inline-output.ts\";\n\nimport { markerRunEnd } from \"./inline-output.ts\";\n\n// Code spans.\n\nexport function codeSpan(\n input: InlineInput,\n value: SourceText,\n start: number,\n): InlineMatch | undefined {\n const openerEnd = markerRunEnd(value, start, \"`\");\n const size = openerEnd - start;\n let search = openerEnd;\n\n while (search < value.length) {\n const candidate = value.indexOf(\"`\", search);\n\n if (candidate === -1) {\n return;\n }\n\n const end = markerRunEnd(value, candidate, \"`\");\n\n if (end - candidate === size) {\n let code = value.slice(openerEnd, candidate).replace(/\\r\\n|[\\r\\n]/gu, \" \");\n\n if (/^ .* $/u.test(code) && /[^ ]/u.test(code)) {\n code = code.slice(1, -1);\n }\n\n return {\n end,\n node: { kind: \"code\", range: input.sourceRange(start, end), value: code },\n };\n }\n\n search = end;\n }\n\n return;\n}\n"],"mappings":";;AAQA,SAAgB,SACd,OACA,OACA,OACyB;CACzB,MAAM,YAAY,aAAa,OAAO,OAAO,GAAG;CAChD,MAAM,OAAO,YAAY;CACzB,IAAI,SAAS;CAEb,OAAO,SAAS,MAAM,QAAQ;EAC5B,MAAM,YAAY,MAAM,QAAQ,KAAK,MAAM;EAE3C,IAAI,cAAc,IAChB;EAGF,MAAM,MAAM,aAAa,OAAO,WAAW,GAAG;EAE9C,IAAI,MAAM,cAAc,MAAM;GAC5B,IAAI,OAAO,MAAM,MAAM,WAAW,SAAS,CAAC,CAAC,QAAQ,iBAAiB,GAAG;GAEzE,IAAI,UAAU,KAAK,IAAI,KAAK,QAAQ,KAAK,IAAI,GAC3C,OAAO,KAAK,MAAM,GAAG,EAAE;GAGzB,OAAO;IACL;IACA,MAAM;KAAE,MAAM;KAAQ,OAAO,MAAM,YAAY,OAAO,GAAG;KAAG,OAAO;IAAK;GAC1E;EACF;EAEA,SAAS;CACX;AAGF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SourceText } from "../source-text.mjs";
|
|
2
|
+
import { InlineInput } from "./inline-input.mjs";
|
|
3
|
+
import { InlineMatch } from "./inline-output.mjs";
|
|
4
|
+
//#region src/parser/inline-directive.d.ts
|
|
5
|
+
export declare function inlineDirective(input: InlineInput, value: SourceText, start: number): InlineMatch | undefined;
|
|
6
|
+
/** A directive whose label or attributes later input could still close. */
|
|
7
|
+
export declare function directiveUnfinished(value: SourceText, start: number): boolean;
|
|
8
|
+
//#endregion
|
|
9
|
+
//# sourceMappingURL=inline-directive.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-directive.d.mts","names":[],"sources":["../../src/parser/inline-directive.ts"],"mappings":";;;;wBAUgB,gBACd,OAAO,aACP,OAAO,YACP,gBACC;;wBAuDa,oBAAoB,OAAO,YAAY"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { parseDirectiveAttributes } from "./directive-attributes.mjs";
|
|
2
|
+
import { findUnescapedInline, textNode } from "./inline-output.mjs";
|
|
3
|
+
//#region src/parser/inline-directive.ts
|
|
4
|
+
function inlineDirective(input, value, start) {
|
|
5
|
+
if (value.char(start + 1) === ":") return;
|
|
6
|
+
const name = /^[A-Za-z][\w-]*/u.exec(value.slice(start + 1))?.[0];
|
|
7
|
+
if (name === void 0) return;
|
|
8
|
+
let cursor = start + 1 + name.length;
|
|
9
|
+
let label = [];
|
|
10
|
+
if (value.char(cursor) === "[") {
|
|
11
|
+
const close = findUnescapedInline(value, "]", cursor + 1);
|
|
12
|
+
if (close === void 0) return;
|
|
13
|
+
label = [textNode(input, value, cursor + 1, close)];
|
|
14
|
+
cursor = close + 1;
|
|
15
|
+
}
|
|
16
|
+
let attributes = [];
|
|
17
|
+
if (value.char(cursor) === "{") {
|
|
18
|
+
const close = findUnescapedInline(value, "}", cursor + 1);
|
|
19
|
+
if (close === void 0) return;
|
|
20
|
+
attributes = parseDirectiveAttributes(value.slice(cursor + 1, close));
|
|
21
|
+
cursor = close + 1;
|
|
22
|
+
}
|
|
23
|
+
if (label.length === 0 && attributes.length === 0) return;
|
|
24
|
+
return {
|
|
25
|
+
end: cursor,
|
|
26
|
+
node: {
|
|
27
|
+
kind: "directive",
|
|
28
|
+
range: input.sourceRange(start, cursor),
|
|
29
|
+
name,
|
|
30
|
+
label,
|
|
31
|
+
attributes
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** A directive whose label or attributes later input could still close. */
|
|
36
|
+
function directiveUnfinished(value, start) {
|
|
37
|
+
const name = /^[A-Za-z][\w-]*/u.exec(value.slice(start + 1))?.[0];
|
|
38
|
+
if (name === void 0 || value.char(start + 1) === ":") return false;
|
|
39
|
+
const cursor = start + 1 + name.length;
|
|
40
|
+
return value.char(cursor) === "[" && findUnescapedInline(value, "]", cursor + 1) === void 0 || value.char(cursor) === "{" && findUnescapedInline(value, "}", cursor + 1) === void 0 || cursor === value.length;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { directiveUnfinished, inlineDirective };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=inline-directive.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-directive.mjs","names":[],"sources":["../../src/parser/inline-directive.ts"],"sourcesContent":["import type { SourceText } from \"../source-text.ts\";\nimport type { InlineInput } from \"./inline-input.ts\";\nimport type { InlineMatch } from \"./inline-output.ts\";\nimport type { InlineDirectiveAttribute, InlineSyntax } from \"./inline-syntax.ts\";\n\nimport { parseDirectiveAttributes } from \"./directive-attributes.ts\";\nimport { findUnescapedInline, textNode } from \"./inline-output.ts\";\n\n// Text directives.\n\nexport function inlineDirective(\n input: InlineInput,\n value: SourceText,\n start: number,\n): InlineMatch | undefined {\n if (value.char(start + 1) === \":\") {\n return;\n }\n\n const name = /^[A-Za-z][\\w-]*/u.exec(value.slice(start + 1))?.[0];\n\n if (name === undefined) {\n return;\n }\n\n let cursor = start + 1 + name.length;\n let label: readonly InlineSyntax[] = [];\n\n if (value.char(cursor) === \"[\") {\n const close = findUnescapedInline(value, \"]\", cursor + 1);\n\n if (close === undefined) {\n return;\n }\n\n label = [textNode(input, value, cursor + 1, close)];\n cursor = close + 1;\n }\n\n let attributes: readonly InlineDirectiveAttribute[] = [];\n\n if (value.char(cursor) === \"{\") {\n const close = findUnescapedInline(value, \"}\", cursor + 1);\n\n if (close === undefined) {\n return;\n }\n\n attributes = parseDirectiveAttributes(value.slice(cursor + 1, close));\n cursor = close + 1;\n }\n\n if (label.length === 0 && attributes.length === 0) {\n return;\n }\n\n return {\n end: cursor,\n node: {\n kind: \"directive\",\n range: input.sourceRange(start, cursor),\n name,\n label,\n attributes,\n },\n };\n}\n\n/** A directive whose label or attributes later input could still close. */\nexport function directiveUnfinished(value: SourceText, start: number): boolean {\n const name = /^[A-Za-z][\\w-]*/u.exec(value.slice(start + 1))?.[0];\n\n if (name === undefined || value.char(start + 1) === \":\") {\n return false;\n }\n\n const cursor = start + 1 + name.length;\n\n return (\n (value.char(cursor) === \"[\" && findUnescapedInline(value, \"]\", cursor + 1) === undefined) ||\n (value.char(cursor) === \"{\" && findUnescapedInline(value, \"}\", cursor + 1) === undefined) ||\n cursor === value.length\n );\n}\n"],"mappings":";;;AAUA,SAAgB,gBACd,OACA,OACA,OACyB;CACzB,IAAI,MAAM,KAAK,QAAQ,CAAC,MAAM,KAC5B;CAGF,MAAM,OAAO,mBAAmB,KAAK,MAAM,MAAM,QAAQ,CAAC,CAAC,CAAC,GAAG;CAE/D,IAAI,SAAS,KAAA,GACX;CAGF,IAAI,SAAS,QAAQ,IAAI,KAAK;CAC9B,IAAI,QAAiC,CAAC;CAEtC,IAAI,MAAM,KAAK,MAAM,MAAM,KAAK;EAC9B,MAAM,QAAQ,oBAAoB,OAAO,KAAK,SAAS,CAAC;EAExD,IAAI,UAAU,KAAA,GACZ;EAGF,QAAQ,CAAC,SAAS,OAAO,OAAO,SAAS,GAAG,KAAK,CAAC;EAClD,SAAS,QAAQ;CACnB;CAEA,IAAI,aAAkD,CAAC;CAEvD,IAAI,MAAM,KAAK,MAAM,MAAM,KAAK;EAC9B,MAAM,QAAQ,oBAAoB,OAAO,KAAK,SAAS,CAAC;EAExD,IAAI,UAAU,KAAA,GACZ;EAGF,aAAa,yBAAyB,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC;EACpE,SAAS,QAAQ;CACnB;CAEA,IAAI,MAAM,WAAW,KAAK,WAAW,WAAW,GAC9C;CAGF,OAAO;EACL,KAAK;EACL,MAAM;GACJ,MAAM;GACN,OAAO,MAAM,YAAY,OAAO,MAAM;GACtC;GACA;GACA;EACF;CACF;AACF;;AAGA,SAAgB,oBAAoB,OAAmB,OAAwB;CAC7E,MAAM,OAAO,mBAAmB,KAAK,MAAM,MAAM,QAAQ,CAAC,CAAC,CAAC,GAAG;CAE/D,IAAI,SAAS,KAAA,KAAa,MAAM,KAAK,QAAQ,CAAC,MAAM,KAClD,OAAO;CAGT,MAAM,SAAS,QAAQ,IAAI,KAAK;CAEhC,OACG,MAAM,KAAK,MAAM,MAAM,OAAO,oBAAoB,OAAO,KAAK,SAAS,CAAC,MAAM,KAAA,KAC9E,MAAM,KAAK,MAAM,MAAM,OAAO,oBAAoB,OAAO,KAAK,SAAS,CAAC,MAAM,KAAA,KAC/E,WAAW,MAAM;AAErB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SourceText } from "../source-text.mjs";
|
|
2
|
+
import { InlineInput } from "./inline-input.mjs";
|
|
3
|
+
import { InlineSyntax } from "./inline-syntax.mjs";
|
|
4
|
+
import { InlineMatch } from "./inline-output.mjs";
|
|
5
|
+
//#region src/parser/inline-embedded.d.ts
|
|
6
|
+
interface OptionalInlineMatch {
|
|
7
|
+
readonly end: number;
|
|
8
|
+
readonly node: InlineSyntax | undefined;
|
|
9
|
+
readonly open: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface AngleMatch extends InlineMatch {
|
|
12
|
+
readonly invalid: boolean;
|
|
13
|
+
readonly open: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function expressionNode(input: InlineInput, value: SourceText, start: number): OptionalInlineMatch | undefined;
|
|
16
|
+
export declare function angleNode(input: InlineInput, value: SourceText, start: number): AngleMatch | undefined;
|
|
17
|
+
//#endregion
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=inline-embedded.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-embedded.d.mts","names":[],"sources":["../../src/parser/inline-embedded.ts"],"mappings":";;;;;UAYU;WACC;WACA,MAAM;WACN;;UAGD,mBAAmB;WAClB;WACA;;wBAGK,eACd,OAAO,aACP,OAAO,YACP,gBACC;wBAuCa,UACd,OAAO,aACP,OAAO,YACP,gBACC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { JavaScriptScanner } from "./javascript-scanner.mjs";
|
|
2
|
+
import { JsxBoundaryScanner } from "./embedded-scanner.mjs";
|
|
3
|
+
import { parseJavaScriptBoundary } from "./javascript-boundary.mjs";
|
|
4
|
+
import { textNode } from "./inline-output.mjs";
|
|
5
|
+
//#region src/parser/inline-embedded.ts
|
|
6
|
+
function expressionNode(input, value, start) {
|
|
7
|
+
const structural = new JavaScriptScanner("}").append(value.slice(start + 1));
|
|
8
|
+
if (structural.kind === "open") return {
|
|
9
|
+
end: value.length,
|
|
10
|
+
node: void 0,
|
|
11
|
+
open: true
|
|
12
|
+
};
|
|
13
|
+
const end = start + 1 + structural.offset;
|
|
14
|
+
if (structural.kind === "invalid") return {
|
|
15
|
+
end,
|
|
16
|
+
node: void 0,
|
|
17
|
+
open: false
|
|
18
|
+
};
|
|
19
|
+
const authored = value.slice(start + 1, end - 1);
|
|
20
|
+
const boundary = authored.trim() === "" ? void 0 : parseJavaScriptBoundary("expression", authored, input.sourceRange(start + 1, start + 1).start);
|
|
21
|
+
return {
|
|
22
|
+
end,
|
|
23
|
+
open: false,
|
|
24
|
+
node: authored.trim() === "" || boundary?.kind === "valid" ? {
|
|
25
|
+
kind: "expression",
|
|
26
|
+
range: input.sourceRange(start, end),
|
|
27
|
+
value: authored
|
|
28
|
+
} : void 0
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function angleNode(input, value, start) {
|
|
32
|
+
const rest = value.slice(start);
|
|
33
|
+
if (/^<(?:!--|!\[CDATA\[|\?|!)/u.test(rest)) {
|
|
34
|
+
const closing = rest.startsWith("<!--") ? "-->" : rest.startsWith("<![CDATA[") ? "]] >".replace(" ", "") : rest.startsWith("<?") ? "?>" : ">";
|
|
35
|
+
const close = rest.indexOf(closing, 2);
|
|
36
|
+
if (close === -1) return;
|
|
37
|
+
const end = start + close + closing.length;
|
|
38
|
+
return {
|
|
39
|
+
end,
|
|
40
|
+
invalid: false,
|
|
41
|
+
open: false,
|
|
42
|
+
node: {
|
|
43
|
+
kind: "rawHtml",
|
|
44
|
+
range: input.sourceRange(start, end),
|
|
45
|
+
value: value.slice(start, end)
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (!/^<(?:>|\/(?:>|[A-Za-z_$][\w$-]*(?:[.:][A-Za-z_$][\w$-]*)*(?=[\s>]))|[A-Za-z_$][\w$-]*(?:[.:][A-Za-z_$][\w$-]*)*(?=[\s/{>]))/u.test(rest)) {
|
|
50
|
+
const autolink = /^<((?:https?:\/\/|mailto:)[^ <>]+|[^ <>@]+@[^ <>@]+)>/u.exec(rest);
|
|
51
|
+
if (autolink === null) return;
|
|
52
|
+
const end = start + autolink[0].length;
|
|
53
|
+
const label = autolink[1];
|
|
54
|
+
const destination = /^(?:https?:\/\/|mailto:)/iu.test(label) ? label : `mailto:${label}`;
|
|
55
|
+
return {
|
|
56
|
+
end,
|
|
57
|
+
invalid: false,
|
|
58
|
+
open: false,
|
|
59
|
+
node: {
|
|
60
|
+
kind: "link",
|
|
61
|
+
range: input.sourceRange(start, end),
|
|
62
|
+
destination,
|
|
63
|
+
title: void 0,
|
|
64
|
+
children: [textNode(input, value, start + 1, end - 1)]
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const structural = new JsxBoundaryScanner().append(rest);
|
|
69
|
+
const end = structural.kind === "open" ? value.length : start + structural.offset;
|
|
70
|
+
if (structural.kind !== "closed") return {
|
|
71
|
+
end,
|
|
72
|
+
invalid: true,
|
|
73
|
+
open: structural.kind === "open",
|
|
74
|
+
node: textNode(input, value, start, end)
|
|
75
|
+
};
|
|
76
|
+
const authored = value.slice(start, end);
|
|
77
|
+
const valid = parseJavaScriptBoundary("jsxExpression", authored, input.sourceRange(start, start).start).kind === "valid";
|
|
78
|
+
return {
|
|
79
|
+
end,
|
|
80
|
+
invalid: !valid,
|
|
81
|
+
open: false,
|
|
82
|
+
node: valid ? {
|
|
83
|
+
kind: "jsx",
|
|
84
|
+
range: input.sourceRange(start, end),
|
|
85
|
+
value: authored
|
|
86
|
+
} : textNode(input, value, start, end)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
export { angleNode, expressionNode };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=inline-embedded.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-embedded.mjs","names":[],"sources":["../../src/parser/inline-embedded.ts"],"sourcesContent":["import type { SourceText } from \"../source-text.ts\";\nimport type { InlineInput } from \"./inline-input.ts\";\nimport type { InlineMatch } from \"./inline-output.ts\";\nimport type { InlineSyntax } from \"./inline-syntax.ts\";\n\nimport { JsxBoundaryScanner } from \"./embedded-scanner.ts\";\nimport { textNode } from \"./inline-output.ts\";\nimport { parseJavaScriptBoundary } from \"./javascript-boundary.ts\";\nimport { JavaScriptScanner } from \"./javascript-scanner.ts\";\n\n// Inline JSX, raw HTML, autolinks in angle brackets, and expressions.\n\ninterface OptionalInlineMatch {\n readonly end: number;\n readonly node: InlineSyntax | undefined;\n readonly open: boolean;\n}\n\ninterface AngleMatch extends InlineMatch {\n readonly invalid: boolean;\n readonly open: boolean;\n}\n\nexport function expressionNode(\n input: InlineInput,\n value: SourceText,\n start: number,\n): OptionalInlineMatch | undefined {\n const scanner = new JavaScriptScanner(\"}\");\n const structural = scanner.append(value.slice(start + 1));\n\n if (structural.kind === \"open\") {\n return { end: value.length, node: undefined, open: true };\n }\n\n const end = start + 1 + structural.offset;\n\n if (structural.kind === \"invalid\") {\n return { end, node: undefined, open: false };\n }\n\n const authored = value.slice(start + 1, end - 1);\n\n const boundary =\n authored.trim() === \"\"\n ? undefined\n : parseJavaScriptBoundary(\n \"expression\",\n authored,\n input.sourceRange(start + 1, start + 1).start,\n );\n\n return {\n end,\n open: false,\n node:\n authored.trim() === \"\" || boundary?.kind === \"valid\"\n ? {\n kind: \"expression\",\n range: input.sourceRange(start, end),\n value: authored,\n }\n : undefined,\n };\n}\n\nexport function angleNode(\n input: InlineInput,\n value: SourceText,\n start: number,\n): AngleMatch | undefined {\n const rest = value.slice(start);\n\n if (/^<(?:!--|!\\[CDATA\\[|\\?|!)/u.test(rest)) {\n const closing = rest.startsWith(\"<!--\")\n ? \"-->\"\n : rest.startsWith(\"<![CDATA[\")\n ? \"]] >\".replace(\" \", \"\")\n : rest.startsWith(\"<?\")\n ? \"?>\"\n : \">\";\n\n const close = rest.indexOf(closing, 2);\n\n if (close === -1) {\n return;\n }\n\n const end = start + close + closing.length;\n\n return {\n end,\n invalid: false,\n open: false,\n node: {\n kind: \"rawHtml\",\n range: input.sourceRange(start, end),\n value: value.slice(start, end),\n },\n };\n }\n\n if (\n !/^<(?:>|\\/(?:>|[A-Za-z_$][\\w$-]*(?:[.:][A-Za-z_$][\\w$-]*)*(?=[\\s>]))|[A-Za-z_$][\\w$-]*(?:[.:][A-Za-z_$][\\w$-]*)*(?=[\\s/{>]))/u.test(\n rest,\n )\n ) {\n const autolink = /^<((?:https?:\\/\\/|mailto:)[^ <>]+|[^ <>@]+@[^ <>@]+)>/u.exec(rest);\n\n if (autolink === null) {\n return;\n }\n\n const end = start + autolink[0].length;\n const label = autolink[1];\n\n const destination = /^(?:https?:\\/\\/|mailto:)/iu.test(label) ? label : `mailto:${label}`;\n\n return {\n end,\n invalid: false,\n open: false,\n node: {\n kind: \"link\",\n range: input.sourceRange(start, end),\n destination,\n title: undefined,\n children: [textNode(input, value, start + 1, end - 1)],\n },\n };\n }\n\n const scanner = new JsxBoundaryScanner();\n const structural = scanner.append(rest);\n const end = structural.kind === \"open\" ? value.length : start + structural.offset;\n\n if (structural.kind !== \"closed\") {\n return {\n end,\n invalid: true,\n open: structural.kind === \"open\",\n node: textNode(input, value, start, end),\n };\n }\n\n const authored = value.slice(start, end);\n\n const boundary = parseJavaScriptBoundary(\n \"jsxExpression\",\n authored,\n input.sourceRange(start, start).start,\n );\n\n const valid = boundary.kind === \"valid\";\n\n return {\n end,\n invalid: !valid,\n open: false,\n node: valid\n ? { kind: \"jsx\", range: input.sourceRange(start, end), value: authored }\n : textNode(input, value, start, end),\n };\n}\n"],"mappings":";;;;;AAuBA,SAAgB,eACd,OACA,OACA,OACiC;CAEjC,MAAM,aAAa,IADC,kBAAkB,GACb,CAAC,CAAC,OAAO,MAAM,MAAM,QAAQ,CAAC,CAAC;CAExD,IAAI,WAAW,SAAS,QACtB,OAAO;EAAE,KAAK,MAAM;EAAQ,MAAM,KAAA;EAAW,MAAM;CAAK;CAG1D,MAAM,MAAM,QAAQ,IAAI,WAAW;CAEnC,IAAI,WAAW,SAAS,WACtB,OAAO;EAAE;EAAK,MAAM,KAAA;EAAW,MAAM;CAAM;CAG7C,MAAM,WAAW,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;CAE/C,MAAM,WACJ,SAAS,KAAK,MAAM,KAChB,KAAA,IACA,wBACE,cACA,UACA,MAAM,YAAY,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,KAC1C;CAEN,OAAO;EACL;EACA,MAAM;EACN,MACE,S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M,WAAW,SAAS;EAC1B,MAAM,SAAS,OAAO,OAAO,OAAO,GAAG;CACzC;CAGF,MAAM,WAAW,MAAM,MAAM,OAAO,GAAG;CAQvC,MAAM,QANW,wBACf,iBACA,UACA,MAAM,YAAY,OAAO,KAAK,CAAC,CAAC,KAGb,CAAC,CAAC,SAAS;CAEhC,OAAO;EACL;EACA,SAAS,CAAC;EACV,MAAM;EACN,MAAM,QACF;GAAE,MAAM;GAAO,OAAO,MAAM,YAAY,OAAO,GAAG;GAAG,OAAO;EAAS,IACrE,SAAS,OAAO,OAAO,OAAO,GAAG;CACvC;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ResolvedSyntaxOptions } from "../syntax-options.mjs";
|
|
2
|
+
import { SourceText } from "../source-text.mjs";
|
|
3
|
+
import { InlineInput } from "./inline-input.mjs";
|
|
4
|
+
import { Delimiter, Output } from "./inline-output.mjs";
|
|
5
|
+
//#region src/parser/inline-emphasis.d.ts
|
|
6
|
+
export declare function createDelimiter(value: SourceText, start: number, end: number, marker: Delimiter["marker"]): Delimiter;
|
|
7
|
+
export declare function resolveCloser(input: InlineInput, output: Output[], delimiters: Delimiter[], closer: Delimiter, syntax: ResolvedSyntaxOptions, after?: number): void;
|
|
8
|
+
/** Resolves closers that were held behind a bracket boundary. */
|
|
9
|
+
export declare function resolveDelimiters(input: InlineInput, output: Output[], delimiters: Delimiter[], syntax: ResolvedSyntaxOptions, after?: number): void;
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=inline-emphasis.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-emphasis.d.mts","names":[],"sources":["../../src/parser/inline-emphasis.ts"],"mappings":";;;;;wBAWgB,gBACd,OAAO,YACP,eACA,aACA,QAAQ,sBACP;wBAwBa,cACd,OAAO,aACP,QAAQ,UACR,YAAY,aACZ,QAAQ,WACR,QAAQ,uBACR;;wBAmGc,kBACd,OAAO,aACP,QAAQ,UACR,YAAY,aACZ,QAAQ,uBACR"}
|