@wdprlib/parser 3.2.0 → 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 +10451 -8402
- package/dist/index.d.cts +313 -337
- package/dist/index.d.ts +313 -337
- package/dist/index.js +10438 -8389
- 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 +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 +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,239 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Block rule for the Wikidot iframe block: `[[iframe URL attributes]]`.
|
|
4
|
-
*
|
|
5
|
-
* The `[[iframe]]` tag is a self-closing block that embeds an external
|
|
6
|
-
* page in an `<iframe>`. The first argument after the block name is the
|
|
7
|
-
* URL, followed by optional attributes.
|
|
8
|
-
*
|
|
9
|
-
* Security measures:
|
|
10
|
-
* - Only `http://` and `https://` URLs are accepted.
|
|
11
|
-
* - `javascript:`, `data:`, and `vbscript:` schemes are rejected.
|
|
12
|
-
* - URL normalisation strips whitespace and control characters to prevent
|
|
13
|
-
* evasion via character insertion.
|
|
14
|
-
* - Only a specific set of HTML attributes is allowed (Wikidot filters
|
|
15
|
-
* out `id` but permits `class`).
|
|
16
|
-
*
|
|
17
|
-
* Allowed attributes: `align`, `class`, `frameborder`, `height`,
|
|
18
|
-
* `scrolling`, `style`, `width`.
|
|
19
|
-
*
|
|
20
|
-
* @module
|
|
21
|
-
*/
|
|
22
|
-
import type { AttributeMap, Element } from "@wdprlib/ast";
|
|
23
|
-
import type { BlockRule, ParseContext, RuleResult } from "../types";
|
|
24
|
-
import { currentToken } from "../types";
|
|
25
|
-
import { parseBlockName } from "./utils";
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Whitelist of attributes permitted on `[[iframe]]`. Wikidot strips
|
|
29
|
-
* `id` but permits `class`.
|
|
30
|
-
*/
|
|
31
|
-
const ALLOWED_IFRAME_ATTRS = new Set([
|
|
32
|
-
"align",
|
|
33
|
-
"class",
|
|
34
|
-
"frameborder",
|
|
35
|
-
"height",
|
|
36
|
-
"scrolling",
|
|
37
|
-
"style",
|
|
38
|
-
"width",
|
|
39
|
-
]);
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Normalises a URL string for security checks by removing whitespace and
|
|
43
|
-
* control characters (U+0000--U+001F, U+007F--U+009F) that could be used
|
|
44
|
-
* to evade scheme detection, then lowercasing the result.
|
|
45
|
-
*
|
|
46
|
-
* @param url - The raw URL string.
|
|
47
|
-
* @returns The normalised, lowercased URL.
|
|
48
|
-
*/
|
|
49
|
-
function normalizeUrl(url: string): string {
|
|
50
|
-
return url.replace(/[\s\u0000-\u001f\u007f-\u009f]/g, "").toLowerCase();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Tests whether a normalised URL begins with a dangerous scheme
|
|
55
|
-
* (`javascript:`, `data:`, `vbscript:`) that must be rejected.
|
|
56
|
-
*
|
|
57
|
-
* @param normalizedUrl - The URL after {@link normalizeUrl} processing.
|
|
58
|
-
* @returns `true` if the URL has a dangerous scheme.
|
|
59
|
-
*/
|
|
60
|
-
function isDangerousUrl(normalizedUrl: string): boolean {
|
|
61
|
-
return /^(javascript|data|vbscript):/i.test(normalizedUrl);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Block rule for `[[iframe URL ...attributes]]`.
|
|
66
|
-
*
|
|
67
|
-
* Parsing strategy:
|
|
68
|
-
* 1. Match BLOCK_OPEN + name "iframe".
|
|
69
|
-
* 2. Consume the URL (all tokens until whitespace, BLOCK_CLOSE, or newline).
|
|
70
|
-
* 3. Validate the URL: normalise, reject dangerous schemes, require http(s).
|
|
71
|
-
* 4. Parse key/value attributes, filtering through `ALLOWED_IFRAME_ATTRS`.
|
|
72
|
-
* 5. Consume closing `]]` and optional trailing newline.
|
|
73
|
-
* 6. Emit an `iframe` element with `url` and `attributes`.
|
|
74
|
-
*/
|
|
75
|
-
export const iframeRule: BlockRule = {
|
|
76
|
-
name: "iframe",
|
|
77
|
-
startTokens: ["BLOCK_OPEN"],
|
|
78
|
-
requiresLineStart: false,
|
|
79
|
-
|
|
80
|
-
parse(ctx: ParseContext): RuleResult<Element> {
|
|
81
|
-
const openToken = currentToken(ctx);
|
|
82
|
-
if (openToken.type !== "BLOCK_OPEN") {
|
|
83
|
-
return { success: false };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
let pos = ctx.pos + 1;
|
|
87
|
-
let consumed = 1;
|
|
88
|
-
|
|
89
|
-
// Parse block name
|
|
90
|
-
const nameResult = parseBlockName(ctx, pos);
|
|
91
|
-
if (!nameResult || nameResult.name.toLowerCase() !== "iframe") {
|
|
92
|
-
return { success: false };
|
|
93
|
-
}
|
|
94
|
-
pos += nameResult.consumed;
|
|
95
|
-
consumed += nameResult.consumed;
|
|
96
|
-
|
|
97
|
-
// Skip whitespace
|
|
98
|
-
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
99
|
-
pos++;
|
|
100
|
-
consumed++;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Parse URL (first argument)
|
|
104
|
-
let url = "";
|
|
105
|
-
while (pos < ctx.tokens.length) {
|
|
106
|
-
const token = ctx.tokens[pos];
|
|
107
|
-
if (!token) break;
|
|
108
|
-
if (token.type === "BLOCK_CLOSE" || token.type === "WHITESPACE" || token.type === "NEWLINE") {
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
url += token.value;
|
|
112
|
-
pos++;
|
|
113
|
-
consumed++;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (!url) {
|
|
117
|
-
return { success: false };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Normalize URL for consistent security checks
|
|
121
|
-
const normalizedUrl = normalizeUrl(url);
|
|
122
|
-
|
|
123
|
-
// Reject dangerous URLs (javascript:, data:, vbscript:)
|
|
124
|
-
// These will fall back to text rendering
|
|
125
|
-
if (isDangerousUrl(normalizedUrl)) {
|
|
126
|
-
return { success: false };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Only allow http:// and https:// URLs (checked against normalized URL)
|
|
130
|
-
// This blocks relative URLs and other schemes
|
|
131
|
-
if (!/^https?:\/\//i.test(normalizedUrl)) {
|
|
132
|
-
return { success: false };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Parse attributes
|
|
136
|
-
const attributes: AttributeMap = {};
|
|
137
|
-
|
|
138
|
-
while (pos < ctx.tokens.length) {
|
|
139
|
-
const token = ctx.tokens[pos];
|
|
140
|
-
if (!token || token.type === "BLOCK_CLOSE") break;
|
|
141
|
-
|
|
142
|
-
if (token.type === "NEWLINE") {
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (token.type === "WHITESPACE") {
|
|
147
|
-
pos++;
|
|
148
|
-
consumed++;
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Parse key=value or key="value"
|
|
153
|
-
if (token.type === "IDENTIFIER" || token.type === "TEXT") {
|
|
154
|
-
const key = token.value;
|
|
155
|
-
pos++;
|
|
156
|
-
consumed++;
|
|
157
|
-
|
|
158
|
-
// Skip whitespace
|
|
159
|
-
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
160
|
-
pos++;
|
|
161
|
-
consumed++;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Expect =
|
|
165
|
-
if (ctx.tokens[pos]?.type === "EQUALS") {
|
|
166
|
-
pos++;
|
|
167
|
-
consumed++;
|
|
168
|
-
|
|
169
|
-
// Skip whitespace
|
|
170
|
-
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
171
|
-
pos++;
|
|
172
|
-
consumed++;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Parse value
|
|
176
|
-
let value = "";
|
|
177
|
-
const valueToken = ctx.tokens[pos];
|
|
178
|
-
if (valueToken?.type === "QUOTED_STRING") {
|
|
179
|
-
// Remove quotes
|
|
180
|
-
value = valueToken.value.slice(1, -1);
|
|
181
|
-
pos++;
|
|
182
|
-
consumed++;
|
|
183
|
-
} else {
|
|
184
|
-
// Unquoted value
|
|
185
|
-
while (pos < ctx.tokens.length) {
|
|
186
|
-
const vt = ctx.tokens[pos];
|
|
187
|
-
if (
|
|
188
|
-
!vt ||
|
|
189
|
-
vt.type === "BLOCK_CLOSE" ||
|
|
190
|
-
vt.type === "WHITESPACE" ||
|
|
191
|
-
vt.type === "NEWLINE"
|
|
192
|
-
) {
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
value += vt.value;
|
|
196
|
-
pos++;
|
|
197
|
-
consumed++;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Only allow specific attributes (Wikidot filters out class/id)
|
|
202
|
-
if (ALLOWED_IFRAME_ATTRS.has(key.toLowerCase())) {
|
|
203
|
-
attributes[key.toLowerCase()] = value;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
} else {
|
|
207
|
-
pos++;
|
|
208
|
-
consumed++;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Expect ]]
|
|
213
|
-
if (ctx.tokens[pos]?.type !== "BLOCK_CLOSE") {
|
|
214
|
-
return { success: false };
|
|
215
|
-
}
|
|
216
|
-
pos++;
|
|
217
|
-
consumed++;
|
|
218
|
-
|
|
219
|
-
// Skip trailing newline
|
|
220
|
-
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
221
|
-
pos++;
|
|
222
|
-
consumed++;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return {
|
|
226
|
-
success: true,
|
|
227
|
-
elements: [
|
|
228
|
-
{
|
|
229
|
-
element: "iframe",
|
|
230
|
-
data: {
|
|
231
|
-
url,
|
|
232
|
-
attributes,
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
],
|
|
236
|
-
consumed,
|
|
237
|
-
};
|
|
238
|
-
},
|
|
239
|
-
};
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import type { Element, PageRef, VariableMap } from "@wdprlib/ast";
|
|
2
|
-
import type { BlockRule, ParseContext, RuleResult } from "../types";
|
|
3
|
-
import { currentToken } from "../types";
|
|
4
|
-
import { parseBlockName } from "./utils";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Parse page reference from include target
|
|
8
|
-
* Formats:
|
|
9
|
-
* - "page" -> { site: null, page: "page" }
|
|
10
|
-
* - ":site:page" -> { site: "site", page: "page" }
|
|
11
|
-
* - "fragment:name" -> { site: null, page: "fragment:name" }
|
|
12
|
-
*/
|
|
13
|
-
function parsePageRef(target: string): PageRef {
|
|
14
|
-
// Check for :site:page format
|
|
15
|
-
if (target.startsWith(":")) {
|
|
16
|
-
const rest = target.slice(1);
|
|
17
|
-
const colonIndex = rest.indexOf(":");
|
|
18
|
-
if (colonIndex !== -1) {
|
|
19
|
-
return {
|
|
20
|
-
site: rest.slice(0, colonIndex),
|
|
21
|
-
page: rest.slice(colonIndex + 1),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return { site: null, page: target };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Parse variables from include arguments
|
|
30
|
-
* Format: key=value separated by |
|
|
31
|
-
*/
|
|
32
|
-
function parseVariables(tokens: string[]): VariableMap {
|
|
33
|
-
const vars: VariableMap = {};
|
|
34
|
-
|
|
35
|
-
let current = "";
|
|
36
|
-
for (const token of tokens) {
|
|
37
|
-
if (token === "|") {
|
|
38
|
-
if (current.trim()) {
|
|
39
|
-
const eqIndex = current.indexOf("=");
|
|
40
|
-
if (eqIndex !== -1) {
|
|
41
|
-
const key = current.slice(0, eqIndex).trim();
|
|
42
|
-
const value = current.slice(eqIndex + 1).trim();
|
|
43
|
-
if (key) {
|
|
44
|
-
vars[key] = value;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
current = "";
|
|
49
|
-
} else {
|
|
50
|
-
current += token;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Handle last segment
|
|
55
|
-
if (current.trim()) {
|
|
56
|
-
const eqIndex = current.indexOf("=");
|
|
57
|
-
if (eqIndex !== -1) {
|
|
58
|
-
const key = current.slice(0, eqIndex).trim();
|
|
59
|
-
const value = current.slice(eqIndex + 1).trim();
|
|
60
|
-
if (key) {
|
|
61
|
-
vars[key] = value;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return vars;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export const includeRule: BlockRule = {
|
|
70
|
-
name: "include",
|
|
71
|
-
startTokens: ["BLOCK_OPEN"],
|
|
72
|
-
requiresLineStart: false,
|
|
73
|
-
|
|
74
|
-
parse(ctx: ParseContext): RuleResult<Element> {
|
|
75
|
-
const openToken = currentToken(ctx);
|
|
76
|
-
if (openToken.type !== "BLOCK_OPEN") {
|
|
77
|
-
return { success: false };
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let pos = ctx.pos + 1;
|
|
81
|
-
let consumed = 1;
|
|
82
|
-
|
|
83
|
-
// Parse block name
|
|
84
|
-
const nameResult = parseBlockName(ctx, pos);
|
|
85
|
-
if (!nameResult || nameResult.name.toLowerCase() !== "include") {
|
|
86
|
-
return { success: false };
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Page syntax disabled (e.g., forum-post mode)
|
|
90
|
-
if (!ctx.settings.enablePageSyntax) {
|
|
91
|
-
return { success: false };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
pos += nameResult.consumed;
|
|
95
|
-
consumed += nameResult.consumed;
|
|
96
|
-
|
|
97
|
-
// Skip whitespace
|
|
98
|
-
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
99
|
-
pos++;
|
|
100
|
-
consumed++;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Collect target and arguments until ]]
|
|
104
|
-
const argTokens: string[] = [];
|
|
105
|
-
let target = "";
|
|
106
|
-
let inTarget = true;
|
|
107
|
-
|
|
108
|
-
while (pos < ctx.tokens.length) {
|
|
109
|
-
const token = ctx.tokens[pos];
|
|
110
|
-
if (!token) break;
|
|
111
|
-
|
|
112
|
-
if (token.type === "BLOCK_CLOSE") {
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Newlines are allowed in include arguments
|
|
117
|
-
if (token.type === "NEWLINE") {
|
|
118
|
-
pos++;
|
|
119
|
-
consumed++;
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (inTarget) {
|
|
124
|
-
// First non-whitespace segment is the target
|
|
125
|
-
if (token.type === "WHITESPACE") {
|
|
126
|
-
if (target) {
|
|
127
|
-
inTarget = false;
|
|
128
|
-
}
|
|
129
|
-
} else if (token.type === "PIPE") {
|
|
130
|
-
inTarget = false;
|
|
131
|
-
argTokens.push("|");
|
|
132
|
-
} else {
|
|
133
|
-
target += token.value;
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
argTokens.push(token.value);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
pos++;
|
|
140
|
-
consumed++;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Expect ]]
|
|
144
|
-
if (ctx.tokens[pos]?.type !== "BLOCK_CLOSE") {
|
|
145
|
-
return { success: false };
|
|
146
|
-
}
|
|
147
|
-
pos++;
|
|
148
|
-
consumed++;
|
|
149
|
-
|
|
150
|
-
// Skip trailing newline
|
|
151
|
-
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
152
|
-
pos++;
|
|
153
|
-
consumed++;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (!target) {
|
|
157
|
-
return { success: false };
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const location = parsePageRef(target);
|
|
161
|
-
const variables = parseVariables(argTokens);
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
success: true,
|
|
165
|
-
elements: [
|
|
166
|
-
{
|
|
167
|
-
element: "include",
|
|
168
|
-
data: {
|
|
169
|
-
"paragraph-safe": false,
|
|
170
|
-
variables,
|
|
171
|
-
location,
|
|
172
|
-
elements: [],
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
consumed,
|
|
177
|
-
};
|
|
178
|
-
},
|
|
179
|
-
};
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Block rule for Wikidot marker-based lists (`* item`, `# item`).
|
|
4
|
-
*
|
|
5
|
-
* Wikidot lists use leading `*` (bullet) or `#` (numbered) markers at the
|
|
6
|
-
* start of a line. Nesting is achieved by prepending spaces:
|
|
7
|
-
*
|
|
8
|
-
* ```
|
|
9
|
-
* * Item 1
|
|
10
|
-
* * Nested bullet
|
|
11
|
-
* # Nested numbered
|
|
12
|
-
* * Item 2
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* The depth of each item is determined by the number of leading spaces
|
|
16
|
-
* before the marker. Mixed bullet/numbered lists are supported: when the
|
|
17
|
-
* list type changes at the same depth, a new sub-list is created.
|
|
18
|
-
*
|
|
19
|
-
* The flat depth-annotated items are converted into a recursive tree by
|
|
20
|
-
* `processDepths()`, then transformed into nested `list` AST elements
|
|
21
|
-
* by `buildListElement()`.
|
|
22
|
-
*
|
|
23
|
-
* Maximum nesting depth is capped at `MAX_LIST_DEPTH` (20).
|
|
24
|
-
*
|
|
25
|
-
* @module
|
|
26
|
-
*/
|
|
27
|
-
import type { Element, ListData, ListItem, ListType } from "@wdprlib/ast";
|
|
28
|
-
import type { BlockRule, ParseContext, RuleResult } from "../types";
|
|
29
|
-
import { currentToken } from "../types";
|
|
30
|
-
import { parseInlineUntil } from "../inline/utils";
|
|
31
|
-
import { processDepths, type DepthList } from "../../depth";
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Safety limit for list nesting depth.
|
|
35
|
-
* Items deeper than this are not parsed, preventing stack overflow on
|
|
36
|
-
* deeply nested or adversarial input.
|
|
37
|
-
*/
|
|
38
|
-
const MAX_LIST_DEPTH = 20;
|
|
39
|
-
|
|
40
|
-
/** Internal discriminated type for bullet vs numbered items during parsing. */
|
|
41
|
-
type InternalListType = "bullet" | "numbered";
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Default list type used as the top-level placeholder in
|
|
45
|
-
* `processDepths()`. The actual type of each sub-list is determined
|
|
46
|
-
* by its first item's marker.
|
|
47
|
-
*/
|
|
48
|
-
const GENERIC_LIST_TYPE: InternalListType = "bullet";
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Block rule for marker-based lists (`* ` bullet, `# ` numbered).
|
|
52
|
-
*
|
|
53
|
-
* Parsing strategy:
|
|
54
|
-
* 1. Verify the first token is LIST_BULLET or LIST_NUMBER at line start.
|
|
55
|
-
* 2. Collect consecutive list lines, recording each item's depth (number
|
|
56
|
-
* of leading spaces), type (bullet/numbered), and inline content.
|
|
57
|
-
* 3. Feed the flat depth array into `processDepths()` with type
|
|
58
|
-
* comparison, producing a nested tree.
|
|
59
|
-
* 4. Convert the tree into `list` AST elements via `buildListElement()`.
|
|
60
|
-
*/
|
|
61
|
-
export const listRule: BlockRule = {
|
|
62
|
-
name: "list",
|
|
63
|
-
startTokens: ["LIST_BULLET", "LIST_NUMBER"],
|
|
64
|
-
requiresLineStart: true,
|
|
65
|
-
|
|
66
|
-
parse(ctx: ParseContext): RuleResult<Element> {
|
|
67
|
-
const firstToken = currentToken(ctx);
|
|
68
|
-
|
|
69
|
-
if (!firstToken.lineStart) {
|
|
70
|
-
return { success: false };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Wikidot: list must start with list marker directly (no leading whitespace)
|
|
74
|
-
if (firstToken.type !== "LIST_BULLET" && firstToken.type !== "LIST_NUMBER") {
|
|
75
|
-
return { success: false };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Collect depth-annotated items
|
|
79
|
-
const depths: Array<{
|
|
80
|
-
depth: number;
|
|
81
|
-
ltype: InternalListType;
|
|
82
|
-
value: Element[];
|
|
83
|
-
}> = [];
|
|
84
|
-
let pos = ctx.pos;
|
|
85
|
-
let consumed = 0;
|
|
86
|
-
|
|
87
|
-
while (pos < ctx.tokens.length) {
|
|
88
|
-
const token = ctx.tokens[pos];
|
|
89
|
-
|
|
90
|
-
if (!token || !token.lineStart) {
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Determine depth from leading whitespace
|
|
95
|
-
let depth = 0;
|
|
96
|
-
if (token.type === "WHITESPACE") {
|
|
97
|
-
// Count spaces for depth (each space is 1 level)
|
|
98
|
-
depth = token.value.length;
|
|
99
|
-
pos++;
|
|
100
|
-
consumed++;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Check for list marker
|
|
104
|
-
const markerToken = ctx.tokens[pos];
|
|
105
|
-
if (
|
|
106
|
-
!markerToken ||
|
|
107
|
-
(markerToken.type !== "LIST_BULLET" && markerToken.type !== "LIST_NUMBER")
|
|
108
|
-
) {
|
|
109
|
-
// Undo whitespace consumption if not followed by list marker
|
|
110
|
-
if (depth > 0) {
|
|
111
|
-
pos--;
|
|
112
|
-
consumed--;
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Check maximum depth
|
|
118
|
-
if (depth > MAX_LIST_DEPTH) {
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Get list type
|
|
123
|
-
const ltype: InternalListType = markerToken.type === "LIST_BULLET" ? "bullet" : "numbered";
|
|
124
|
-
|
|
125
|
-
// Skip marker
|
|
126
|
-
pos++;
|
|
127
|
-
consumed++;
|
|
128
|
-
|
|
129
|
-
// Expect whitespace after marker
|
|
130
|
-
if (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
131
|
-
pos++;
|
|
132
|
-
consumed++;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Parse inline content until newline
|
|
136
|
-
const inlineCtx: ParseContext = { ...ctx, pos };
|
|
137
|
-
const inlineResult = parseInlineUntil(inlineCtx, "NEWLINE");
|
|
138
|
-
const elements: Element[] = inlineResult.elements;
|
|
139
|
-
consumed += inlineResult.consumed;
|
|
140
|
-
pos += inlineResult.consumed;
|
|
141
|
-
|
|
142
|
-
// Consume newline
|
|
143
|
-
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
144
|
-
pos++;
|
|
145
|
-
consumed++;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Add to depths
|
|
149
|
-
depths.push({
|
|
150
|
-
depth,
|
|
151
|
-
ltype,
|
|
152
|
-
value: elements,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// No items parsed - rule fails
|
|
157
|
-
if (depths.length === 0) {
|
|
158
|
-
return { success: false };
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Process depths with list type comparison
|
|
162
|
-
const depthTrees = processDepths<InternalListType, Element[]>(
|
|
163
|
-
GENERIC_LIST_TYPE,
|
|
164
|
-
depths,
|
|
165
|
-
(a, b) => a === b,
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
// Convert depth trees to list elements
|
|
169
|
-
const lists = depthTrees.map(({ ltype, list }) => buildListElement(ltype, list));
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
success: true,
|
|
173
|
-
elements: lists,
|
|
174
|
-
consumed,
|
|
175
|
-
};
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Converts the internal list type enum to the AST's {@link ListType}.
|
|
181
|
-
*
|
|
182
|
-
* @param ltype - Internal "bullet" or "numbered".
|
|
183
|
-
* @returns The corresponding AST list type.
|
|
184
|
-
*/
|
|
185
|
-
function toListType(ltype: InternalListType): ListType {
|
|
186
|
-
return ltype === "numbered" ? "numbered" : "bullet";
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Builds a `list` AST element from a depth tree produced by
|
|
191
|
-
* `processDepths()`.
|
|
192
|
-
*
|
|
193
|
-
* @param topLtype - The list type for the top-level list.
|
|
194
|
-
* @param list - The depth tree of items and sub-lists.
|
|
195
|
-
* @returns A `list` element.
|
|
196
|
-
*/
|
|
197
|
-
function buildListElement(
|
|
198
|
-
topLtype: InternalListType,
|
|
199
|
-
list: DepthList<InternalListType, Element[]>,
|
|
200
|
-
): Element {
|
|
201
|
-
return {
|
|
202
|
-
element: "list",
|
|
203
|
-
data: buildListData(topLtype, list),
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Recursively builds the {@link ListData} payload from a depth tree.
|
|
209
|
-
*
|
|
210
|
-
* Leaf items become `"elements"` list items; nested sub-trees become
|
|
211
|
-
* `"sub-list"` items with their own recursive {@link ListData}.
|
|
212
|
-
*
|
|
213
|
-
* @param topLtype - List type for this level.
|
|
214
|
-
* @param list - The depth tree nodes at this level.
|
|
215
|
-
* @returns Fully constructed {@link ListData}.
|
|
216
|
-
*/
|
|
217
|
-
function buildListData(
|
|
218
|
-
topLtype: InternalListType,
|
|
219
|
-
list: DepthList<InternalListType, Element[]>,
|
|
220
|
-
): ListData {
|
|
221
|
-
const items: ListItem[] = [];
|
|
222
|
-
|
|
223
|
-
for (const item of list) {
|
|
224
|
-
if (item.kind === "item") {
|
|
225
|
-
items.push({
|
|
226
|
-
"item-type": "elements",
|
|
227
|
-
attributes: {},
|
|
228
|
-
elements: item.value,
|
|
229
|
-
});
|
|
230
|
-
} else {
|
|
231
|
-
items.push({
|
|
232
|
-
"item-type": "sub-list",
|
|
233
|
-
element: "list",
|
|
234
|
-
data: buildListData(item.ltype, item.children),
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return {
|
|
240
|
-
type: toListType(topLtype),
|
|
241
|
-
attributes: {},
|
|
242
|
-
items,
|
|
243
|
-
};
|
|
244
|
-
}
|