@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,400 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Block rule for Wikidot `[[div]]` and `[[div_]]` container blocks.
|
|
4
|
-
*
|
|
5
|
-
* `[[div]]` wraps its body content in a `<div>` element, with full
|
|
6
|
-
* paragraph processing for the body. `[[div_]]` (paragraph strip mode)
|
|
7
|
-
* unwraps the first and last paragraphs so their content appears directly
|
|
8
|
-
* inside the `<div>`, while middle paragraphs keep their `<p>` wrappers.
|
|
9
|
-
*
|
|
10
|
-
* Both variants accept HTML attributes (class, style, id, etc.) on the
|
|
11
|
-
* opening tag.
|
|
12
|
-
*
|
|
13
|
-
* Wikidot-specific edge cases:
|
|
14
|
-
* - The opening `]]` MUST be followed by a NEWLINE for the block to be
|
|
15
|
-
* recognised. `[[div]]inline[[/div]]` is NOT a valid div -- it becomes
|
|
16
|
-
* a failed div (see `consumeFailedDiv()`).
|
|
17
|
-
* - When a div fails, everything from the opening `[[div]]` through the
|
|
18
|
-
* last `[[/div]]` is collected as a single paragraph of text/line-break
|
|
19
|
-
* elements. Blank lines within that span are silently removed.
|
|
20
|
-
* - `[[div_]]` uses `unwrapEdgeParagraphs()` to strip paragraph
|
|
21
|
-
* wrappers from the first and last elements.
|
|
22
|
-
*
|
|
23
|
-
* @module
|
|
24
|
-
*/
|
|
25
|
-
import type { Element } from "@wdprlib/ast";
|
|
26
|
-
import type { BlockRule, ParseContext, RuleResult } from "../types";
|
|
27
|
-
import { currentToken } from "../types";
|
|
28
|
-
import { parseBlockName, parseAttributes, parseBlocksUntil } from "./utils";
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Block rule for `[[div]]`/`[[div_]]` container blocks.
|
|
32
|
-
*
|
|
33
|
-
* `requiresLineStart` is `false` because nested `[[div_]]` inside another
|
|
34
|
-
* `[[div_]]` may appear after inline content.
|
|
35
|
-
*/
|
|
36
|
-
export const divRule: BlockRule = {
|
|
37
|
-
name: "div",
|
|
38
|
-
startTokens: ["BLOCK_OPEN"],
|
|
39
|
-
requiresLineStart: false, // Allow nested [[div_]] inside [[div_]]
|
|
40
|
-
|
|
41
|
-
parse(ctx: ParseContext): RuleResult<Element> {
|
|
42
|
-
const openToken = currentToken(ctx);
|
|
43
|
-
if (openToken.type !== "BLOCK_OPEN") {
|
|
44
|
-
return { success: false };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
let pos = ctx.pos + 1;
|
|
48
|
-
let consumed = 1;
|
|
49
|
-
|
|
50
|
-
// Parse block name
|
|
51
|
-
const nameResult = parseBlockName(ctx, pos);
|
|
52
|
-
if (!nameResult) {
|
|
53
|
-
return { success: false };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const blockName = nameResult.name;
|
|
57
|
-
// Check if it's a div or div_
|
|
58
|
-
if (blockName !== "div" && blockName !== "div_") {
|
|
59
|
-
return { success: false };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// div_ means paragraph strip (no paragraph wrapping)
|
|
63
|
-
const paragraphStrip = blockName === "div_";
|
|
64
|
-
|
|
65
|
-
pos += nameResult.consumed;
|
|
66
|
-
consumed += nameResult.consumed;
|
|
67
|
-
|
|
68
|
-
// Parse attributes
|
|
69
|
-
const attrResult = parseAttributes(ctx, pos);
|
|
70
|
-
pos += attrResult.consumed;
|
|
71
|
-
consumed += attrResult.consumed;
|
|
72
|
-
|
|
73
|
-
// Expect ]]
|
|
74
|
-
if (ctx.tokens[pos]?.type !== "BLOCK_CLOSE") {
|
|
75
|
-
return { success: false };
|
|
76
|
-
}
|
|
77
|
-
pos++;
|
|
78
|
-
consumed++;
|
|
79
|
-
|
|
80
|
-
// Wikidot: [[div]] must be followed by newline to be recognized as block
|
|
81
|
-
// [[div]]inline[[/div]] is NOT recognized as div
|
|
82
|
-
// When this fails, Wikidot consumes everything up to the last [[/div]]
|
|
83
|
-
// as text in a single paragraph (blank lines are ignored)
|
|
84
|
-
if (ctx.tokens[pos]?.type !== "NEWLINE") {
|
|
85
|
-
return consumeFailedDiv(ctx);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Wikidot matches [[div]]/[[/div]] pairs from outside-in. When there are
|
|
89
|
-
// more opens than closes, the innermost excess opens become text. We enforce
|
|
90
|
-
// this with a "closes budget": the number of additional nested divs that can
|
|
91
|
-
// open. When budget reaches 0, this div cannot open.
|
|
92
|
-
if (ctx.scope.divClosesBudget === 0) {
|
|
93
|
-
return { success: false };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
pos++;
|
|
97
|
-
consumed++;
|
|
98
|
-
|
|
99
|
-
// Record opening tag position for diagnostics
|
|
100
|
-
const openPosition = openToken.position;
|
|
101
|
-
|
|
102
|
-
// Calculate closes budget for nested divs in the body.
|
|
103
|
-
// Count [[/div]] from body start to scope boundary, subtract 1 (for self).
|
|
104
|
-
let bodyBudget: number | undefined;
|
|
105
|
-
if (ctx.scope.divClosesBudget !== undefined) {
|
|
106
|
-
bodyBudget = ctx.scope.divClosesBudget - 1;
|
|
107
|
-
} else {
|
|
108
|
-
const closesInScope = countDivCloses(ctx, pos);
|
|
109
|
-
bodyBudget = closesInScope > 0 ? closesInScope - 1 : 0;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Close condition for [[/div]]
|
|
113
|
-
const closeCondition = (checkCtx: ParseContext): boolean => {
|
|
114
|
-
const token = checkCtx.tokens[checkCtx.pos];
|
|
115
|
-
if (token?.type === "BLOCK_END_OPEN") {
|
|
116
|
-
const closeNameResult = parseBlockName(checkCtx, checkCtx.pos + 1);
|
|
117
|
-
if (closeNameResult?.name === "div") {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return false;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const bodyCtx: ParseContext = {
|
|
125
|
-
...ctx,
|
|
126
|
-
pos,
|
|
127
|
-
scope: { ...ctx.scope, divClosesBudget: bodyBudget },
|
|
128
|
-
};
|
|
129
|
-
let children: Element[];
|
|
130
|
-
|
|
131
|
-
if (paragraphStrip) {
|
|
132
|
-
// div_ - parse as blocks, then unwrap first/last paragraphs
|
|
133
|
-
// Wikidot: blank lines create <p> for middle blocks only
|
|
134
|
-
const bodyResult = parseBlocksUntil(bodyCtx, closeCondition);
|
|
135
|
-
consumed += bodyResult.consumed;
|
|
136
|
-
pos += bodyResult.consumed;
|
|
137
|
-
children = unwrapEdgeParagraphs(bodyResult.elements);
|
|
138
|
-
} else {
|
|
139
|
-
// div - parse blocks with paragraph wrapping
|
|
140
|
-
const bodyResult = parseBlocksUntil(bodyCtx, closeCondition);
|
|
141
|
-
consumed += bodyResult.consumed;
|
|
142
|
-
pos += bodyResult.consumed;
|
|
143
|
-
children = bodyResult.elements;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Check for missing close tag
|
|
147
|
-
if (ctx.tokens[pos]?.type !== "BLOCK_END_OPEN") {
|
|
148
|
-
ctx.diagnostics.push({
|
|
149
|
-
severity: "warning",
|
|
150
|
-
code: "unclosed-block",
|
|
151
|
-
message: `Missing closing tag [[/div]] for [[${blockName}]]`,
|
|
152
|
-
position: openPosition,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Consume [[/div]]
|
|
157
|
-
if (ctx.tokens[pos]?.type === "BLOCK_END_OPEN") {
|
|
158
|
-
pos++;
|
|
159
|
-
consumed++;
|
|
160
|
-
const closeNameResult = parseBlockName(ctx, pos);
|
|
161
|
-
if (closeNameResult) {
|
|
162
|
-
pos += closeNameResult.consumed;
|
|
163
|
-
consumed += closeNameResult.consumed;
|
|
164
|
-
}
|
|
165
|
-
if (ctx.tokens[pos]?.type === "BLOCK_CLOSE") {
|
|
166
|
-
pos++;
|
|
167
|
-
consumed++;
|
|
168
|
-
}
|
|
169
|
-
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
170
|
-
pos++;
|
|
171
|
-
consumed++;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return {
|
|
176
|
-
success: true,
|
|
177
|
-
elements: [
|
|
178
|
-
{
|
|
179
|
-
element: "container",
|
|
180
|
-
data: {
|
|
181
|
-
type: "div",
|
|
182
|
-
attributes: attrResult.attrs,
|
|
183
|
-
elements: children,
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
],
|
|
187
|
-
consumed,
|
|
188
|
-
};
|
|
189
|
-
},
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Counts `[[/div]]` close tags from a given position to the end of the
|
|
194
|
-
* token stream. Used to calculate the nesting budget for div blocks.
|
|
195
|
-
*/
|
|
196
|
-
function countDivCloses(ctx: ParseContext, startPos: number): number {
|
|
197
|
-
let count = 0;
|
|
198
|
-
for (let i = startPos; i < ctx.tokens.length; i++) {
|
|
199
|
-
const t = ctx.tokens[i];
|
|
200
|
-
if (!t || t.type === "EOF") break;
|
|
201
|
-
if (t.type === "BLOCK_END_OPEN") {
|
|
202
|
-
const nameResult = parseBlockName(ctx, i + 1);
|
|
203
|
-
if (nameResult?.name === "div") {
|
|
204
|
-
count++;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return count;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Handles the case where `[[div]]` fails as a block element because
|
|
213
|
-
* the closing `]]` is not followed by a NEWLINE.
|
|
214
|
-
*
|
|
215
|
-
* In Wikidot, this scenario causes the parser to scan forward for the
|
|
216
|
-
* LAST `[[/div]]` in the contiguous token stream and collect everything
|
|
217
|
-
* from the current position through that close tag as a single paragraph.
|
|
218
|
-
* Blank lines (double newlines) within the range are silently collapsed,
|
|
219
|
-
* and single newlines become `<br />`.
|
|
220
|
-
*
|
|
221
|
-
* If no `[[/div]]` is found at all, the rule fails entirely.
|
|
222
|
-
*
|
|
223
|
-
* @param ctx - Parse context, positioned at the opening `[[div...]]` tag.
|
|
224
|
-
* @returns A paragraph container with text/line-break elements, or failure.
|
|
225
|
-
*/
|
|
226
|
-
function consumeFailedDiv(ctx: ParseContext): RuleResult<Element> {
|
|
227
|
-
const elements: Element[] = [];
|
|
228
|
-
let pos = ctx.pos;
|
|
229
|
-
let consumed = 0;
|
|
230
|
-
let lastClosePos = -1;
|
|
231
|
-
let lastCloseConsumed = 0;
|
|
232
|
-
|
|
233
|
-
// Find the last [[/div]] before the next valid div block.
|
|
234
|
-
// A valid div block is [[div]]/[[div_]] at line start followed by ]] + NEWLINE.
|
|
235
|
-
// When a valid div block is found, stop scanning — it should be parsed as a
|
|
236
|
-
// separate block element, not absorbed into this failed div's text.
|
|
237
|
-
let scanPos = pos;
|
|
238
|
-
while (scanPos < ctx.tokens.length) {
|
|
239
|
-
const t = ctx.tokens[scanPos];
|
|
240
|
-
if (!t || t.type === "EOF") break;
|
|
241
|
-
|
|
242
|
-
// Check for a valid div block opening (skip the initial failed div at pos)
|
|
243
|
-
if (t.type === "BLOCK_OPEN" && t.lineStart && scanPos > pos) {
|
|
244
|
-
const nameResult = parseBlockName(ctx, scanPos + 1);
|
|
245
|
-
if (nameResult?.name === "div" || nameResult?.name === "div_") {
|
|
246
|
-
let checkPos = scanPos + 1 + nameResult.consumed;
|
|
247
|
-
const attrResult = parseAttributes(ctx, checkPos);
|
|
248
|
-
checkPos += attrResult.consumed;
|
|
249
|
-
if (ctx.tokens[checkPos]?.type === "BLOCK_CLOSE") {
|
|
250
|
-
checkPos++;
|
|
251
|
-
if (ctx.tokens[checkPos]?.type === "NEWLINE" || ctx.tokens[checkPos]?.type === "EOF") {
|
|
252
|
-
// Valid div block found — stop scanning here
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (t.type === "BLOCK_END_OPEN") {
|
|
260
|
-
const nameResult = parseBlockName(ctx, scanPos + 1);
|
|
261
|
-
if (nameResult?.name === "div") {
|
|
262
|
-
// Found [[/div]] - record position after ]]
|
|
263
|
-
lastClosePos = scanPos;
|
|
264
|
-
lastCloseConsumed = 1 + nameResult.consumed; // [[/ + div
|
|
265
|
-
const closeToken = ctx.tokens[scanPos + 1 + nameResult.consumed];
|
|
266
|
-
if (closeToken?.type === "BLOCK_CLOSE") {
|
|
267
|
-
lastCloseConsumed++;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
scanPos++;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (lastClosePos === -1) {
|
|
275
|
-
// No [[/div]] found, fall back to normal failure
|
|
276
|
-
return { success: false };
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Emit diagnostics for all inline [[div]] patterns in the absorbed range.
|
|
280
|
-
// The initial [[div]] at ctx.pos is always included; any additional [[div]]
|
|
281
|
-
// patterns within the range also get diagnostics.
|
|
282
|
-
const endPosForDiag = lastClosePos;
|
|
283
|
-
for (let diagPos = ctx.pos; diagPos < endPosForDiag; diagPos++) {
|
|
284
|
-
const t = ctx.tokens[diagPos];
|
|
285
|
-
if (t?.type === "BLOCK_OPEN") {
|
|
286
|
-
const nameResult = parseBlockName(ctx, diagPos + 1);
|
|
287
|
-
if (nameResult?.name === "div" || nameResult?.name === "div_") {
|
|
288
|
-
if (t.position) {
|
|
289
|
-
ctx.diagnostics.push({
|
|
290
|
-
severity: "error",
|
|
291
|
-
code: "inline-block-element",
|
|
292
|
-
message: `[[${nameResult.name}]] must be followed by a newline to be a block element`,
|
|
293
|
-
position: t.position,
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Consume everything from current position to after the last [[/div]]
|
|
301
|
-
const endPos = lastClosePos + lastCloseConsumed;
|
|
302
|
-
while (pos < endPos && pos < ctx.tokens.length) {
|
|
303
|
-
const t = ctx.tokens[pos];
|
|
304
|
-
if (!t || t.type === "EOF") break;
|
|
305
|
-
|
|
306
|
-
if (t.type === "NEWLINE") {
|
|
307
|
-
// Check if this is a blank line (NEWLINE+NEWLINE or NEWLINE+WHITESPACE+NEWLINE)
|
|
308
|
-
let peekPos = pos + 1;
|
|
309
|
-
while (ctx.tokens[peekPos]?.type === "WHITESPACE") peekPos++;
|
|
310
|
-
if (ctx.tokens[peekPos]?.type === "NEWLINE") {
|
|
311
|
-
// Blank line — skip all newlines and whitespace
|
|
312
|
-
while (ctx.tokens[pos]?.type === "NEWLINE" || ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
313
|
-
pos++;
|
|
314
|
-
consumed++;
|
|
315
|
-
}
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
// Single newline → line-break
|
|
319
|
-
elements.push({ element: "line-break" });
|
|
320
|
-
pos++;
|
|
321
|
-
consumed++;
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
elements.push({ element: "text", data: t.value });
|
|
326
|
-
pos++;
|
|
327
|
-
consumed++;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Consume trailing newline after [[/div]] if present
|
|
331
|
-
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
332
|
-
pos++;
|
|
333
|
-
consumed++;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return {
|
|
337
|
-
success: true,
|
|
338
|
-
elements: [
|
|
339
|
-
{
|
|
340
|
-
element: "container",
|
|
341
|
-
data: {
|
|
342
|
-
type: "paragraph",
|
|
343
|
-
attributes: {},
|
|
344
|
-
elements,
|
|
345
|
-
},
|
|
346
|
-
},
|
|
347
|
-
],
|
|
348
|
-
consumed,
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Implements the `[[div_]]` paragraph-strip behaviour.
|
|
354
|
-
*
|
|
355
|
-
* In Wikidot's `div_` mode, the first and last paragraph containers have
|
|
356
|
-
* their `<p>` wrappers removed, leaving the inner elements bare. Any
|
|
357
|
-
* middle paragraphs retain their wrapping. This produces output where the
|
|
358
|
-
* opening and closing text sit directly inside the `<div>`.
|
|
359
|
-
*
|
|
360
|
-
* @param elements - Block elements produced by body parsing.
|
|
361
|
-
* @returns A new array with edge paragraphs unwrapped.
|
|
362
|
-
*/
|
|
363
|
-
function unwrapEdgeParagraphs(elements: Element[]): Element[] {
|
|
364
|
-
if (elements.length === 0) return elements;
|
|
365
|
-
|
|
366
|
-
const result = [...elements];
|
|
367
|
-
|
|
368
|
-
// Unwrap first element if paragraph
|
|
369
|
-
if (isParagraphContainer(result[0])) {
|
|
370
|
-
const inner = (result[0] as any).data.elements as Element[];
|
|
371
|
-
result.splice(0, 1, ...inner);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Unwrap last element if paragraph (find new last index after splice)
|
|
375
|
-
const lastIdx = result.length - 1;
|
|
376
|
-
if (lastIdx >= 0 && isParagraphContainer(result[lastIdx])) {
|
|
377
|
-
const inner = (result[lastIdx] as any).data.elements as Element[];
|
|
378
|
-
result.splice(lastIdx, 1, ...inner);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
return result;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* Checks whether an element is a paragraph container
|
|
386
|
-
* (i.e. `{ element: "container", data: { type: "paragraph" } }`).
|
|
387
|
-
*
|
|
388
|
-
* @param el - Element to test, or `undefined`.
|
|
389
|
-
* @returns `true` if the element is a paragraph container.
|
|
390
|
-
*/
|
|
391
|
-
function isParagraphContainer(el: Element | undefined): boolean {
|
|
392
|
-
return (
|
|
393
|
-
el !== undefined &&
|
|
394
|
-
el.element === "container" &&
|
|
395
|
-
typeof el.data === "object" &&
|
|
396
|
-
el.data !== null &&
|
|
397
|
-
"type" in el.data &&
|
|
398
|
-
el.data.type === "paragraph"
|
|
399
|
-
);
|
|
400
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Block rule for Wikidot embed blocks: `[[embed]]`, `[[embedvideo]]`,
|
|
4
|
-
* and `[[embedaudio]]` (each with a matching closing tag).
|
|
5
|
-
*
|
|
6
|
-
* In original Wikidot, only HTML that matches a server-side allow-list is
|
|
7
|
-
* rendered. This parser does not perform that filtering -- the raw content
|
|
8
|
-
* between the tags is stored verbatim as an `embed-block` element. Validation
|
|
9
|
-
* and sanitisation are expected to happen at rendering time or on the server.
|
|
10
|
-
*
|
|
11
|
-
* The embed block is wrapped in a paragraph container in the AST, matching
|
|
12
|
-
* Wikidot's rendering behaviour where embeds sit inside `<p>` tags.
|
|
13
|
-
*
|
|
14
|
-
* If no closing tag is found, the rule fails to prevent consuming the rest
|
|
15
|
-
* of the document.
|
|
16
|
-
*
|
|
17
|
-
* @module
|
|
18
|
-
*/
|
|
19
|
-
import type { Element } from "@wdprlib/ast";
|
|
20
|
-
import type { BlockRule, ParseContext, RuleResult } from "../types";
|
|
21
|
-
import { currentToken } from "../types";
|
|
22
|
-
import { parseBlockName } from "./utils";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Block rule for `[[embed]]`, `[[embedvideo]]`, and `[[embedaudio]]`.
|
|
26
|
-
*
|
|
27
|
-
* Content between the opening and closing tags is captured as raw text.
|
|
28
|
-
* The block name matching is case-insensitive; the closing tag may use
|
|
29
|
-
* any of the three names (`embed`, `embedvideo`, `embedaudio`) regardless
|
|
30
|
-
* of which was used to open.
|
|
31
|
-
*/
|
|
32
|
-
export const embedBlockRule: BlockRule = {
|
|
33
|
-
name: "embed-block",
|
|
34
|
-
startTokens: ["BLOCK_OPEN"],
|
|
35
|
-
requiresLineStart: false,
|
|
36
|
-
|
|
37
|
-
parse(ctx: ParseContext): RuleResult<Element> {
|
|
38
|
-
const openToken = currentToken(ctx);
|
|
39
|
-
if (openToken.type !== "BLOCK_OPEN") {
|
|
40
|
-
return { success: false };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let pos = ctx.pos + 1;
|
|
44
|
-
let consumed = 1;
|
|
45
|
-
|
|
46
|
-
// Parse block name
|
|
47
|
-
const nameResult = parseBlockName(ctx, pos);
|
|
48
|
-
if (!nameResult) {
|
|
49
|
-
return { success: false };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const blockName = nameResult.name.toLowerCase();
|
|
53
|
-
if (blockName !== "embed" && blockName !== "embedvideo" && blockName !== "embedaudio") {
|
|
54
|
-
return { success: false };
|
|
55
|
-
}
|
|
56
|
-
pos += nameResult.consumed;
|
|
57
|
-
consumed += nameResult.consumed;
|
|
58
|
-
|
|
59
|
-
// Skip whitespace
|
|
60
|
-
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
61
|
-
pos++;
|
|
62
|
-
consumed++;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Expect ]]
|
|
66
|
-
if (ctx.tokens[pos]?.type !== "BLOCK_CLOSE") {
|
|
67
|
-
return { success: false };
|
|
68
|
-
}
|
|
69
|
-
pos++;
|
|
70
|
-
consumed++;
|
|
71
|
-
|
|
72
|
-
// Collect content until [[/embed]], [[/embedvideo]], or [[/embedaudio]]
|
|
73
|
-
let contents = "";
|
|
74
|
-
let foundClose = false;
|
|
75
|
-
|
|
76
|
-
while (pos < ctx.tokens.length) {
|
|
77
|
-
const token = ctx.tokens[pos];
|
|
78
|
-
if (!token) break;
|
|
79
|
-
|
|
80
|
-
// Check for closing [[/embed*]]
|
|
81
|
-
if (token.type === "BLOCK_END_OPEN") {
|
|
82
|
-
const closeNameResult = parseBlockName(ctx, pos + 1);
|
|
83
|
-
if (closeNameResult) {
|
|
84
|
-
const closeName = closeNameResult.name.toLowerCase();
|
|
85
|
-
if (closeName === "embed" || closeName === "embedvideo" || closeName === "embedaudio") {
|
|
86
|
-
foundClose = true;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
contents += token.value;
|
|
93
|
-
pos++;
|
|
94
|
-
consumed++;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Require closing tag - without it, fail to prevent consuming entire document
|
|
98
|
-
if (!foundClose) {
|
|
99
|
-
ctx.diagnostics.push({
|
|
100
|
-
severity: "warning",
|
|
101
|
-
code: "unclosed-block",
|
|
102
|
-
message: `Missing closing tag [[/${blockName}]] for [[${blockName}]]`,
|
|
103
|
-
position: openToken.position,
|
|
104
|
-
});
|
|
105
|
-
return { success: false };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Consume [[/embed*]]
|
|
109
|
-
if (ctx.tokens[pos]?.type === "BLOCK_END_OPEN") {
|
|
110
|
-
pos++;
|
|
111
|
-
consumed++;
|
|
112
|
-
const closeNameResult = parseBlockName(ctx, pos);
|
|
113
|
-
if (closeNameResult) {
|
|
114
|
-
pos += closeNameResult.consumed;
|
|
115
|
-
consumed += closeNameResult.consumed;
|
|
116
|
-
}
|
|
117
|
-
if (ctx.tokens[pos]?.type === "BLOCK_CLOSE") {
|
|
118
|
-
pos++;
|
|
119
|
-
consumed++;
|
|
120
|
-
}
|
|
121
|
-
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
122
|
-
pos++;
|
|
123
|
-
consumed++;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Trim the contents
|
|
128
|
-
contents = contents.trim();
|
|
129
|
-
|
|
130
|
-
// Wikidotと同じく、embed-blockをparagraphで囲む
|
|
131
|
-
return {
|
|
132
|
-
success: true,
|
|
133
|
-
elements: [
|
|
134
|
-
{
|
|
135
|
-
element: "container",
|
|
136
|
-
data: {
|
|
137
|
-
type: "paragraph",
|
|
138
|
-
attributes: {},
|
|
139
|
-
elements: [
|
|
140
|
-
{
|
|
141
|
-
element: "embed-block",
|
|
142
|
-
data: {
|
|
143
|
-
contents,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
consumed,
|
|
151
|
-
};
|
|
152
|
-
},
|
|
153
|
-
};
|