@wdprlib/parser 3.1.2 → 4.0.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/dist/index.cjs +10456 -8230
- package/dist/index.d.cts +313 -337
- package/dist/index.d.ts +313 -337
- package/dist/index.js +10460 -8234
- package/package.json +5 -3
- package/src/index.ts +170 -0
- package/src/lexer/anchor.ts +48 -0
- package/src/lexer/index.ts +21 -0
- package/src/lexer/lexer.ts +201 -0
- package/src/lexer/options.ts +19 -0
- package/src/lexer/punctuation.ts +70 -0
- package/src/lexer/quoted-string.ts +16 -0
- package/src/lexer/runs.ts +85 -0
- package/src/lexer/spacing-actions.ts +24 -0
- package/src/lexer/state.ts +103 -0
- package/src/lexer/syntax-actions.ts +80 -0
- package/src/lexer/text-actions.ts +41 -0
- package/src/lexer/token-actions.ts +136 -0
- package/src/lexer/token-factory.ts +62 -0
- package/src/lexer/tokenize.ts +18 -0
- package/src/lexer/tokens.ts +141 -0
- package/src/parser/constants.ts +175 -0
- package/src/parser/depth/index.ts +111 -0
- package/src/parser/depth/stack.ts +82 -0
- package/src/parser/index.ts +18 -0
- package/src/parser/parse/block.ts +42 -0
- package/src/parser/parse/context.ts +26 -0
- package/src/parser/parse/footnotes.ts +25 -0
- package/src/parser/parse/index.ts +42 -0
- package/src/parser/parse/options.ts +34 -0
- package/src/parser/parse/parser.ts +79 -0
- package/src/parser/parse/plain-non-ascii.ts +129 -0
- package/src/parser/parse/result.ts +57 -0
- package/src/parser/parse/source.ts +11 -0
- package/src/parser/postprocess/divAdjacentParagraph.ts +76 -0
- package/src/parser/postprocess/index.ts +15 -0
- package/src/parser/postprocess/spanStrip/clean-element.ts +168 -0
- package/src/parser/postprocess/spanStrip/cleanup.ts +25 -0
- package/src/parser/postprocess/spanStrip/empty-spans.ts +36 -0
- package/src/parser/postprocess/spanStrip/escaped.ts +78 -0
- package/src/parser/postprocess/spanStrip/factory.ts +23 -0
- package/src/parser/postprocess/spanStrip/index.ts +8 -0
- package/src/parser/postprocess/spanStrip/merge.ts +117 -0
- package/src/parser/postprocess/spanStrip/predicates.ts +59 -0
- package/src/parser/postprocess/spanStrip/split.ts +67 -0
- package/src/parser/preprocess/expr/chars.ts +15 -0
- package/src/parser/preprocess/expr/evaluate.ts +22 -0
- package/src/parser/preprocess/expr/index.ts +45 -0
- package/src/parser/preprocess/expr/kind.ts +19 -0
- package/src/parser/preprocess/expr/parse.ts +103 -0
- package/src/parser/preprocess/expr/scan.ts +34 -0
- package/src/parser/preprocess/expr/types.ts +14 -0
- package/src/parser/preprocess/index.ts +38 -0
- package/src/parser/preprocess/typography.ts +132 -0
- package/src/parser/preprocess/utils/bracket-depths.ts +98 -0
- package/src/parser/preprocess/utils/index.ts +13 -0
- package/src/parser/preprocess/utils/raw-regions.ts +153 -0
- package/src/parser/preprocess/whitespace/detection.ts +39 -0
- package/src/parser/preprocess/whitespace/index.ts +79 -0
- package/src/parser/preprocess/whitespace/leading-spaces.ts +11 -0
- package/src/parser/preprocess/whitespace/patterns.ts +23 -0
- package/src/parser/rules/block/align/body.ts +46 -0
- package/src/parser/rules/block/align/element.ts +13 -0
- package/src/parser/rules/block/align/index.ts +90 -0
- package/src/parser/rules/block/align/syntax.ts +113 -0
- package/src/parser/rules/block/bibliography/body.ts +81 -0
- package/src/parser/rules/block/bibliography/entries.ts +49 -0
- package/src/parser/rules/block/bibliography/entry-content.ts +73 -0
- package/src/parser/rules/block/bibliography/entry-key.ts +83 -0
- package/src/parser/rules/block/bibliography/index.ts +90 -0
- package/src/parser/rules/block/bibliography/open.ts +53 -0
- package/src/parser/rules/block/block-list/bare-content.ts +105 -0
- package/src/parser/rules/block/block-list/bare-paragraph.ts +60 -0
- package/src/parser/rules/block/block-list/index.ts +51 -0
- package/src/parser/rules/block/block-list/item-content.ts +132 -0
- package/src/parser/rules/block/block-list/li-content.ts +107 -0
- package/src/parser/rules/block/block-list/li-item.ts +77 -0
- package/src/parser/rules/block/block-list/list-block.ts +100 -0
- package/src/parser/rules/block/block-list/open.ts +51 -0
- package/src/parser/rules/block/block-list/tags.ts +50 -0
- package/src/parser/rules/block/blockquote/build.ts +62 -0
- package/src/parser/rules/block/blockquote/index.ts +80 -0
- package/src/parser/rules/block/blockquote/line.ts +79 -0
- package/src/parser/rules/block/blockquote/lines.ts +39 -0
- package/src/parser/rules/block/center/index.ts +72 -0
- package/src/parser/rules/block/center/open.ts +27 -0
- package/src/parser/rules/block/clear-float/index.ts +51 -0
- package/src/parser/rules/block/clear-float/syntax.ts +43 -0
- package/src/parser/rules/block/code/attributes.ts +30 -0
- package/src/parser/rules/block/code/content.ts +57 -0
- package/src/parser/rules/block/code/index.ts +100 -0
- package/src/parser/rules/block/collapsible/attributes.ts +95 -0
- package/src/parser/rules/block/collapsible/body.ts +69 -0
- package/src/parser/rules/block/collapsible/index.ts +117 -0
- package/src/parser/rules/block/collapsible/open.ts +51 -0
- package/src/parser/rules/block/collapsible/orphans.ts +31 -0
- package/src/parser/rules/block/collapsible/tags.ts +17 -0
- package/src/parser/rules/block/comment/consume.ts +37 -0
- package/src/parser/rules/block/comment/index.ts +47 -0
- package/src/parser/rules/block/content-separator/index.ts +49 -0
- package/src/parser/rules/block/content-separator/syntax.ts +33 -0
- package/src/parser/rules/block/definition-list/collect.ts +40 -0
- package/src/parser/rules/block/definition-list/index.ts +63 -0
- package/src/parser/rules/block/definition-list/item-key.ts +95 -0
- package/src/parser/rules/block/definition-list/item-value.ts +56 -0
- package/src/parser/rules/block/definition-list/items.ts +54 -0
- package/src/parser/rules/block/div/body.ts +41 -0
- package/src/parser/rules/block/div/close.ts +41 -0
- package/src/parser/rules/block/div/failed.ts +117 -0
- package/src/parser/rules/block/div/index.ts +112 -0
- package/src/parser/rules/block/div/nesting.ts +37 -0
- package/src/parser/rules/block/div/open.ts +59 -0
- package/src/parser/rules/block/div/paragraph-strip.ts +44 -0
- package/src/parser/rules/block/embed-block/content.ts +53 -0
- package/src/parser/rules/block/embed-block/index.ts +91 -0
- package/src/parser/rules/block/embed-block/open.ts +52 -0
- package/src/parser/rules/block/embed-block/tags.ts +5 -0
- package/src/parser/rules/block/footnoteblock/attributes.ts +73 -0
- package/src/parser/rules/block/footnoteblock/index.ts +82 -0
- package/src/parser/rules/block/footnoteblock/open.ts +53 -0
- package/src/parser/rules/block/heading/index.ts +87 -0
- package/src/parser/rules/block/heading/open.ts +50 -0
- package/src/parser/rules/block/heading/toc-text.ts +26 -0
- package/src/parser/rules/block/horizontal-rule/index.ts +44 -0
- package/src/parser/rules/block/horizontal-rule/syntax.ts +21 -0
- package/src/parser/rules/block/html/body.ts +114 -0
- package/src/parser/rules/block/html/diagnostics.ts +11 -0
- package/src/parser/rules/block/html/index.ts +95 -0
- package/src/parser/rules/block/html/open.ts +36 -0
- package/src/parser/rules/block/iframe/attributes.ts +106 -0
- package/src/parser/rules/block/iframe/index.ts +73 -0
- package/src/parser/rules/block/iframe/open.ts +58 -0
- package/src/parser/rules/block/iframe/source.ts +24 -0
- package/src/parser/rules/block/iframe/url.ts +38 -0
- package/src/parser/rules/block/iftags/body.ts +48 -0
- package/src/parser/rules/block/iftags/condition.ts +24 -0
- package/src/parser/rules/block/iftags/index.ts +108 -0
- package/src/parser/rules/block/include/arguments.ts +48 -0
- package/src/parser/rules/block/include/index.ts +75 -0
- package/src/parser/rules/block/include/location.ts +24 -0
- package/src/parser/rules/block/include/variables.ts +37 -0
- package/src/parser/rules/block/index.ts +127 -0
- package/src/parser/rules/block/list/index.ts +73 -0
- package/src/parser/rules/block/list/line.ts +77 -0
- package/src/parser/rules/block/list/native.ts +89 -0
- package/src/parser/rules/block/math/content.ts +54 -0
- package/src/parser/rules/block/math/index.ts +106 -0
- package/src/parser/rules/block/math/name.ts +35 -0
- package/src/parser/rules/block/module/backlinks/index.ts +31 -0
- package/src/parser/rules/block/module/backlinks/types.ts +21 -0
- package/src/parser/rules/block/module/body.ts +92 -0
- package/src/parser/rules/block/module/categories/index.ts +34 -0
- package/src/parser/rules/block/module/categories/types.ts +21 -0
- package/src/parser/rules/block/module/css/index.ts +37 -0
- package/src/parser/rules/block/module/element.ts +33 -0
- package/src/parser/rules/block/module/iftags/condition.ts +109 -0
- package/src/parser/rules/block/module/iftags/index.ts +26 -0
- package/src/parser/rules/block/module/iftags/preprocess.ts +140 -0
- package/src/parser/rules/block/module/iftags/resolve.ts +73 -0
- package/src/parser/rules/block/module/iftags/types.ts +63 -0
- package/src/parser/rules/block/module/include/directive.ts +91 -0
- package/src/parser/rules/block/module/include/index.ts +29 -0
- package/src/parser/rules/block/module/include/references.ts +42 -0
- package/src/parser/rules/block/module/include/resolve/cache.ts +44 -0
- package/src/parser/rules/block/module/include/resolve/index.ts +106 -0
- package/src/parser/rules/block/module/include/resolve/iterate.ts +202 -0
- package/src/parser/rules/block/module/include/resolve/replace.ts +31 -0
- package/src/parser/rules/block/module/include/resolve/types.ts +105 -0
- package/src/parser/rules/block/module/include/scanner.ts +121 -0
- package/src/parser/rules/block/module/index.ts +134 -0
- package/src/parser/rules/block/module/join/index.ts +34 -0
- package/src/parser/rules/block/module/join/types.ts +23 -0
- package/src/parser/rules/block/module/listpages/compiler.ts +73 -0
- package/src/parser/rules/block/module/listpages/extract.ts +76 -0
- package/src/parser/rules/block/module/listpages/extraction/listpages.ts +42 -0
- package/src/parser/rules/block/module/listpages/extraction/listusers.ts +30 -0
- package/src/parser/rules/block/module/listpages/extraction/query.ts +51 -0
- package/src/parser/rules/block/module/listpages/extraction/result.ts +18 -0
- package/src/parser/rules/block/module/listpages/extraction/template.ts +96 -0
- package/src/parser/rules/block/module/listpages/extraction/variables.ts +58 -0
- package/src/parser/rules/block/module/listpages/index.ts +83 -0
- package/src/parser/rules/block/module/listpages/normalization/date-selector.ts +53 -0
- package/src/parser/rules/block/module/listpages/normalization/numeric-selector.ts +32 -0
- package/src/parser/rules/block/module/listpages/normalization/order-parent.ts +82 -0
- package/src/parser/rules/block/module/listpages/normalization/selectors.ts +2 -0
- package/src/parser/rules/block/module/listpages/normalization/tags-category.ts +86 -0
- package/src/parser/rules/block/module/listpages/normalize.ts +74 -0
- package/src/parser/rules/block/module/listpages/parser.ts +106 -0
- package/src/parser/rules/block/module/listpages/resolution/items.ts +43 -0
- package/src/parser/rules/block/module/listpages/resolution/wrapper.ts +42 -0
- package/src/parser/rules/block/module/listpages/resolve.ts +60 -0
- package/src/parser/rules/block/module/listpages/template/format/content.ts +41 -0
- package/src/parser/rules/block/module/listpages/template/format/date.ts +116 -0
- package/src/parser/rules/block/module/listpages/template/format/index.ts +4 -0
- package/src/parser/rules/block/module/listpages/template/format/tags.ts +7 -0
- package/src/parser/rules/block/module/listpages/template/format/user.ts +9 -0
- package/src/parser/rules/block/module/listpages/template/getters/index.ts +36 -0
- package/src/parser/rules/block/module/listpages/template/getters/parameterized.ts +60 -0
- package/src/parser/rules/block/module/listpages/template/getters/simple.ts +65 -0
- package/src/parser/rules/block/module/listpages/template/getters/types.ts +3 -0
- package/src/parser/rules/block/module/listpages/template/syntax.ts +97 -0
- package/src/parser/rules/block/module/listpages/types/data-fetcher.ts +15 -0
- package/src/parser/rules/block/module/listpages/types/data-requirements.ts +52 -0
- package/src/parser/rules/block/module/listpages/types/external-data.ts +77 -0
- package/src/parser/rules/block/module/listpages/types/index.ts +17 -0
- package/src/parser/rules/block/module/listpages/types/normalized-query.ts +120 -0
- package/src/parser/rules/block/module/listpages/types/query.ts +67 -0
- package/src/parser/rules/block/module/listpages/types/template.ts +17 -0
- package/src/parser/rules/block/module/listpages/types/variables.ts +69 -0
- package/src/parser/rules/block/module/listpages/url-resolution/fields.ts +48 -0
- package/src/parser/rules/block/module/listpages/url-resolution/params.ts +19 -0
- package/src/parser/rules/block/module/listpages/url-resolution/query.ts +24 -0
- package/src/parser/rules/block/module/listpages/url-resolution/resolve.ts +53 -0
- package/src/parser/rules/block/module/listpages/url-resolution/value.ts +25 -0
- package/src/parser/rules/block/module/listpages/url-resolver.ts +29 -0
- package/src/parser/rules/block/module/listusers/compiler.ts +56 -0
- package/src/parser/rules/block/module/listusers/extract.ts +40 -0
- package/src/parser/rules/block/module/listusers/getters.ts +21 -0
- package/src/parser/rules/block/module/listusers/index.ts +36 -0
- package/src/parser/rules/block/module/listusers/parser.ts +54 -0
- package/src/parser/rules/block/module/listusers/resolve.ts +58 -0
- package/src/parser/rules/block/module/listusers/types.ts +93 -0
- package/src/parser/rules/block/module/listusers/variables.ts +15 -0
- package/src/parser/rules/block/module/mapping.ts +61 -0
- package/src/parser/rules/block/module/open.ts +57 -0
- package/src/parser/rules/block/module/page-tree/index.ts +38 -0
- package/src/parser/rules/block/module/page-tree/types.ts +29 -0
- package/src/parser/rules/block/module/rate/index.ts +28 -0
- package/src/parser/rules/block/module/rate/types.ts +19 -0
- package/src/parser/rules/block/module/resolution/contexts.ts +78 -0
- package/src/parser/rules/block/module/resolution/data-maps.ts +39 -0
- package/src/parser/rules/block/module/resolution/dynamic-modules.ts +93 -0
- package/src/parser/rules/block/module/resolution/styles.ts +53 -0
- package/src/parser/rules/block/module/resolution/walk-resolve.ts +107 -0
- package/src/parser/rules/block/module/resolve.ts +198 -0
- package/src/parser/rules/block/module/rule.ts +56 -0
- package/src/parser/rules/block/module/types-common.ts +70 -0
- package/src/parser/rules/block/module/types.ts +61 -0
- package/src/parser/rules/block/module/utils.ts +43 -0
- package/src/parser/rules/block/module/walk/children.ts +35 -0
- package/src/parser/rules/block/module/walk/index.ts +9 -0
- package/src/parser/rules/block/module/walk/map/index.ts +2 -0
- package/src/parser/rules/block/module/walk/map/stateful-definition-list.ts +25 -0
- package/src/parser/rules/block/module/walk/map/stateful-list.ts +40 -0
- package/src/parser/rules/block/module/walk/map/stateful-table.ts +23 -0
- package/src/parser/rules/block/module/walk/map/stateful-tabs.ts +19 -0
- package/src/parser/rules/block/module/walk/map/stateful.ts +71 -0
- package/src/parser/rules/block/module/walk/map/stateless-definition-list.ts +12 -0
- package/src/parser/rules/block/module/walk/map/stateless-list.ts +29 -0
- package/src/parser/rules/block/module/walk/map/stateless-table.ts +11 -0
- package/src/parser/rules/block/module/walk/map/stateless-tabs.ts +5 -0
- package/src/parser/rules/block/module/walk/map/stateless.ts +51 -0
- package/src/parser/rules/block/module/walk/map/types.ts +6 -0
- package/src/parser/rules/block/module/walk/traverse.ts +65 -0
- package/src/parser/rules/block/orphan-li/content.ts +60 -0
- package/src/parser/rules/block/orphan-li/index.ts +75 -0
- package/src/parser/rules/block/orphan-li/open.ts +25 -0
- package/src/parser/rules/block/orphan-li/tags.ts +40 -0
- package/src/parser/rules/block/paragraph/content.ts +12 -0
- package/src/parser/rules/block/paragraph/index.ts +60 -0
- package/src/parser/rules/block/paragraph/normalize.ts +52 -0
- package/src/parser/rules/block/paragraph/span-markers.ts +52 -0
- package/src/parser/rules/block/parsing/attributes/index.ts +32 -0
- package/src/parser/rules/block/parsing/attributes/names.ts +93 -0
- package/src/parser/rules/block/parsing/attributes/scanner.ts +75 -0
- package/src/parser/rules/block/parsing/attributes/values.ts +26 -0
- package/src/parser/rules/block/parsing/block-item.ts +29 -0
- package/src/parser/rules/block/parsing/content.ts +127 -0
- package/src/parser/rules/block/parsing/end-condition.ts +51 -0
- package/src/parser/rules/block/parsing/inline-content.ts +105 -0
- package/src/parser/rules/block/parsing/inline-newline.ts +41 -0
- package/src/parser/rules/block/parsing/non-boundary.ts +24 -0
- package/src/parser/rules/block/parsing/rule-dispatch.ts +44 -0
- package/src/parser/rules/block/table/index.ts +80 -0
- package/src/parser/rules/block/table/pipe/cell-start.ts +69 -0
- package/src/parser/rules/block/table/pipe/cell.ts +106 -0
- package/src/parser/rules/block/table/pipe/index.ts +2 -0
- package/src/parser/rules/block/table/pipe/row.ts +88 -0
- package/src/parser/rules/block/table/pipe/tokens.ts +14 -0
- package/src/parser/rules/block/table/pipe/trim.ts +50 -0
- package/src/parser/rules/block/table-block/body.ts +79 -0
- package/src/parser/rules/block/table-block/cell-attributes.ts +33 -0
- package/src/parser/rules/block/table-block/cell-boundary.ts +99 -0
- package/src/parser/rules/block/table-block/cell-content/index.ts +88 -0
- package/src/parser/rules/block/table-block/cell-content/segments.ts +134 -0
- package/src/parser/rules/block/table-block/cell-newline.ts +47 -0
- package/src/parser/rules/block/table-block/cell.ts +64 -0
- package/src/parser/rules/block/table-block/index.ts +113 -0
- package/src/parser/rules/block/table-block/row-boundary.ts +75 -0
- package/src/parser/rules/block/table-block/structure.ts +80 -0
- package/src/parser/rules/block/tabview/body.ts +64 -0
- package/src/parser/rules/block/tabview/index.ts +90 -0
- package/src/parser/rules/block/tabview/open.ts +50 -0
- package/src/parser/rules/block/tabview/tab.ts +92 -0
- package/src/parser/rules/block/tabview/tags.ts +30 -0
- package/src/parser/rules/block/toc/element.ts +11 -0
- package/src/parser/rules/block/toc/index.ts +44 -0
- package/src/parser/rules/block/toc/open.ts +84 -0
- package/src/parser/rules/block/utils.ts +15 -0
- package/src/parser/rules/common/attribute-safety.ts +109 -0
- package/src/parser/rules/common/block-name.ts +33 -0
- package/src/parser/rules/common/index.ts +2 -0
- package/src/parser/rules/contracts/index.ts +3 -0
- package/src/parser/rules/contracts/parse-context.ts +38 -0
- package/src/parser/rules/contracts/rule.ts +43 -0
- package/src/parser/rules/contracts/scope.ts +31 -0
- package/src/parser/rules/index.ts +49 -0
- package/src/parser/rules/inline/anchor/attributes.ts +54 -0
- package/src/parser/rules/inline/anchor/child.ts +26 -0
- package/src/parser/rules/inline/anchor/close.ts +34 -0
- package/src/parser/rules/inline/anchor/content.ts +59 -0
- package/src/parser/rules/inline/anchor/index.ts +103 -0
- package/src/parser/rules/inline/anchor/newline.ts +26 -0
- package/src/parser/rules/inline/anchor/open.ts +47 -0
- package/src/parser/rules/inline/anchor/paragraph-strip.ts +14 -0
- package/src/parser/rules/inline/anchor/syntax.ts +40 -0
- package/src/parser/rules/inline/anchor-name/index.ts +38 -0
- package/src/parser/rules/inline/anchor-name/name.ts +39 -0
- package/src/parser/rules/inline/anchor-name/syntax.ts +46 -0
- package/src/parser/rules/inline/bibcite/element.ts +14 -0
- package/src/parser/rules/inline/bibcite/index.ts +34 -0
- package/src/parser/rules/inline/bibcite/syntax.ts +64 -0
- package/src/parser/rules/inline/bold.ts +49 -0
- package/src/parser/rules/inline/color/index.ts +35 -0
- package/src/parser/rules/inline/color/syntax.ts +69 -0
- package/src/parser/rules/inline/comment/consume.ts +31 -0
- package/src/parser/rules/inline/comment/index.ts +64 -0
- package/src/parser/rules/inline/equation-ref/element.ts +8 -0
- package/src/parser/rules/inline/equation-ref/index.ts +34 -0
- package/src/parser/rules/inline/equation-ref/syntax.ts +45 -0
- package/src/parser/rules/inline/expr/branch.ts +104 -0
- package/src/parser/rules/inline/expr/conditional-branch.ts +27 -0
- package/src/parser/rules/inline/expr/conditional.ts +80 -0
- package/src/parser/rules/inline/expr/depth.ts +25 -0
- package/src/parser/rules/inline/expr/elements.ts +39 -0
- package/src/parser/rules/inline/expr/index.ts +84 -0
- package/src/parser/rules/inline/expr/syntax.ts +45 -0
- package/src/parser/rules/inline/footnote/child.ts +22 -0
- package/src/parser/rules/inline/footnote/close.ts +33 -0
- package/src/parser/rules/inline/footnote/content.ts +54 -0
- package/src/parser/rules/inline/footnote/elements.ts +38 -0
- package/src/parser/rules/inline/footnote/index.ts +54 -0
- package/src/parser/rules/inline/footnote/newline.ts +27 -0
- package/src/parser/rules/inline/footnote/open.ts +38 -0
- package/src/parser/rules/inline/formatting/container.ts +50 -0
- package/src/parser/rules/inline/guillemet/index.ts +56 -0
- package/src/parser/rules/inline/guillemet/text.ts +11 -0
- package/src/parser/rules/inline/html/gate.ts +64 -0
- package/src/parser/rules/inline/html/index.ts +81 -0
- package/src/parser/rules/inline/html/open.ts +37 -0
- package/src/parser/rules/inline/image/attributes.ts +22 -0
- package/src/parser/rules/inline/image/body.ts +36 -0
- package/src/parser/rules/inline/image/index.ts +89 -0
- package/src/parser/rules/inline/image/open.ts +56 -0
- package/src/parser/rules/inline/image/source.ts +62 -0
- package/src/parser/rules/inline/image/syntax.ts +76 -0
- package/src/parser/rules/inline/index.ts +150 -0
- package/src/parser/rules/inline/italic.ts +46 -0
- package/src/parser/rules/inline/line-break/backslash.ts +58 -0
- package/src/parser/rules/inline/line-break/elements.ts +9 -0
- package/src/parser/rules/inline/line-break/index.ts +3 -0
- package/src/parser/rules/inline/line-break/newline.ts +82 -0
- package/src/parser/rules/inline/line-break/underscore.ts +45 -0
- package/src/parser/rules/inline/link-anchor.ts +72 -0
- package/src/parser/rules/inline/link-bracket/anchor.ts +3 -0
- package/src/parser/rules/inline/link-bracket/direct-url.ts +5 -0
- package/src/parser/rules/inline/link-bracket/parsed.ts +81 -0
- package/src/parser/rules/inline/link-bracket/parts.ts +64 -0
- package/src/parser/rules/inline/link-bracket/prefix.ts +15 -0
- package/src/parser/rules/inline/link-single.ts +73 -0
- package/src/parser/rules/inline/link-star.ts +72 -0
- package/src/parser/rules/inline/link-triple/fallback.ts +10 -0
- package/src/parser/rules/inline/link-triple/index.ts +62 -0
- package/src/parser/rules/inline/link-triple/interwiki.ts +11 -0
- package/src/parser/rules/inline/link-triple/label.ts +35 -0
- package/src/parser/rules/inline/link-triple/syntax.ts +72 -0
- package/src/parser/rules/inline/link-triple/target.ts +36 -0
- package/src/parser/rules/inline/math-inline/index.ts +40 -0
- package/src/parser/rules/inline/math-inline/syntax.ts +55 -0
- package/src/parser/rules/inline/monospace.ts +50 -0
- package/src/parser/rules/inline/parsing/block-boundary.ts +42 -0
- package/src/parser/rules/inline/parsing/block-start-predicates.ts +117 -0
- package/src/parser/rules/inline/parsing/collect.ts +23 -0
- package/src/parser/rules/inline/parsing/inline-content.ts +115 -0
- package/src/parser/rules/inline/parsing/paragraph-boundary.ts +47 -0
- package/src/parser/rules/inline/parsing/plain-text.ts +69 -0
- package/src/parser/rules/inline/parsing/preserved-line-break.ts +11 -0
- package/src/parser/rules/inline/parsing/rules.ts +34 -0
- package/src/parser/rules/inline/parsing/simple-token.ts +26 -0
- package/src/parser/rules/inline/raw/angle.ts +40 -0
- package/src/parser/rules/inline/raw/double-at.ts +78 -0
- package/src/parser/rules/inline/raw/index.ts +26 -0
- package/src/parser/rules/inline/raw/result.ts +26 -0
- package/src/parser/rules/inline/size/content.ts +65 -0
- package/src/parser/rules/inline/size/index.ts +55 -0
- package/src/parser/rules/inline/size/open.ts +43 -0
- package/src/parser/rules/inline/size/value.ts +45 -0
- package/src/parser/rules/inline/span/content.ts +97 -0
- package/src/parser/rules/inline/span/elements.ts +108 -0
- package/src/parser/rules/inline/span/index.ts +79 -0
- package/src/parser/rules/inline/span/newline.ts +50 -0
- package/src/parser/rules/inline/span/syntax.ts +70 -0
- package/src/parser/rules/inline/strikethrough/index.ts +60 -0
- package/src/parser/rules/inline/strikethrough/parse.ts +14 -0
- package/src/parser/rules/inline/strikethrough/syntax.ts +24 -0
- package/src/parser/rules/inline/subscript.ts +47 -0
- package/src/parser/rules/inline/superscript.ts +49 -0
- package/src/parser/rules/inline/text/element.ts +5 -0
- package/src/parser/rules/inline/text/index.ts +85 -0
- package/src/parser/rules/inline/underline/child.ts +26 -0
- package/src/parser/rules/inline/underline/content.ts +29 -0
- package/src/parser/rules/inline/underline/index.ts +84 -0
- package/src/parser/rules/inline/user/element.ts +11 -0
- package/src/parser/rules/inline/user/index.ts +34 -0
- package/src/parser/rules/inline/user/syntax.ts +67 -0
- package/src/parser/rules/inline/utils.ts +4 -0
- package/src/parser/rules/tokens.ts +106 -0
- package/src/parser/rules/types.ts +9 -0
- package/src/parser/toc.ts +130 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Parses the Wikidot single-bracket link syntax: `[url label]`.
|
|
4
|
+
*
|
|
5
|
+
* Single-bracket links create hyperlinks to external URLs or
|
|
6
|
+
* site-relative paths. The URL and label are separated by whitespace.
|
|
7
|
+
*
|
|
8
|
+
* Supported URL formats:
|
|
9
|
+
* - Absolute URLs: `[https://example.com/ Label]`
|
|
10
|
+
* - Relative paths: `[/some-page Label]`
|
|
11
|
+
*
|
|
12
|
+
* An optional `*` prefix on the URL opens the link in a new tab:
|
|
13
|
+
* `[*https://example.com/ Opens in new tab]`.
|
|
14
|
+
*
|
|
15
|
+
* Unlike triple-bracket links (`[[[page]]]`), single-bracket links
|
|
16
|
+
* require a full URL (starting with `http://`, `https://`, or `/`).
|
|
17
|
+
* The label text is required.
|
|
18
|
+
*
|
|
19
|
+
* Produces a `"link"` AST element with `type: "direct"`.
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
import type { Element, LinkLabel } from "@wdprlib/ast";
|
|
24
|
+
import type { InlineRule, ParseContext, RuleResult } from "../types";
|
|
25
|
+
import { parseSingleBracketLink } from "./link-bracket/parsed";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Inline rule for parsing `[url label]` single-bracket links.
|
|
29
|
+
*
|
|
30
|
+
* Triggered by a `BRACKET_OPEN` (`[`) token. Optionally detects a
|
|
31
|
+
* `*` prefix for new-tab behavior, then collects the URL (until
|
|
32
|
+
* whitespace) and the label text (until `]`).
|
|
33
|
+
*
|
|
34
|
+
* Fails if:
|
|
35
|
+
* - No closing `]` is found on the same line
|
|
36
|
+
* - The URL does not start with `http://`, `https://`, or `/`
|
|
37
|
+
* - The label text is empty
|
|
38
|
+
*/
|
|
39
|
+
export const linkSingleRule: InlineRule = {
|
|
40
|
+
name: "linkSingle",
|
|
41
|
+
startTokens: ["BRACKET_OPEN"],
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Attempts to parse a single-bracket link at the current position.
|
|
45
|
+
*
|
|
46
|
+
* @param ctx - Parse context with token stream and current position
|
|
47
|
+
* @returns A successful result with a `"link"` element of type `"direct"`,
|
|
48
|
+
* or `{ success: false }`
|
|
49
|
+
*/
|
|
50
|
+
parse(ctx: ParseContext): RuleResult<Element> {
|
|
51
|
+
const parsed = parseSingleBracketLink(ctx);
|
|
52
|
+
if (!parsed) return { success: false };
|
|
53
|
+
|
|
54
|
+
const linkLabel: LinkLabel = { text: parsed.labelText };
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
success: true,
|
|
58
|
+
elements: [
|
|
59
|
+
{
|
|
60
|
+
element: "link",
|
|
61
|
+
data: {
|
|
62
|
+
type: "direct",
|
|
63
|
+
link: parsed.link,
|
|
64
|
+
extra: null,
|
|
65
|
+
label: linkLabel,
|
|
66
|
+
target: parsed.target,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
consumed: parsed.consumed,
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Parses the Wikidot star-link syntax: `[*url label]`.
|
|
4
|
+
*
|
|
5
|
+
* A star link is a convenience syntax for creating links that open
|
|
6
|
+
* in a new tab/window. The `[*` opening delimiter is tokenized as
|
|
7
|
+
* `BRACKET_STAR` by the lexer.
|
|
8
|
+
*
|
|
9
|
+
* Unlike the regular single-bracket link, the star link does not
|
|
10
|
+
* require a specific URL scheme -- any non-empty URL is accepted.
|
|
11
|
+
* If no label text is provided, the URL itself is used as the display text.
|
|
12
|
+
*
|
|
13
|
+
* The link always has `target: "new-tab"` regardless of the URL content.
|
|
14
|
+
*
|
|
15
|
+
* Wikidot syntax examples:
|
|
16
|
+
* - `[*https://example.com/ Visit Example]` -- with label
|
|
17
|
+
* - `[*https://example.com/]` -- URL used as label
|
|
18
|
+
*
|
|
19
|
+
* Produces a `"link"` AST element with `type: "direct"` and
|
|
20
|
+
* `target: "new-tab"`.
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import type { Element, LinkLabel } from "@wdprlib/ast";
|
|
25
|
+
import type { InlineRule, ParseContext, RuleResult } from "../types";
|
|
26
|
+
import { parseStarBracketLink } from "./link-bracket/parsed";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Inline rule for parsing `[*url label]` star links.
|
|
30
|
+
*
|
|
31
|
+
* Triggered by a `BRACKET_STAR` (`[*`) token. Collects the URL
|
|
32
|
+
* (until whitespace) and the optional label text (until `]`).
|
|
33
|
+
* When no label is provided, the URL serves as display text.
|
|
34
|
+
*
|
|
35
|
+
* Fails if:
|
|
36
|
+
* - No closing `]` is found on the same line
|
|
37
|
+
* - The URL is empty
|
|
38
|
+
*/
|
|
39
|
+
export const linkStarRule: InlineRule = {
|
|
40
|
+
name: "linkStar",
|
|
41
|
+
startTokens: ["BRACKET_STAR"],
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Attempts to parse a star link at the current position.
|
|
45
|
+
*
|
|
46
|
+
* @param ctx - Parse context with token stream and current position
|
|
47
|
+
* @returns A successful result with a `"link"` element, or `{ success: false }`
|
|
48
|
+
*/
|
|
49
|
+
parse(ctx: ParseContext): RuleResult<Element> {
|
|
50
|
+
const parsed = parseStarBracketLink(ctx);
|
|
51
|
+
if (!parsed) return { success: false };
|
|
52
|
+
|
|
53
|
+
const linkLabel: LinkLabel = { text: parsed.labelText };
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
success: true,
|
|
57
|
+
elements: [
|
|
58
|
+
{
|
|
59
|
+
element: "link",
|
|
60
|
+
data: {
|
|
61
|
+
type: "direct",
|
|
62
|
+
link: parsed.link,
|
|
63
|
+
extra: null,
|
|
64
|
+
label: linkLabel,
|
|
65
|
+
target: parsed.target,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
consumed: parsed.consumed,
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Element } from "@wdprlib/ast";
|
|
2
|
+
import type { RuleResult } from "../../types";
|
|
3
|
+
|
|
4
|
+
export function literalOpenLink(value: string): RuleResult<Element> {
|
|
5
|
+
return {
|
|
6
|
+
success: true,
|
|
7
|
+
elements: [{ element: "text", data: value }],
|
|
8
|
+
consumed: 1,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Parses the Wikidot triple-bracket link syntax: `[[[target | label]]]`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { Element } from "@wdprlib/ast";
|
|
8
|
+
import type { InlineRule, ParseContext, RuleResult } from "../../types";
|
|
9
|
+
import { currentToken } from "../../types";
|
|
10
|
+
import { literalOpenLink } from "./fallback";
|
|
11
|
+
import { buildTripleLinkLabel } from "./label";
|
|
12
|
+
import { collectTripleLinkParts, hasClosingLinkMarker } from "./syntax";
|
|
13
|
+
import {
|
|
14
|
+
determineLinkTypeAndLocation,
|
|
15
|
+
isInvalidTripleLinkTarget,
|
|
16
|
+
normalizeTripleLinkTarget,
|
|
17
|
+
} from "./target";
|
|
18
|
+
|
|
19
|
+
export const linkTripleRule: InlineRule = {
|
|
20
|
+
name: "linkTriple",
|
|
21
|
+
startTokens: ["LINK_OPEN"],
|
|
22
|
+
|
|
23
|
+
parse(ctx: ParseContext): RuleResult<Element> {
|
|
24
|
+
const startToken = currentToken(ctx);
|
|
25
|
+
|
|
26
|
+
if (!hasClosingLinkMarker(ctx, ctx.pos + 1)) {
|
|
27
|
+
return literalOpenLink(startToken.value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const parts = collectTripleLinkParts(ctx, ctx.pos + 1);
|
|
31
|
+
const trimmedTarget = parts.target.trim();
|
|
32
|
+
if (isInvalidTripleLinkTarget(trimmedTarget, parts.foundPipe)) {
|
|
33
|
+
return literalOpenLink(startToken.value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const normalized = normalizeTripleLinkTarget(trimmedTarget);
|
|
37
|
+
const { linkType, link } = determineLinkTypeAndLocation(normalized.target);
|
|
38
|
+
const label = buildTripleLinkLabel({
|
|
39
|
+
foundPipe: parts.foundPipe,
|
|
40
|
+
labelText: parts.labelText,
|
|
41
|
+
finalTarget: normalized.target,
|
|
42
|
+
originalTarget: trimmedTarget,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
success: true,
|
|
47
|
+
elements: [
|
|
48
|
+
{
|
|
49
|
+
element: "link",
|
|
50
|
+
data: {
|
|
51
|
+
type: linkType,
|
|
52
|
+
link,
|
|
53
|
+
extra: null,
|
|
54
|
+
label,
|
|
55
|
+
target: normalized.hasStar && linkType === "direct" ? "new-tab" : null,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
consumed: parts.consumed,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const INTERWIKI_PREFIXES = new Set(["wikipedia", "google", "dictionary", "wikidot"]);
|
|
2
|
+
|
|
3
|
+
export function isInterwikiTarget(target: string): boolean {
|
|
4
|
+
const colonIdx = target.indexOf(":");
|
|
5
|
+
if (colonIdx <= 0 || target.includes("/")) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const prefix = target.slice(0, colonIdx).toLowerCase();
|
|
10
|
+
return INTERWIKI_PREFIXES.has(prefix);
|
|
11
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { LinkLabel } from "@wdprlib/ast";
|
|
2
|
+
|
|
3
|
+
export function buildTripleLinkLabel(args: {
|
|
4
|
+
foundPipe: boolean;
|
|
5
|
+
labelText: string;
|
|
6
|
+
finalTarget: string;
|
|
7
|
+
originalTarget: string;
|
|
8
|
+
}): LinkLabel {
|
|
9
|
+
return {
|
|
10
|
+
text: getTripleLinkDisplayText(args),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getTripleLinkDisplayText(args: {
|
|
15
|
+
foundPipe: boolean;
|
|
16
|
+
labelText: string;
|
|
17
|
+
finalTarget: string;
|
|
18
|
+
originalTarget: string;
|
|
19
|
+
}): string {
|
|
20
|
+
const trimmedLabel = args.labelText.trim();
|
|
21
|
+
if (args.foundPipe) {
|
|
22
|
+
return trimmedLabel || args.finalTarget;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const colonIdx = args.originalTarget.indexOf(":");
|
|
26
|
+
if (
|
|
27
|
+
colonIdx !== -1 &&
|
|
28
|
+
!args.originalTarget.startsWith("http") &&
|
|
29
|
+
!args.originalTarget.startsWith("*")
|
|
30
|
+
) {
|
|
31
|
+
return args.originalTarget.slice(colonIdx + 1).trim();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return args.originalTarget;
|
|
35
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ParseContext } from "../../types";
|
|
2
|
+
|
|
3
|
+
export interface TripleLinkParts {
|
|
4
|
+
target: string;
|
|
5
|
+
labelText: string;
|
|
6
|
+
foundPipe: boolean;
|
|
7
|
+
consumed: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function hasClosingLinkMarker(ctx: ParseContext, startPos: number): boolean {
|
|
11
|
+
let pos = startPos;
|
|
12
|
+
while (pos < ctx.tokens.length) {
|
|
13
|
+
const token = ctx.tokens[pos];
|
|
14
|
+
if (!token || token.type === "EOF") {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (token.type === "LINK_CLOSE") {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (token.type === "NEWLINE") {
|
|
21
|
+
const next = ctx.tokens[pos + 1];
|
|
22
|
+
if (next?.type === "NEWLINE" || next?.type === "LINK_CLOSE") {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
pos++;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function collectTripleLinkParts(ctx: ParseContext, startPos: number): TripleLinkParts {
|
|
32
|
+
let target = "";
|
|
33
|
+
let labelText = "";
|
|
34
|
+
let foundPipe = false;
|
|
35
|
+
let consumed = 1;
|
|
36
|
+
let pos = startPos;
|
|
37
|
+
|
|
38
|
+
while (pos < ctx.tokens.length) {
|
|
39
|
+
const token = ctx.tokens[pos];
|
|
40
|
+
if (!token || token.type === "LINK_CLOSE" || token.type === "EOF") {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (token.type === "NEWLINE") {
|
|
45
|
+
if (foundPipe) {
|
|
46
|
+
labelText += " ";
|
|
47
|
+
} else {
|
|
48
|
+
target += " ";
|
|
49
|
+
}
|
|
50
|
+
consumed++;
|
|
51
|
+
pos++;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (token.type === "PIPE" && !foundPipe) {
|
|
56
|
+
foundPipe = true;
|
|
57
|
+
} else if (foundPipe) {
|
|
58
|
+
labelText += token.value;
|
|
59
|
+
} else {
|
|
60
|
+
target += token.value;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
consumed++;
|
|
64
|
+
pos++;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (ctx.tokens[pos]?.type === "LINK_CLOSE") {
|
|
68
|
+
consumed++;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return { target, labelText, foundPipe, consumed };
|
|
72
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { LinkLocation, LinkType } from "@wdprlib/ast";
|
|
2
|
+
import { isInterwikiTarget } from "./interwiki";
|
|
3
|
+
|
|
4
|
+
export interface TripleLinkTarget {
|
|
5
|
+
target: string;
|
|
6
|
+
hasStar: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function normalizeTripleLinkTarget(trimmedTarget: string): TripleLinkTarget {
|
|
10
|
+
if (trimmedTarget.startsWith("*")) {
|
|
11
|
+
return { target: trimmedTarget.slice(1), hasStar: true };
|
|
12
|
+
}
|
|
13
|
+
return { target: trimmedTarget, hasStar: false };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isInvalidTripleLinkTarget(trimmedTarget: string, foundPipe: boolean): boolean {
|
|
17
|
+
return (trimmedTarget === "" && foundPipe) || /#{2,}/.test(trimmedTarget);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function determineLinkTypeAndLocation(target: string): {
|
|
21
|
+
linkType: LinkType;
|
|
22
|
+
link: LinkLocation;
|
|
23
|
+
} {
|
|
24
|
+
if (target.startsWith("#")) {
|
|
25
|
+
return { linkType: "anchor", link: target };
|
|
26
|
+
}
|
|
27
|
+
if (target.startsWith("http://") || target.startsWith("https://")) {
|
|
28
|
+
return { linkType: "direct", link: target };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (isInterwikiTarget(target)) {
|
|
32
|
+
return { linkType: "interwiki", link: target };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return { linkType: "page", link: { site: null, page: target } };
|
|
36
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Parses the Wikidot inline math syntax: `[[$ LaTeX $]]`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { Element } from "@wdprlib/ast";
|
|
8
|
+
import type { InlineRule, ParseContext, RuleResult } from "../../types";
|
|
9
|
+
import { currentToken } from "../../types";
|
|
10
|
+
import { parseInlineMathSource } from "./syntax";
|
|
11
|
+
|
|
12
|
+
export const mathInlineRule: InlineRule = {
|
|
13
|
+
name: "math-inline",
|
|
14
|
+
startTokens: ["BLOCK_OPEN"],
|
|
15
|
+
|
|
16
|
+
parse(ctx: ParseContext): RuleResult<Element> {
|
|
17
|
+
const openToken = currentToken(ctx);
|
|
18
|
+
if (openToken.type !== "BLOCK_OPEN") {
|
|
19
|
+
return { success: false };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const parsed = parseInlineMathSource(ctx, ctx.pos + 1);
|
|
23
|
+
if (!parsed) {
|
|
24
|
+
return { success: false };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
success: true,
|
|
29
|
+
elements: [
|
|
30
|
+
{
|
|
31
|
+
element: "math-inline",
|
|
32
|
+
data: {
|
|
33
|
+
"latex-source": parsed.latexSource,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
consumed: 1 + parsed.consumed,
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ParseContext } from "../../types";
|
|
2
|
+
|
|
3
|
+
export function parseInlineMathSource(
|
|
4
|
+
ctx: ParseContext,
|
|
5
|
+
startPos: number,
|
|
6
|
+
): { latexSource: string; consumed: number } | null {
|
|
7
|
+
let pos = startPos;
|
|
8
|
+
let consumed = 0;
|
|
9
|
+
|
|
10
|
+
if (ctx.tokens[pos]?.type !== "TEXT" || ctx.tokens[pos]?.value !== "$") {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
pos++;
|
|
14
|
+
consumed++;
|
|
15
|
+
|
|
16
|
+
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
17
|
+
pos++;
|
|
18
|
+
consumed++;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let latexSource = "";
|
|
22
|
+
while (pos < ctx.tokens.length) {
|
|
23
|
+
const token = ctx.tokens[pos];
|
|
24
|
+
if (!token || token.type === "NEWLINE") {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
token.type === "TEXT" &&
|
|
30
|
+
token.value === "$" &&
|
|
31
|
+
ctx.tokens[pos + 1]?.type === "BLOCK_CLOSE"
|
|
32
|
+
) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
latexSource += token.value;
|
|
37
|
+
pos++;
|
|
38
|
+
consumed++;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (ctx.tokens[pos]?.type !== "TEXT" || ctx.tokens[pos]?.value !== "$") {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
pos++;
|
|
45
|
+
consumed++;
|
|
46
|
+
|
|
47
|
+
if (ctx.tokens[pos]?.type !== "BLOCK_CLOSE") {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
latexSource: latexSource.trim(),
|
|
53
|
+
consumed: consumed + 1,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Parses the Wikidot monospace (teletype) formatting syntax: `{{text}}`.
|
|
4
|
+
*
|
|
5
|
+
* Monospace text is delimited by double curly braces. The opening and
|
|
6
|
+
* closing markers must appear on the same line. If no closing `}}`
|
|
7
|
+
* is found before a newline, the opening marker is emitted as literal text.
|
|
8
|
+
*
|
|
9
|
+
* Note: the opening marker is `MONO_MARKER` (`{{`) and the closing marker
|
|
10
|
+
* is `MONO_CLOSE` (`}}`). These are distinct token types because `{` and
|
|
11
|
+
* `}` have different lexer significance in some contexts.
|
|
12
|
+
*
|
|
13
|
+
* Monospace is a "container" element, meaning it can nest other inline
|
|
14
|
+
* formatting within its body. It renders as a `<tt>` element in HTML.
|
|
15
|
+
*
|
|
16
|
+
* Wikidot syntax: `{{monospace text}}`
|
|
17
|
+
*
|
|
18
|
+
* Produces a `"container"` AST element with `type: "monospace"`.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import type { Element } from "@wdprlib/ast";
|
|
23
|
+
import type { InlineRule, ParseContext, RuleResult } from "../types";
|
|
24
|
+
import { parseSameLineDelimitedContainer } from "./formatting/container";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Inline rule for parsing `{{monospace}}` formatting.
|
|
28
|
+
*
|
|
29
|
+
* Triggered by a `MONO_MARKER` token (`{{`). Checks for a matching
|
|
30
|
+
* `MONO_CLOSE` (`}}`) on the same line, then recursively parses
|
|
31
|
+
* inline content between the markers.
|
|
32
|
+
*
|
|
33
|
+
* When no closing marker is found, the opening `{{` is treated as
|
|
34
|
+
* literal text.
|
|
35
|
+
*/
|
|
36
|
+
export const monospaceRule: InlineRule = {
|
|
37
|
+
name: "monospace",
|
|
38
|
+
startTokens: ["MONO_MARKER"],
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Attempts to parse monospace formatting at the current position.
|
|
42
|
+
*
|
|
43
|
+
* @param ctx - Parse context with token stream and current position
|
|
44
|
+
* @returns A successful result containing either a `"container"` element
|
|
45
|
+
* with `type: "monospace"`, or a text fallback for unmatched markers
|
|
46
|
+
*/
|
|
47
|
+
parse(ctx: ParseContext): RuleResult<Element> {
|
|
48
|
+
return parseSameLineDelimitedContainer(ctx, "MONO_CLOSE", "monospace");
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ParseContext } from "../../types";
|
|
2
|
+
import { INDENT_ACCEPTING_BLOCK_NAMES, KNOWN_BLOCK_NAMES } from "../../../constants";
|
|
3
|
+
import { parseBlockName } from "../../common";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether the block token at `tokenPos` names a block in the excluded set.
|
|
7
|
+
*/
|
|
8
|
+
export function isExcludedBlockToken(ctx: ParseContext, tokenPos: number): boolean {
|
|
9
|
+
const excluded = ctx.scope.excludedBlockNames;
|
|
10
|
+
if (!excluded?.size) return false;
|
|
11
|
+
const token = ctx.tokens[tokenPos];
|
|
12
|
+
if (token?.type !== "BLOCK_OPEN" && token?.type !== "BLOCK_END_OPEN") return false;
|
|
13
|
+
const nameResult = parseBlockName(ctx, tokenPos + 1);
|
|
14
|
+
return nameResult !== null && excluded.has(nameResult.name);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Checks whether the block token at `tokenPos` names a block that no rule recognizes.
|
|
19
|
+
*/
|
|
20
|
+
export function isUnknownBlockToken(ctx: ParseContext, tokenPos: number): boolean {
|
|
21
|
+
const token = ctx.tokens[tokenPos];
|
|
22
|
+
if (token?.type !== "BLOCK_OPEN" && token?.type !== "BLOCK_END_OPEN") return false;
|
|
23
|
+
const nameResult = parseBlockName(ctx, tokenPos + 1);
|
|
24
|
+
if (nameResult === null) {
|
|
25
|
+
if (ctx.tokens[tokenPos + 1]?.type === "EQUALS") {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return !KNOWN_BLOCK_NAMES.has(nameResult.name);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Checks whether the block token at `tokenPos` names a block whose rule accepts indentation.
|
|
35
|
+
*/
|
|
36
|
+
export function isIndentAcceptingBlock(ctx: ParseContext, tokenPos: number): boolean {
|
|
37
|
+
const token = ctx.tokens[tokenPos];
|
|
38
|
+
if (token?.type !== "BLOCK_OPEN" && token?.type !== "BLOCK_END_OPEN") return false;
|
|
39
|
+
const nameResult = parseBlockName(ctx, tokenPos + 1);
|
|
40
|
+
if (nameResult === null) return false;
|
|
41
|
+
return INDENT_ACCEPTING_BLOCK_NAMES.has(nameResult.name);
|
|
42
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { ParseContext } from "../../types";
|
|
2
|
+
import { BLOCK_START_TOKEN_SET } from "../../../constants";
|
|
3
|
+
import {
|
|
4
|
+
isExcludedBlockToken,
|
|
5
|
+
isIndentAcceptingBlock,
|
|
6
|
+
isUnknownBlockToken,
|
|
7
|
+
} from "./block-boundary";
|
|
8
|
+
|
|
9
|
+
export function isParagraphBreakingBlockStart(
|
|
10
|
+
ctx: ParseContext,
|
|
11
|
+
newlinePos: number,
|
|
12
|
+
lookAhead: number,
|
|
13
|
+
): boolean {
|
|
14
|
+
const nextPos = newlinePos + lookAhead;
|
|
15
|
+
const nextMeaningfulToken = ctx.tokens[nextPos];
|
|
16
|
+
if (!nextMeaningfulToken || !BLOCK_START_TOKEN_SET.has(nextMeaningfulToken.type)) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const isIndentedBlockOpener =
|
|
21
|
+
(nextMeaningfulToken.type === "BLOCK_OPEN" || nextMeaningfulToken.type === "BLOCK_END_OPEN") &&
|
|
22
|
+
isIndentAcceptingBlock(ctx, nextPos);
|
|
23
|
+
|
|
24
|
+
if (!nextMeaningfulToken.lineStart && !isIndentedBlockOpener) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
!isOrphanCloseSpan(ctx, nextPos) &&
|
|
30
|
+
!isAnchorName(ctx, nextPos) &&
|
|
31
|
+
!isInvalidBlockOpen(ctx, nextPos) &&
|
|
32
|
+
!isInvalidHeading(ctx, nextPos) &&
|
|
33
|
+
!isExcludedBlockStart(ctx, nextPos) &&
|
|
34
|
+
!isUnknownBlockStart(ctx, nextPos)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isOrphanCloseSpan(ctx: ParseContext, blockEndOpenPos: number): boolean {
|
|
39
|
+
const token = ctx.tokens[blockEndOpenPos];
|
|
40
|
+
if (token?.type !== "BLOCK_END_OPEN") return false;
|
|
41
|
+
|
|
42
|
+
const namePos = skipWhitespace(ctx, blockEndOpenPos + 1);
|
|
43
|
+
const nameToken = ctx.tokens[namePos];
|
|
44
|
+
return nameToken?.type === "IDENTIFIER" && nameToken.value.toLowerCase() === "span";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isAnchorName(ctx: ParseContext, blockOpenPos: number): boolean {
|
|
48
|
+
const token = ctx.tokens[blockOpenPos];
|
|
49
|
+
if (token?.type !== "BLOCK_OPEN") return false;
|
|
50
|
+
|
|
51
|
+
const hashPos = skipWhitespace(ctx, blockOpenPos + 1);
|
|
52
|
+
const hashToken = ctx.tokens[hashPos];
|
|
53
|
+
return hashToken?.type === "HASH" || (hashToken?.type === "TEXT" && hashToken.value === "#");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function isInvalidBlockOpen(ctx: ParseContext, blockOpenPos: number): boolean {
|
|
57
|
+
const token = ctx.tokens[blockOpenPos];
|
|
58
|
+
if (token?.type !== "BLOCK_OPEN") return false;
|
|
59
|
+
|
|
60
|
+
const firstAfter = ctx.tokens[blockOpenPos + 1];
|
|
61
|
+
if (firstAfter?.type === "TEXT" && (firstAfter.value === ">" || firstAfter.value === "<")) {
|
|
62
|
+
const secondAfter = ctx.tokens[blockOpenPos + 2];
|
|
63
|
+
if (secondAfter && secondAfter.type !== "BLOCK_CLOSE") {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const blockNamePos = skipWhitespace(ctx, blockOpenPos + 1);
|
|
69
|
+
const blockNameToken = ctx.tokens[blockNamePos];
|
|
70
|
+
return (
|
|
71
|
+
blockNameToken !== undefined &&
|
|
72
|
+
(blockNameToken.type === "TEXT" || blockNameToken.type === "IDENTIFIER") &&
|
|
73
|
+
blockNameToken.value.toLowerCase() === "footnoteblock" &&
|
|
74
|
+
Boolean(ctx.scope.footnoteBlockParsed)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isInvalidHeading(ctx: ParseContext, markerPos: number): boolean {
|
|
79
|
+
const marker = ctx.tokens[markerPos];
|
|
80
|
+
if (marker?.type !== "HEADING_MARKER") return false;
|
|
81
|
+
|
|
82
|
+
const markerLen = marker.value.length;
|
|
83
|
+
const afterMarker = ctx.tokens[markerPos + 1];
|
|
84
|
+
if (markerLen > 6) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (afterMarker?.type === "STAR") {
|
|
89
|
+
return ctx.tokens[markerPos + 2]?.type !== "WHITESPACE";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return afterMarker?.type !== "WHITESPACE";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function isExcludedBlockStart(ctx: ParseContext, tokenPos: number): boolean {
|
|
96
|
+
const token = ctx.tokens[tokenPos];
|
|
97
|
+
return (
|
|
98
|
+
(token?.type === "BLOCK_OPEN" || token?.type === "BLOCK_END_OPEN") &&
|
|
99
|
+
isExcludedBlockToken(ctx, tokenPos)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isUnknownBlockStart(ctx: ParseContext, tokenPos: number): boolean {
|
|
104
|
+
const token = ctx.tokens[tokenPos];
|
|
105
|
+
return (
|
|
106
|
+
(token?.type === "BLOCK_OPEN" || token?.type === "BLOCK_END_OPEN") &&
|
|
107
|
+
isUnknownBlockToken(ctx, tokenPos)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function skipWhitespace(ctx: ParseContext, startPos: number): number {
|
|
112
|
+
let pos = startPos;
|
|
113
|
+
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
114
|
+
pos++;
|
|
115
|
+
}
|
|
116
|
+
return pos;
|
|
117
|
+
}
|