@wdprlib/parser 3.2.0 → 4.1.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 +10471 -8406
- package/dist/index.d.cts +313 -337
- package/dist/index.d.ts +313 -337
- package/dist/index.js +10457 -8392
- package/package.json +1 -1
- package/src/index.ts +7 -0
- package/src/lexer/anchor.ts +48 -0
- package/src/lexer/index.ts +3 -2
- package/src/lexer/lexer.ts +73 -559
- 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/parser/constants.ts +2 -0
- package/src/parser/depth/index.ts +111 -0
- package/src/parser/depth/stack.ts +82 -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 +1 -1
- 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/typography.ts +70 -5
- 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.ts → center/index.ts} +7 -22
- package/src/parser/rules/block/center/open.ts +27 -0
- package/src/parser/rules/block/{clear-float.ts → clear-float/index.ts} +6 -30
- 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.ts → comment/index.ts} +12 -38
- package/src/parser/rules/block/{content-separator.ts → content-separator/index.ts} +5 -35
- 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.ts → horizontal-rule/index.ts} +4 -21
- 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.ts → iftags/index.ts} +16 -58
- 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/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/body.ts +92 -0
- package/src/parser/rules/block/module/element.ts +33 -0
- package/src/parser/rules/block/module/include/directive.ts +91 -0
- package/src/parser/rules/block/module/include/index.ts +11 -2
- 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 +14 -2
- package/src/parser/rules/block/module/listpages/compiler.ts +12 -392
- package/src/parser/rules/block/module/listpages/extract.ts +25 -359
- 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/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 +8 -324
- 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 +5 -75
- 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 +30 -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 +62 -0
- package/src/parser/rules/block/module/listpages/url-resolution/value.ts +34 -0
- package/src/parser/rules/block/module/listpages/url-resolver.ts +3 -160
- package/src/parser/rules/block/module/listusers/compiler.ts +4 -25
- package/src/parser/rules/block/module/listusers/extract.ts +4 -9
- package/src/parser/rules/block/module/listusers/getters.ts +21 -0
- package/src/parser/rules/block/module/listusers/variables.ts +15 -0
- package/src/parser/rules/block/module/open.ts +57 -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 +79 -292
- package/src/parser/rules/block/module/rule.ts +56 -0
- package/src/parser/rules/block/module/types-common.ts +11 -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 +10 -610
- package/src/parser/rules/{utils.ts → common/attribute-safety.ts} +3 -49
- 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/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 +2 -39
- 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.ts → comment/index.ts} +10 -36
- 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.ts → guillemet/index.ts} +5 -13
- 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.ts → html/index.ts} +9 -60
- 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/italic.ts +2 -30
- 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 +6 -81
- 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 +7 -98
- package/src/parser/rules/inline/link-star.ts +7 -69
- 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 +2 -30
- 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.ts → strikethrough/index.ts} +5 -60
- 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 +2 -39
- package/src/parser/rules/inline/superscript.ts +4 -39
- package/src/parser/rules/inline/text/element.ts +5 -0
- package/src/parser/rules/inline/{text.ts → text/index.ts} +5 -4
- 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.ts → underline/index.ts} +6 -49
- 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 -344
- package/src/parser/rules/tokens.ts +106 -0
- package/src/parser/rules/types.ts +9 -252
- package/src/parser/depth.ts +0 -251
- package/src/parser/parse.ts +0 -315
- package/src/parser/postprocess/spanStrip.ts +0 -697
- package/src/parser/preprocess/expr.ts +0 -265
- package/src/parser/preprocess/utils.ts +0 -250
- package/src/parser/preprocess/whitespace.ts +0 -111
- package/src/parser/rules/block/align.ts +0 -282
- package/src/parser/rules/block/bibliography.ts +0 -359
- package/src/parser/rules/block/block-list.ts +0 -689
- package/src/parser/rules/block/blockquote.ts +0 -238
- package/src/parser/rules/block/code.ts +0 -187
- package/src/parser/rules/block/collapsible.ts +0 -337
- package/src/parser/rules/block/definition-list.ts +0 -270
- package/src/parser/rules/block/div.ts +0 -400
- package/src/parser/rules/block/embed-block.ts +0 -153
- package/src/parser/rules/block/footnoteblock.ts +0 -200
- package/src/parser/rules/block/heading.ts +0 -142
- package/src/parser/rules/block/html.ts +0 -222
- package/src/parser/rules/block/iframe.ts +0 -239
- package/src/parser/rules/block/include.ts +0 -179
- package/src/parser/rules/block/list.ts +0 -244
- package/src/parser/rules/block/math.ts +0 -183
- package/src/parser/rules/block/module/include/resolve.ts +0 -556
- package/src/parser/rules/block/module/listpages/types.ts +0 -513
- package/src/parser/rules/block/module/walk.ts +0 -380
- package/src/parser/rules/block/module.ts +0 -164
- package/src/parser/rules/block/orphan-li.ts +0 -177
- package/src/parser/rules/block/paragraph.ts +0 -157
- package/src/parser/rules/block/table-block.ts +0 -726
- package/src/parser/rules/block/table.ts +0 -441
- package/src/parser/rules/block/tabview.ts +0 -331
- package/src/parser/rules/block/toc.ts +0 -129
- package/src/parser/rules/inline/anchor-name.ts +0 -154
- package/src/parser/rules/inline/anchor.ts +0 -327
- package/src/parser/rules/inline/bibcite.ts +0 -153
- package/src/parser/rules/inline/color.ts +0 -140
- package/src/parser/rules/inline/equation-ref.ts +0 -115
- package/src/parser/rules/inline/expr.ts +0 -526
- package/src/parser/rules/inline/footnote.ts +0 -223
- package/src/parser/rules/inline/image.ts +0 -328
- package/src/parser/rules/inline/line-break.ts +0 -326
- package/src/parser/rules/inline/link-triple.ts +0 -267
- package/src/parser/rules/inline/math-inline.ts +0 -126
- package/src/parser/rules/inline/raw.ts +0 -262
- package/src/parser/rules/inline/size.ts +0 -244
- package/src/parser/rules/inline/span.ts +0 -424
- package/src/parser/rules/inline/user.ts +0 -147
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Parses the Wikidot inline math syntax: `[[$ LaTeX $]]`.
|
|
4
|
-
*
|
|
5
|
-
* Inline math renders a LaTeX expression inline with the surrounding
|
|
6
|
-
* text (as opposed to the block-level `[[math]]` which produces a
|
|
7
|
-
* display-mode equation).
|
|
8
|
-
*
|
|
9
|
-
* The LaTeX source is captured as-is between the `$` delimiters and
|
|
10
|
-
* stored in the AST for later rendering by a LaTeX engine (e.g. KaTeX
|
|
11
|
-
* or MathJax).
|
|
12
|
-
*
|
|
13
|
-
* Newlines are NOT allowed within inline math; if a `NEWLINE` token is
|
|
14
|
-
* encountered before the closing `$]]`, the parse fails.
|
|
15
|
-
*
|
|
16
|
-
* Wikidot syntax: `[[$ E = mc^2 $]]`
|
|
17
|
-
*
|
|
18
|
-
* Produces a `"math-inline"` AST element with `data["latex-source"]`
|
|
19
|
-
* containing the trimmed LaTeX string.
|
|
20
|
-
*
|
|
21
|
-
* @module
|
|
22
|
-
*/
|
|
23
|
-
import type { Element } from "@wdprlib/ast";
|
|
24
|
-
import type { InlineRule, ParseContext, RuleResult } from "../types";
|
|
25
|
-
import { currentToken } from "../types";
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Inline rule for parsing `[[$ LaTeX $]]` inline math.
|
|
29
|
-
*
|
|
30
|
-
* Triggered by a `BLOCK_OPEN` (`[[`) token. Looks for a `$` text
|
|
31
|
-
* token immediately after, collects the LaTeX source until the closing
|
|
32
|
-
* `$]]` sequence, and produces a math-inline element.
|
|
33
|
-
*
|
|
34
|
-
* Fails if:
|
|
35
|
-
* - No `$` follows the `[[`
|
|
36
|
-
* - A newline is encountered within the LaTeX source
|
|
37
|
-
* - The closing `$]]` sequence is not found
|
|
38
|
-
*/
|
|
39
|
-
export const mathInlineRule: InlineRule = {
|
|
40
|
-
name: "math-inline",
|
|
41
|
-
startTokens: ["BLOCK_OPEN"],
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Attempts to parse inline math at the current position.
|
|
45
|
-
*
|
|
46
|
-
* @param ctx - Parse context with token stream and current position
|
|
47
|
-
* @returns A successful result with a `"math-inline"` element, or `{ success: false }`
|
|
48
|
-
*/
|
|
49
|
-
parse(ctx: ParseContext): RuleResult<Element> {
|
|
50
|
-
const openToken = currentToken(ctx);
|
|
51
|
-
if (openToken.type !== "BLOCK_OPEN") {
|
|
52
|
-
return { success: false };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let pos = ctx.pos + 1;
|
|
56
|
-
let consumed = 1;
|
|
57
|
-
|
|
58
|
-
// Expect $
|
|
59
|
-
if (ctx.tokens[pos]?.type !== "TEXT" || ctx.tokens[pos]?.value !== "$") {
|
|
60
|
-
return { success: false };
|
|
61
|
-
}
|
|
62
|
-
pos++;
|
|
63
|
-
consumed++;
|
|
64
|
-
|
|
65
|
-
// Skip whitespace
|
|
66
|
-
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
67
|
-
pos++;
|
|
68
|
-
consumed++;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Collect LaTeX content until $]]
|
|
72
|
-
let latexSource = "";
|
|
73
|
-
|
|
74
|
-
while (pos < ctx.tokens.length) {
|
|
75
|
-
const token = ctx.tokens[pos];
|
|
76
|
-
if (!token) break;
|
|
77
|
-
|
|
78
|
-
// No newlines allowed in inline math
|
|
79
|
-
if (token.type === "NEWLINE") {
|
|
80
|
-
return { success: false };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Check for closing $]]
|
|
84
|
-
if (
|
|
85
|
-
token.type === "TEXT" &&
|
|
86
|
-
token.value === "$" &&
|
|
87
|
-
ctx.tokens[pos + 1]?.type === "BLOCK_CLOSE"
|
|
88
|
-
) {
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
latexSource += token.value;
|
|
93
|
-
pos++;
|
|
94
|
-
consumed++;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Expect $]]
|
|
98
|
-
if (ctx.tokens[pos]?.type !== "TEXT" || ctx.tokens[pos]?.value !== "$") {
|
|
99
|
-
return { success: false };
|
|
100
|
-
}
|
|
101
|
-
pos++;
|
|
102
|
-
consumed++;
|
|
103
|
-
|
|
104
|
-
if (ctx.tokens[pos]?.type !== "BLOCK_CLOSE") {
|
|
105
|
-
return { success: false };
|
|
106
|
-
}
|
|
107
|
-
pos++;
|
|
108
|
-
consumed++;
|
|
109
|
-
|
|
110
|
-
// Trim the LaTeX source
|
|
111
|
-
latexSource = latexSource.trim();
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
success: true,
|
|
115
|
-
elements: [
|
|
116
|
-
{
|
|
117
|
-
element: "math-inline",
|
|
118
|
-
data: {
|
|
119
|
-
"latex-source": latexSource,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
consumed,
|
|
124
|
-
};
|
|
125
|
-
},
|
|
126
|
-
};
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Parses the Wikidot raw (verbatim) text syntaxes: `@@...@@` and `@<...>@`.
|
|
4
|
-
*
|
|
5
|
-
* Raw text bypasses all inline formatting -- the content between the
|
|
6
|
-
* delimiters is emitted as-is without interpretation of any Wikidot
|
|
7
|
-
* markup characters.
|
|
8
|
-
*
|
|
9
|
-
* Two syntax variants are supported:
|
|
10
|
-
*
|
|
11
|
-
* 1. Double-at syntax (`@@...@@`): The more common form. Content between
|
|
12
|
-
* the markers is treated as raw text. Several Wikidot quirks apply:
|
|
13
|
-
* - Empty raw (`@@@@` = two consecutive `RAW_OPEN` tokens) produces
|
|
14
|
-
* no output
|
|
15
|
-
* - `@@\n@@` (raw spanning a newline with no content) also produces
|
|
16
|
-
* no output
|
|
17
|
-
* - Content containing both `@<` and `>@` is discarded entirely
|
|
18
|
-
* - `>@` followed immediately by `@@` is split: `>` becomes raw
|
|
19
|
-
* content, `@@` acts as the closer, and the leftover `@` becomes text
|
|
20
|
-
*
|
|
21
|
-
* 2. Angle-bracket syntax (`@<...>@`): A less common form that also
|
|
22
|
-
* treats content as raw text. If the closing `>@` is not found on the
|
|
23
|
-
* same line, `@<` is treated as literal text. The `@<\n>@` spanning
|
|
24
|
-
* pattern outputs only `@<` as text.
|
|
25
|
-
*
|
|
26
|
-
* Produces a `"raw"` AST element whose `data` field contains the
|
|
27
|
-
* verbatim text string, or empty elements when the raw content is discarded.
|
|
28
|
-
*
|
|
29
|
-
* @module
|
|
30
|
-
*/
|
|
31
|
-
import type { Element } from "@wdprlib/ast";
|
|
32
|
-
import type { InlineRule, ParseContext, RuleResult } from "../types";
|
|
33
|
-
import { currentToken, hasClosingMarkerBeforeNewline } from "../types";
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Inline rule for parsing `@@...@@` and `@<...>@` raw (verbatim) text.
|
|
37
|
-
*
|
|
38
|
-
* Triggered by either `RAW_OPEN` (`@@`) or `RAW_BLOCK_OPEN` (`@<`) tokens.
|
|
39
|
-
* Delegates to the appropriate handler based on the opening token type.
|
|
40
|
-
*/
|
|
41
|
-
export const rawRule: InlineRule = {
|
|
42
|
-
name: "raw",
|
|
43
|
-
startTokens: ["RAW_OPEN", "RAW_BLOCK_OPEN"],
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Attempts to parse raw text at the current position.
|
|
47
|
-
*
|
|
48
|
-
* @param ctx - Parse context with token stream and current position
|
|
49
|
-
* @returns A successful result with `"raw"` element(s), text fallback,
|
|
50
|
-
* or empty elements depending on the variant and content
|
|
51
|
-
*/
|
|
52
|
-
parse(ctx: ParseContext): RuleResult<Element> {
|
|
53
|
-
const startToken = currentToken(ctx);
|
|
54
|
-
|
|
55
|
-
// Handle @<...>@ syntax
|
|
56
|
-
if (startToken.type === "RAW_BLOCK_OPEN") {
|
|
57
|
-
return parseAngleRaw(ctx);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Handle @@...@@ syntax
|
|
61
|
-
return parseDoubleAtRaw(ctx);
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Parses the `@@...@@` double-at raw text syntax.
|
|
67
|
-
*
|
|
68
|
-
* Handles several Wikidot-specific edge cases:
|
|
69
|
-
* - Consecutive `@@@@` (two RAW_OPEN tokens) = empty raw, no output
|
|
70
|
-
* - `@@\n@@` = empty raw spanning newline, no output
|
|
71
|
-
* - Content with both `@<` and `>@` embedded = entirely discarded
|
|
72
|
-
* - `>@` immediately before `@@` = split into raw content + text
|
|
73
|
-
*
|
|
74
|
-
* When no closing `@@` is found on the same line, the opening `@@`
|
|
75
|
-
* is emitted as literal text.
|
|
76
|
-
*
|
|
77
|
-
* @param ctx - Parse context positioned at the opening `@@` token
|
|
78
|
-
* @returns Parse result with raw element(s), empty array, or text fallback
|
|
79
|
-
*/
|
|
80
|
-
function parseDoubleAtRaw(ctx: ParseContext): RuleResult<Element> {
|
|
81
|
-
const startToken = currentToken(ctx);
|
|
82
|
-
let pos = ctx.pos + 1;
|
|
83
|
-
|
|
84
|
-
const next1 = ctx.tokens[pos];
|
|
85
|
-
|
|
86
|
-
// Wikidot behavior for consecutive @@:
|
|
87
|
-
// @@@@ (RAW_OPEN RAW_OPEN) -> empty raw (no output), rest becomes plain text
|
|
88
|
-
// @@@@@ (5 @s) -> empty raw + @ (text)
|
|
89
|
-
// @@@@@@ (6 @s) -> empty raw + @@ (text)
|
|
90
|
-
// Empty raw produces no output, so we just consume the tokens.
|
|
91
|
-
if (next1?.type === "RAW_OPEN") {
|
|
92
|
-
return {
|
|
93
|
-
success: true,
|
|
94
|
-
elements: [], // Empty raw produces no output
|
|
95
|
-
consumed: 2, // Only consume the two RAW_OPEN tokens (@@@@)
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Check if closing @@ exists before newline
|
|
100
|
-
if (!hasClosingMarkerBeforeNewline({ ...ctx, pos }, "RAW_OPEN")) {
|
|
101
|
-
// Special case: @@\n@@ (empty raw spanning newline)
|
|
102
|
-
// Wikidot treats this as an empty raw that produces no output
|
|
103
|
-
const nextToken = ctx.tokens[pos];
|
|
104
|
-
if (nextToken?.type === "NEWLINE") {
|
|
105
|
-
const afterNewline = ctx.tokens[pos + 1];
|
|
106
|
-
if (afterNewline?.type === "RAW_OPEN") {
|
|
107
|
-
// Consume @@, NEWLINE, @@ and produce no output
|
|
108
|
-
return {
|
|
109
|
-
success: true,
|
|
110
|
-
elements: [],
|
|
111
|
-
consumed: 3, // @@ + NEWLINE + @@
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
success: true,
|
|
117
|
-
elements: [{ element: "text", data: startToken.value }],
|
|
118
|
-
consumed: 1,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Collect raw content and check for embedded @< and >@
|
|
123
|
-
let value = "";
|
|
124
|
-
let consumed = 1; // opening @@
|
|
125
|
-
let hasBlockOpen = false; // has @<
|
|
126
|
-
let hasBlockClose = false; // has >@
|
|
127
|
-
|
|
128
|
-
// In @@...@@ syntax, only RAW_OPEN (@@) acts as closer.
|
|
129
|
-
// Special handling for RAW_BLOCK_CLOSE (>@) followed by RAW_OPEN (@@):
|
|
130
|
-
// Wikidot treats ">@@@" as ">@@" + "@", so we only take ">" and let the
|
|
131
|
-
// @ combine with the following @@ to form the closer.
|
|
132
|
-
while (pos < ctx.tokens.length) {
|
|
133
|
-
const token = ctx.tokens[pos];
|
|
134
|
-
if (!token || token.type === "RAW_OPEN" || token.type === "NEWLINE" || token.type === "EOF") {
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
// Check if RAW_BLOCK_CLOSE (>@) is followed by RAW_OPEN (@@)
|
|
138
|
-
// Wikidot interprets ">@@@" as ">" (raw content) + "@@" (closer) + "@" (text)
|
|
139
|
-
// We need to only take ">" and output "@" as trailing text after the raw element
|
|
140
|
-
if (token.type === "RAW_BLOCK_CLOSE") {
|
|
141
|
-
const nextToken = ctx.tokens[pos + 1];
|
|
142
|
-
if (nextToken?.type === "RAW_OPEN") {
|
|
143
|
-
// Only take the ">" part
|
|
144
|
-
value += ">";
|
|
145
|
-
consumed += 2; // Consume both RAW_BLOCK_CLOSE and RAW_OPEN (as closer)
|
|
146
|
-
// Return raw element followed by "@" text (from the >@ token's @)
|
|
147
|
-
return {
|
|
148
|
-
success: true,
|
|
149
|
-
elements: [
|
|
150
|
-
{ element: "raw", data: value },
|
|
151
|
-
{ element: "text", data: "@" },
|
|
152
|
-
],
|
|
153
|
-
consumed,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
// Mark that we have embedded >@ (not followed by @@)
|
|
157
|
-
hasBlockClose = true;
|
|
158
|
-
}
|
|
159
|
-
// Track embedded @< token
|
|
160
|
-
if (token.type === "RAW_BLOCK_OPEN") {
|
|
161
|
-
hasBlockOpen = true;
|
|
162
|
-
}
|
|
163
|
-
value += token.value;
|
|
164
|
-
consumed++;
|
|
165
|
-
pos++;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Consume closing @@
|
|
169
|
-
if (ctx.tokens[pos]?.type === "RAW_OPEN") {
|
|
170
|
-
consumed++;
|
|
171
|
-
pos++;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Wikidot quirk: @@...@@ containing BOTH @< AND >@ is discarded entirely
|
|
175
|
-
// (produces no output, not even text fallback)
|
|
176
|
-
// Having only @< or only >@ is fine - they're treated as raw content.
|
|
177
|
-
if (hasBlockOpen && hasBlockClose) {
|
|
178
|
-
return {
|
|
179
|
-
success: true,
|
|
180
|
-
elements: [],
|
|
181
|
-
consumed,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
success: true,
|
|
187
|
-
elements: [{ element: "raw", data: value }],
|
|
188
|
-
consumed,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Parses the `@<...>@` angle-bracket raw text syntax.
|
|
194
|
-
*
|
|
195
|
-
* This is the less common raw text form. Content between `@<` and `>@`
|
|
196
|
-
* is treated as verbatim text.
|
|
197
|
-
*
|
|
198
|
-
* Edge cases:
|
|
199
|
-
* - `@<\n>@` (spanning a newline) outputs only `@<` as text and
|
|
200
|
-
* consumes all three tokens
|
|
201
|
-
* - No closing `>@` on the same line = `@<` emitted as literal text
|
|
202
|
-
*
|
|
203
|
-
* @param ctx - Parse context positioned at the opening `@<` token
|
|
204
|
-
* @returns Parse result with a raw element or text fallback
|
|
205
|
-
*/
|
|
206
|
-
function parseAngleRaw(ctx: ParseContext): RuleResult<Element> {
|
|
207
|
-
const startToken = currentToken(ctx);
|
|
208
|
-
let pos = ctx.pos + 1;
|
|
209
|
-
|
|
210
|
-
// Check if closing >@ exists before newline
|
|
211
|
-
if (!hasClosingMarkerBeforeNewline({ ...ctx, pos }, "RAW_BLOCK_CLOSE")) {
|
|
212
|
-
// Special case: @<\n>@ (empty raw spanning newline)
|
|
213
|
-
// Wikidot treats @< as text and >@ disappears
|
|
214
|
-
const nextToken = ctx.tokens[pos];
|
|
215
|
-
if (nextToken?.type === "NEWLINE") {
|
|
216
|
-
const afterNewline = ctx.tokens[pos + 1];
|
|
217
|
-
if (afterNewline?.type === "RAW_BLOCK_CLOSE") {
|
|
218
|
-
// Consume @<, NEWLINE, >@ - output only @< as text
|
|
219
|
-
return {
|
|
220
|
-
success: true,
|
|
221
|
-
elements: [{ element: "text", data: startToken.value }],
|
|
222
|
-
consumed: 3, // @< + NEWLINE + >@
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return {
|
|
227
|
-
success: true,
|
|
228
|
-
elements: [{ element: "text", data: startToken.value }],
|
|
229
|
-
consumed: 1,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Collect raw content
|
|
234
|
-
let value = "";
|
|
235
|
-
let consumed = 1; // opening @<
|
|
236
|
-
|
|
237
|
-
while (pos < ctx.tokens.length) {
|
|
238
|
-
const token = ctx.tokens[pos];
|
|
239
|
-
if (
|
|
240
|
-
!token ||
|
|
241
|
-
token.type === "RAW_BLOCK_CLOSE" ||
|
|
242
|
-
token.type === "NEWLINE" ||
|
|
243
|
-
token.type === "EOF"
|
|
244
|
-
) {
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
value += token.value;
|
|
248
|
-
consumed++;
|
|
249
|
-
pos++;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// Consume closing >@
|
|
253
|
-
if (ctx.tokens[pos]?.type === "RAW_BLOCK_CLOSE") {
|
|
254
|
-
consumed++;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return {
|
|
258
|
-
success: true,
|
|
259
|
-
elements: [{ element: "raw", data: value }],
|
|
260
|
-
consumed,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Parses the Wikidot font size syntax: `[[size value]]text[[/size]]`.
|
|
4
|
-
*
|
|
5
|
-
* This syntax wraps inline content in a `<span>` with an explicit
|
|
6
|
-
* `font-size` CSS style. The size value must include a number and
|
|
7
|
-
* a supported CSS unit.
|
|
8
|
-
*
|
|
9
|
-
* Supported units (matching Wikidot's implementation):
|
|
10
|
-
* `px`, `em`, `rem`, `ex`, `%`, `cm`, `mm`, `in`, `pc`
|
|
11
|
-
*
|
|
12
|
-
* Notably, `pt`, `vh`, `vw`, and other modern CSS units are NOT
|
|
13
|
-
* supported and will cause the parse to fail.
|
|
14
|
-
*
|
|
15
|
-
* Wikidot syntax examples:
|
|
16
|
-
* - `[[size 120%]]larger text[[/size]]`
|
|
17
|
-
* - `[[size 0.8em]]smaller text[[/size]]`
|
|
18
|
-
* - `[[size 24px]]fixed size[[/size]]`
|
|
19
|
-
*
|
|
20
|
-
* Produces a `"container"` AST element with `type: "size"` and a
|
|
21
|
-
* `style` attribute containing the `font-size` declaration.
|
|
22
|
-
*
|
|
23
|
-
* @module
|
|
24
|
-
*/
|
|
25
|
-
import type { Element } from "@wdprlib/ast";
|
|
26
|
-
import type { InlineRule, ParseContext, RuleResult } from "../types";
|
|
27
|
-
import { currentToken } from "../types";
|
|
28
|
-
import { parseBlockName } from "../utils";
|
|
29
|
-
import { parseInlineUntil } from "./utils";
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* CSS size units that Wikidot recognizes in `[[size]]` blocks.
|
|
33
|
-
* Other valid CSS units (like `pt`, `vh`, `vw`) are deliberately
|
|
34
|
-
* excluded to match original Wikidot behavior.
|
|
35
|
-
*/
|
|
36
|
-
const VALID_SIZE_UNITS = ["px", "em", "rem", "ex", "%", "cm", "mm", "in", "pc"];
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Validates a size string against Wikidot-supported CSS units.
|
|
40
|
-
*
|
|
41
|
-
* The value must match the pattern `<number><unit>`, where the number
|
|
42
|
-
* can be an integer or decimal and the unit must be one of the
|
|
43
|
-
* {@link VALID_SIZE_UNITS}.
|
|
44
|
-
*
|
|
45
|
-
* @param size - The size string to validate (e.g. `"120%"`, `"1.5em"`)
|
|
46
|
-
* @returns `true` if the size value is valid
|
|
47
|
-
*/
|
|
48
|
-
function isValidSizeValue(size: string): boolean {
|
|
49
|
-
// Match number + unit pattern
|
|
50
|
-
const unitPattern = VALID_SIZE_UNITS.join("|");
|
|
51
|
-
const match = size.match(new RegExp(`^(\\d+(?:\\.\\d+)?)(${unitPattern})$`, "i"));
|
|
52
|
-
return match !== null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Extracts and validates a size value from the token stream.
|
|
57
|
-
*
|
|
58
|
-
* Skips leading whitespace, then collects consecutive non-whitespace,
|
|
59
|
-
* non-delimiter tokens and joins them into a size string. The resulting
|
|
60
|
-
* string is validated against {@link isValidSizeValue}.
|
|
61
|
-
*
|
|
62
|
-
* @param ctx - The current parse context
|
|
63
|
-
* @param startPos - Token index at which to begin scanning
|
|
64
|
-
* @returns An object with the validated size string and tokens consumed,
|
|
65
|
-
* or `null` if no valid size value was found
|
|
66
|
-
*/
|
|
67
|
-
function parseSizeValue(
|
|
68
|
-
ctx: ParseContext,
|
|
69
|
-
startPos: number,
|
|
70
|
-
): { size: string; consumed: number } | null {
|
|
71
|
-
let pos = startPos;
|
|
72
|
-
let consumed = 0;
|
|
73
|
-
|
|
74
|
-
// Skip whitespace
|
|
75
|
-
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
76
|
-
pos++;
|
|
77
|
-
consumed++;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Collect size value tokens until ]]
|
|
81
|
-
const parts: string[] = [];
|
|
82
|
-
while (pos < ctx.tokens.length) {
|
|
83
|
-
const token = ctx.tokens[pos];
|
|
84
|
-
if (
|
|
85
|
-
!token ||
|
|
86
|
-
token.type === "BLOCK_CLOSE" ||
|
|
87
|
-
token.type === "NEWLINE" ||
|
|
88
|
-
token.type === "EOF"
|
|
89
|
-
) {
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
if (token.type === "WHITESPACE") {
|
|
93
|
-
break; // Size value shouldn't have spaces
|
|
94
|
-
}
|
|
95
|
-
parts.push(token.value);
|
|
96
|
-
pos++;
|
|
97
|
-
consumed++;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (parts.length === 0) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const size = parts.join("");
|
|
105
|
-
|
|
106
|
-
// Validate against supported units
|
|
107
|
-
if (!isValidSizeValue(size)) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return { size, consumed };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Inline rule for parsing `[[size value]]text[[/size]]`.
|
|
116
|
-
*
|
|
117
|
-
* Triggered by a `BLOCK_OPEN` (`[[`) token. Verifies the block name
|
|
118
|
-
* is `size`, parses and validates the size value, then recursively
|
|
119
|
-
* parses inline content until the matching `[[/size]]` closing tag.
|
|
120
|
-
*
|
|
121
|
-
* Fails if:
|
|
122
|
-
* - The block name is not `size`
|
|
123
|
-
* - The size value is missing or uses an unsupported unit
|
|
124
|
-
* - No closing `]]` after the size value
|
|
125
|
-
*/
|
|
126
|
-
export const sizeRule: InlineRule = {
|
|
127
|
-
name: "size",
|
|
128
|
-
startTokens: ["BLOCK_OPEN"],
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Attempts to parse a size block at the current position.
|
|
132
|
-
*
|
|
133
|
-
* @param ctx - Parse context with token stream and current position
|
|
134
|
-
* @returns A successful result with a `"container"` element of type `"size"`,
|
|
135
|
-
* or `{ success: false }`
|
|
136
|
-
*/
|
|
137
|
-
parse(ctx: ParseContext): RuleResult<Element> {
|
|
138
|
-
const openToken = currentToken(ctx);
|
|
139
|
-
if (openToken.type !== "BLOCK_OPEN") {
|
|
140
|
-
return { success: false };
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
let pos = ctx.pos + 1;
|
|
144
|
-
let consumed = 1;
|
|
145
|
-
|
|
146
|
-
// Parse block name
|
|
147
|
-
const nameResult = parseBlockName(ctx, pos);
|
|
148
|
-
if (!nameResult) {
|
|
149
|
-
return { success: false };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const blockName = nameResult.name;
|
|
153
|
-
if (blockName !== "size") {
|
|
154
|
-
return { success: false };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
pos += nameResult.consumed;
|
|
158
|
-
consumed += nameResult.consumed;
|
|
159
|
-
|
|
160
|
-
// Parse size value
|
|
161
|
-
const sizeResult = parseSizeValue(ctx, pos);
|
|
162
|
-
if (!sizeResult) {
|
|
163
|
-
return { success: false };
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
pos += sizeResult.consumed;
|
|
167
|
-
consumed += sizeResult.consumed;
|
|
168
|
-
|
|
169
|
-
// Expect ]]
|
|
170
|
-
if (ctx.tokens[pos]?.type !== "BLOCK_CLOSE") {
|
|
171
|
-
return { success: false };
|
|
172
|
-
}
|
|
173
|
-
pos++;
|
|
174
|
-
consumed++;
|
|
175
|
-
|
|
176
|
-
// Parse inline content until [[/size]]
|
|
177
|
-
const children: Element[] = [];
|
|
178
|
-
let foundClose = false;
|
|
179
|
-
|
|
180
|
-
while (pos < ctx.tokens.length) {
|
|
181
|
-
const token = ctx.tokens[pos];
|
|
182
|
-
if (!token || token.type === "EOF") {
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Check for [[/size]]
|
|
187
|
-
if (token.type === "BLOCK_END_OPEN") {
|
|
188
|
-
const closeNameResult = parseBlockName(ctx, pos + 1);
|
|
189
|
-
if (closeNameResult && closeNameResult.name === "size") {
|
|
190
|
-
foundClose = true;
|
|
191
|
-
// Skip [[/size]]
|
|
192
|
-
pos++; // [[/
|
|
193
|
-
consumed++;
|
|
194
|
-
pos += closeNameResult.consumed; // size
|
|
195
|
-
consumed += closeNameResult.consumed;
|
|
196
|
-
// Skip ]]
|
|
197
|
-
if (ctx.tokens[pos]?.type === "BLOCK_CLOSE") {
|
|
198
|
-
pos++;
|
|
199
|
-
consumed++;
|
|
200
|
-
}
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Parse inline content
|
|
206
|
-
const inlineCtx: ParseContext = { ...ctx, pos };
|
|
207
|
-
const inlineResult = parseInlineUntil(inlineCtx, "BLOCK_END_OPEN");
|
|
208
|
-
if (inlineResult.elements.length > 0) {
|
|
209
|
-
children.push(...inlineResult.elements);
|
|
210
|
-
pos += inlineResult.consumed;
|
|
211
|
-
consumed += inlineResult.consumed;
|
|
212
|
-
} else {
|
|
213
|
-
// Fallback: just add as text
|
|
214
|
-
children.push({ element: "text", data: token.value });
|
|
215
|
-
pos++;
|
|
216
|
-
consumed++;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (!foundClose) {
|
|
221
|
-
ctx.diagnostics.push({
|
|
222
|
-
severity: "warning",
|
|
223
|
-
code: "unclosed-block",
|
|
224
|
-
message: "Missing closing tag [[/size]] for [[size]]",
|
|
225
|
-
position: openToken.position,
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return {
|
|
230
|
-
success: true,
|
|
231
|
-
elements: [
|
|
232
|
-
{
|
|
233
|
-
element: "container",
|
|
234
|
-
data: {
|
|
235
|
-
type: "size",
|
|
236
|
-
attributes: { style: `font-size:${sizeResult.size};` },
|
|
237
|
-
elements: children,
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
],
|
|
241
|
-
consumed,
|
|
242
|
-
};
|
|
243
|
-
},
|
|
244
|
-
};
|