@wdprlib/parser 3.2.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +10471 -8406
- package/dist/index.d.cts +313 -337
- package/dist/index.d.ts +313 -337
- package/dist/index.js +10457 -8392
- package/package.json +1 -1
- package/src/index.ts +7 -0
- package/src/lexer/anchor.ts +48 -0
- package/src/lexer/index.ts +3 -2
- package/src/lexer/lexer.ts +73 -559
- package/src/lexer/options.ts +19 -0
- package/src/lexer/punctuation.ts +70 -0
- package/src/lexer/quoted-string.ts +16 -0
- package/src/lexer/runs.ts +85 -0
- package/src/lexer/spacing-actions.ts +24 -0
- package/src/lexer/state.ts +103 -0
- package/src/lexer/syntax-actions.ts +80 -0
- package/src/lexer/text-actions.ts +41 -0
- package/src/lexer/token-actions.ts +136 -0
- package/src/lexer/token-factory.ts +62 -0
- package/src/lexer/tokenize.ts +18 -0
- package/src/parser/constants.ts +2 -0
- package/src/parser/depth/index.ts +111 -0
- package/src/parser/depth/stack.ts +82 -0
- package/src/parser/parse/block.ts +42 -0
- package/src/parser/parse/context.ts +26 -0
- package/src/parser/parse/footnotes.ts +25 -0
- package/src/parser/parse/index.ts +42 -0
- package/src/parser/parse/options.ts +34 -0
- package/src/parser/parse/parser.ts +79 -0
- package/src/parser/parse/plain-non-ascii.ts +129 -0
- package/src/parser/parse/result.ts +57 -0
- package/src/parser/parse/source.ts +11 -0
- package/src/parser/postprocess/divAdjacentParagraph.ts +1 -1
- package/src/parser/postprocess/spanStrip/clean-element.ts +168 -0
- package/src/parser/postprocess/spanStrip/cleanup.ts +25 -0
- package/src/parser/postprocess/spanStrip/empty-spans.ts +36 -0
- package/src/parser/postprocess/spanStrip/escaped.ts +78 -0
- package/src/parser/postprocess/spanStrip/factory.ts +23 -0
- package/src/parser/postprocess/spanStrip/index.ts +8 -0
- package/src/parser/postprocess/spanStrip/merge.ts +117 -0
- package/src/parser/postprocess/spanStrip/predicates.ts +59 -0
- package/src/parser/postprocess/spanStrip/split.ts +67 -0
- package/src/parser/preprocess/expr/chars.ts +15 -0
- package/src/parser/preprocess/expr/evaluate.ts +22 -0
- package/src/parser/preprocess/expr/index.ts +45 -0
- package/src/parser/preprocess/expr/kind.ts +19 -0
- package/src/parser/preprocess/expr/parse.ts +103 -0
- package/src/parser/preprocess/expr/scan.ts +34 -0
- package/src/parser/preprocess/expr/types.ts +14 -0
- package/src/parser/preprocess/typography.ts +70 -5
- package/src/parser/preprocess/utils/bracket-depths.ts +98 -0
- package/src/parser/preprocess/utils/index.ts +13 -0
- package/src/parser/preprocess/utils/raw-regions.ts +153 -0
- package/src/parser/preprocess/whitespace/detection.ts +39 -0
- package/src/parser/preprocess/whitespace/index.ts +79 -0
- package/src/parser/preprocess/whitespace/leading-spaces.ts +11 -0
- package/src/parser/preprocess/whitespace/patterns.ts +23 -0
- package/src/parser/rules/block/align/body.ts +46 -0
- package/src/parser/rules/block/align/element.ts +13 -0
- package/src/parser/rules/block/align/index.ts +90 -0
- package/src/parser/rules/block/align/syntax.ts +113 -0
- package/src/parser/rules/block/bibliography/body.ts +81 -0
- package/src/parser/rules/block/bibliography/entries.ts +49 -0
- package/src/parser/rules/block/bibliography/entry-content.ts +73 -0
- package/src/parser/rules/block/bibliography/entry-key.ts +83 -0
- package/src/parser/rules/block/bibliography/index.ts +90 -0
- package/src/parser/rules/block/bibliography/open.ts +53 -0
- package/src/parser/rules/block/block-list/bare-content.ts +105 -0
- package/src/parser/rules/block/block-list/bare-paragraph.ts +60 -0
- package/src/parser/rules/block/block-list/index.ts +51 -0
- package/src/parser/rules/block/block-list/item-content.ts +132 -0
- package/src/parser/rules/block/block-list/li-content.ts +107 -0
- package/src/parser/rules/block/block-list/li-item.ts +77 -0
- package/src/parser/rules/block/block-list/list-block.ts +100 -0
- package/src/parser/rules/block/block-list/open.ts +51 -0
- package/src/parser/rules/block/block-list/tags.ts +50 -0
- package/src/parser/rules/block/blockquote/build.ts +62 -0
- package/src/parser/rules/block/blockquote/index.ts +80 -0
- package/src/parser/rules/block/blockquote/line.ts +79 -0
- package/src/parser/rules/block/blockquote/lines.ts +39 -0
- package/src/parser/rules/block/{center.ts → center/index.ts} +7 -22
- package/src/parser/rules/block/center/open.ts +27 -0
- package/src/parser/rules/block/{clear-float.ts → clear-float/index.ts} +6 -30
- package/src/parser/rules/block/clear-float/syntax.ts +43 -0
- package/src/parser/rules/block/code/attributes.ts +30 -0
- package/src/parser/rules/block/code/content.ts +57 -0
- package/src/parser/rules/block/code/index.ts +100 -0
- package/src/parser/rules/block/collapsible/attributes.ts +95 -0
- package/src/parser/rules/block/collapsible/body.ts +69 -0
- package/src/parser/rules/block/collapsible/index.ts +117 -0
- package/src/parser/rules/block/collapsible/open.ts +51 -0
- package/src/parser/rules/block/collapsible/orphans.ts +31 -0
- package/src/parser/rules/block/collapsible/tags.ts +17 -0
- package/src/parser/rules/block/comment/consume.ts +37 -0
- package/src/parser/rules/block/{comment.ts → comment/index.ts} +12 -38
- package/src/parser/rules/block/{content-separator.ts → content-separator/index.ts} +5 -35
- package/src/parser/rules/block/content-separator/syntax.ts +33 -0
- package/src/parser/rules/block/definition-list/collect.ts +40 -0
- package/src/parser/rules/block/definition-list/index.ts +63 -0
- package/src/parser/rules/block/definition-list/item-key.ts +95 -0
- package/src/parser/rules/block/definition-list/item-value.ts +56 -0
- package/src/parser/rules/block/definition-list/items.ts +54 -0
- package/src/parser/rules/block/div/body.ts +41 -0
- package/src/parser/rules/block/div/close.ts +41 -0
- package/src/parser/rules/block/div/failed.ts +117 -0
- package/src/parser/rules/block/div/index.ts +112 -0
- package/src/parser/rules/block/div/nesting.ts +37 -0
- package/src/parser/rules/block/div/open.ts +59 -0
- package/src/parser/rules/block/div/paragraph-strip.ts +44 -0
- package/src/parser/rules/block/embed-block/content.ts +53 -0
- package/src/parser/rules/block/embed-block/index.ts +91 -0
- package/src/parser/rules/block/embed-block/open.ts +52 -0
- package/src/parser/rules/block/embed-block/tags.ts +5 -0
- package/src/parser/rules/block/footnoteblock/attributes.ts +73 -0
- package/src/parser/rules/block/footnoteblock/index.ts +82 -0
- package/src/parser/rules/block/footnoteblock/open.ts +53 -0
- package/src/parser/rules/block/heading/index.ts +87 -0
- package/src/parser/rules/block/heading/open.ts +50 -0
- package/src/parser/rules/block/heading/toc-text.ts +26 -0
- package/src/parser/rules/block/{horizontal-rule.ts → horizontal-rule/index.ts} +4 -21
- package/src/parser/rules/block/horizontal-rule/syntax.ts +21 -0
- package/src/parser/rules/block/html/body.ts +114 -0
- package/src/parser/rules/block/html/diagnostics.ts +11 -0
- package/src/parser/rules/block/html/index.ts +95 -0
- package/src/parser/rules/block/html/open.ts +36 -0
- package/src/parser/rules/block/iframe/attributes.ts +106 -0
- package/src/parser/rules/block/iframe/index.ts +73 -0
- package/src/parser/rules/block/iframe/open.ts +58 -0
- package/src/parser/rules/block/iframe/source.ts +24 -0
- package/src/parser/rules/block/iframe/url.ts +38 -0
- package/src/parser/rules/block/iftags/body.ts +48 -0
- package/src/parser/rules/block/iftags/condition.ts +24 -0
- package/src/parser/rules/block/{iftags.ts → iftags/index.ts} +16 -58
- package/src/parser/rules/block/include/arguments.ts +48 -0
- package/src/parser/rules/block/include/index.ts +75 -0
- package/src/parser/rules/block/include/location.ts +24 -0
- package/src/parser/rules/block/include/variables.ts +37 -0
- package/src/parser/rules/block/list/index.ts +73 -0
- package/src/parser/rules/block/list/line.ts +77 -0
- package/src/parser/rules/block/list/native.ts +89 -0
- package/src/parser/rules/block/math/content.ts +54 -0
- package/src/parser/rules/block/math/index.ts +106 -0
- package/src/parser/rules/block/math/name.ts +35 -0
- package/src/parser/rules/block/module/body.ts +92 -0
- package/src/parser/rules/block/module/element.ts +33 -0
- package/src/parser/rules/block/module/include/directive.ts +91 -0
- package/src/parser/rules/block/module/include/index.ts +11 -2
- package/src/parser/rules/block/module/include/references.ts +42 -0
- package/src/parser/rules/block/module/include/resolve/cache.ts +44 -0
- package/src/parser/rules/block/module/include/resolve/index.ts +106 -0
- package/src/parser/rules/block/module/include/resolve/iterate.ts +202 -0
- package/src/parser/rules/block/module/include/resolve/replace.ts +31 -0
- package/src/parser/rules/block/module/include/resolve/types.ts +105 -0
- package/src/parser/rules/block/module/include/scanner.ts +121 -0
- package/src/parser/rules/block/module/index.ts +14 -2
- package/src/parser/rules/block/module/listpages/compiler.ts +12 -392
- package/src/parser/rules/block/module/listpages/extract.ts +25 -359
- package/src/parser/rules/block/module/listpages/extraction/listpages.ts +42 -0
- package/src/parser/rules/block/module/listpages/extraction/listusers.ts +30 -0
- package/src/parser/rules/block/module/listpages/extraction/query.ts +51 -0
- package/src/parser/rules/block/module/listpages/extraction/result.ts +18 -0
- package/src/parser/rules/block/module/listpages/extraction/template.ts +96 -0
- package/src/parser/rules/block/module/listpages/extraction/variables.ts +58 -0
- package/src/parser/rules/block/module/listpages/normalization/date-selector.ts +53 -0
- package/src/parser/rules/block/module/listpages/normalization/numeric-selector.ts +32 -0
- package/src/parser/rules/block/module/listpages/normalization/order-parent.ts +82 -0
- package/src/parser/rules/block/module/listpages/normalization/selectors.ts +2 -0
- package/src/parser/rules/block/module/listpages/normalization/tags-category.ts +86 -0
- package/src/parser/rules/block/module/listpages/normalize.ts +8 -324
- package/src/parser/rules/block/module/listpages/resolution/items.ts +43 -0
- package/src/parser/rules/block/module/listpages/resolution/wrapper.ts +42 -0
- package/src/parser/rules/block/module/listpages/resolve.ts +5 -75
- package/src/parser/rules/block/module/listpages/template/format/content.ts +41 -0
- package/src/parser/rules/block/module/listpages/template/format/date.ts +116 -0
- package/src/parser/rules/block/module/listpages/template/format/index.ts +4 -0
- package/src/parser/rules/block/module/listpages/template/format/tags.ts +7 -0
- package/src/parser/rules/block/module/listpages/template/format/user.ts +9 -0
- package/src/parser/rules/block/module/listpages/template/getters/index.ts +36 -0
- package/src/parser/rules/block/module/listpages/template/getters/parameterized.ts +60 -0
- package/src/parser/rules/block/module/listpages/template/getters/simple.ts +65 -0
- package/src/parser/rules/block/module/listpages/template/getters/types.ts +3 -0
- package/src/parser/rules/block/module/listpages/template/syntax.ts +97 -0
- package/src/parser/rules/block/module/listpages/types/data-fetcher.ts +15 -0
- package/src/parser/rules/block/module/listpages/types/data-requirements.ts +52 -0
- package/src/parser/rules/block/module/listpages/types/external-data.ts +77 -0
- package/src/parser/rules/block/module/listpages/types/index.ts +17 -0
- package/src/parser/rules/block/module/listpages/types/normalized-query.ts +120 -0
- package/src/parser/rules/block/module/listpages/types/query.ts +67 -0
- package/src/parser/rules/block/module/listpages/types/template.ts +17 -0
- package/src/parser/rules/block/module/listpages/types/variables.ts +69 -0
- package/src/parser/rules/block/module/listpages/url-resolution/fields.ts +48 -0
- package/src/parser/rules/block/module/listpages/url-resolution/params.ts +30 -0
- package/src/parser/rules/block/module/listpages/url-resolution/query.ts +24 -0
- package/src/parser/rules/block/module/listpages/url-resolution/resolve.ts +62 -0
- package/src/parser/rules/block/module/listpages/url-resolution/value.ts +34 -0
- package/src/parser/rules/block/module/listpages/url-resolver.ts +3 -160
- package/src/parser/rules/block/module/listusers/compiler.ts +4 -25
- package/src/parser/rules/block/module/listusers/extract.ts +4 -9
- package/src/parser/rules/block/module/listusers/getters.ts +21 -0
- package/src/parser/rules/block/module/listusers/variables.ts +15 -0
- package/src/parser/rules/block/module/open.ts +57 -0
- package/src/parser/rules/block/module/resolution/contexts.ts +78 -0
- package/src/parser/rules/block/module/resolution/data-maps.ts +39 -0
- package/src/parser/rules/block/module/resolution/dynamic-modules.ts +93 -0
- package/src/parser/rules/block/module/resolution/styles.ts +53 -0
- package/src/parser/rules/block/module/resolution/walk-resolve.ts +107 -0
- package/src/parser/rules/block/module/resolve.ts +79 -292
- package/src/parser/rules/block/module/rule.ts +56 -0
- package/src/parser/rules/block/module/types-common.ts +11 -0
- package/src/parser/rules/block/module/walk/children.ts +35 -0
- package/src/parser/rules/block/module/walk/index.ts +9 -0
- package/src/parser/rules/block/module/walk/map/index.ts +2 -0
- package/src/parser/rules/block/module/walk/map/stateful-definition-list.ts +25 -0
- package/src/parser/rules/block/module/walk/map/stateful-list.ts +40 -0
- package/src/parser/rules/block/module/walk/map/stateful-table.ts +23 -0
- package/src/parser/rules/block/module/walk/map/stateful-tabs.ts +19 -0
- package/src/parser/rules/block/module/walk/map/stateful.ts +71 -0
- package/src/parser/rules/block/module/walk/map/stateless-definition-list.ts +12 -0
- package/src/parser/rules/block/module/walk/map/stateless-list.ts +29 -0
- package/src/parser/rules/block/module/walk/map/stateless-table.ts +11 -0
- package/src/parser/rules/block/module/walk/map/stateless-tabs.ts +5 -0
- package/src/parser/rules/block/module/walk/map/stateless.ts +51 -0
- package/src/parser/rules/block/module/walk/map/types.ts +6 -0
- package/src/parser/rules/block/module/walk/traverse.ts +65 -0
- package/src/parser/rules/block/orphan-li/content.ts +60 -0
- package/src/parser/rules/block/orphan-li/index.ts +75 -0
- package/src/parser/rules/block/orphan-li/open.ts +25 -0
- package/src/parser/rules/block/orphan-li/tags.ts +40 -0
- package/src/parser/rules/block/paragraph/content.ts +12 -0
- package/src/parser/rules/block/paragraph/index.ts +60 -0
- package/src/parser/rules/block/paragraph/normalize.ts +52 -0
- package/src/parser/rules/block/paragraph/span-markers.ts +52 -0
- package/src/parser/rules/block/parsing/attributes/index.ts +32 -0
- package/src/parser/rules/block/parsing/attributes/names.ts +93 -0
- package/src/parser/rules/block/parsing/attributes/scanner.ts +75 -0
- package/src/parser/rules/block/parsing/attributes/values.ts +26 -0
- package/src/parser/rules/block/parsing/block-item.ts +29 -0
- package/src/parser/rules/block/parsing/content.ts +127 -0
- package/src/parser/rules/block/parsing/end-condition.ts +51 -0
- package/src/parser/rules/block/parsing/inline-content.ts +105 -0
- package/src/parser/rules/block/parsing/inline-newline.ts +41 -0
- package/src/parser/rules/block/parsing/non-boundary.ts +24 -0
- package/src/parser/rules/block/parsing/rule-dispatch.ts +44 -0
- package/src/parser/rules/block/table/index.ts +80 -0
- package/src/parser/rules/block/table/pipe/cell-start.ts +69 -0
- package/src/parser/rules/block/table/pipe/cell.ts +106 -0
- package/src/parser/rules/block/table/pipe/index.ts +2 -0
- package/src/parser/rules/block/table/pipe/row.ts +88 -0
- package/src/parser/rules/block/table/pipe/tokens.ts +14 -0
- package/src/parser/rules/block/table/pipe/trim.ts +50 -0
- package/src/parser/rules/block/table-block/body.ts +79 -0
- package/src/parser/rules/block/table-block/cell-attributes.ts +33 -0
- package/src/parser/rules/block/table-block/cell-boundary.ts +99 -0
- package/src/parser/rules/block/table-block/cell-content/index.ts +88 -0
- package/src/parser/rules/block/table-block/cell-content/segments.ts +134 -0
- package/src/parser/rules/block/table-block/cell-newline.ts +47 -0
- package/src/parser/rules/block/table-block/cell.ts +64 -0
- package/src/parser/rules/block/table-block/index.ts +113 -0
- package/src/parser/rules/block/table-block/row-boundary.ts +75 -0
- package/src/parser/rules/block/table-block/structure.ts +80 -0
- package/src/parser/rules/block/tabview/body.ts +64 -0
- package/src/parser/rules/block/tabview/index.ts +90 -0
- package/src/parser/rules/block/tabview/open.ts +50 -0
- package/src/parser/rules/block/tabview/tab.ts +92 -0
- package/src/parser/rules/block/tabview/tags.ts +30 -0
- package/src/parser/rules/block/toc/element.ts +11 -0
- package/src/parser/rules/block/toc/index.ts +44 -0
- package/src/parser/rules/block/toc/open.ts +84 -0
- package/src/parser/rules/block/utils.ts +10 -610
- package/src/parser/rules/{utils.ts → common/attribute-safety.ts} +3 -49
- package/src/parser/rules/common/block-name.ts +33 -0
- package/src/parser/rules/common/index.ts +2 -0
- package/src/parser/rules/contracts/index.ts +3 -0
- package/src/parser/rules/contracts/parse-context.ts +38 -0
- package/src/parser/rules/contracts/rule.ts +43 -0
- package/src/parser/rules/contracts/scope.ts +31 -0
- package/src/parser/rules/inline/anchor/attributes.ts +54 -0
- package/src/parser/rules/inline/anchor/child.ts +26 -0
- package/src/parser/rules/inline/anchor/close.ts +34 -0
- package/src/parser/rules/inline/anchor/content.ts +59 -0
- package/src/parser/rules/inline/anchor/index.ts +103 -0
- package/src/parser/rules/inline/anchor/newline.ts +26 -0
- package/src/parser/rules/inline/anchor/open.ts +47 -0
- package/src/parser/rules/inline/anchor/paragraph-strip.ts +14 -0
- package/src/parser/rules/inline/anchor/syntax.ts +40 -0
- package/src/parser/rules/inline/anchor-name/index.ts +38 -0
- package/src/parser/rules/inline/anchor-name/name.ts +39 -0
- package/src/parser/rules/inline/anchor-name/syntax.ts +46 -0
- package/src/parser/rules/inline/bibcite/element.ts +14 -0
- package/src/parser/rules/inline/bibcite/index.ts +34 -0
- package/src/parser/rules/inline/bibcite/syntax.ts +64 -0
- package/src/parser/rules/inline/bold.ts +2 -39
- package/src/parser/rules/inline/color/index.ts +35 -0
- package/src/parser/rules/inline/color/syntax.ts +69 -0
- package/src/parser/rules/inline/comment/consume.ts +31 -0
- package/src/parser/rules/inline/{comment.ts → comment/index.ts} +10 -36
- package/src/parser/rules/inline/equation-ref/element.ts +8 -0
- package/src/parser/rules/inline/equation-ref/index.ts +34 -0
- package/src/parser/rules/inline/equation-ref/syntax.ts +45 -0
- package/src/parser/rules/inline/expr/branch.ts +104 -0
- package/src/parser/rules/inline/expr/conditional-branch.ts +27 -0
- package/src/parser/rules/inline/expr/conditional.ts +80 -0
- package/src/parser/rules/inline/expr/depth.ts +25 -0
- package/src/parser/rules/inline/expr/elements.ts +39 -0
- package/src/parser/rules/inline/expr/index.ts +84 -0
- package/src/parser/rules/inline/expr/syntax.ts +45 -0
- package/src/parser/rules/inline/footnote/child.ts +22 -0
- package/src/parser/rules/inline/footnote/close.ts +33 -0
- package/src/parser/rules/inline/footnote/content.ts +54 -0
- package/src/parser/rules/inline/footnote/elements.ts +38 -0
- package/src/parser/rules/inline/footnote/index.ts +54 -0
- package/src/parser/rules/inline/footnote/newline.ts +27 -0
- package/src/parser/rules/inline/footnote/open.ts +38 -0
- package/src/parser/rules/inline/formatting/container.ts +50 -0
- package/src/parser/rules/inline/{guillemet.ts → guillemet/index.ts} +5 -13
- package/src/parser/rules/inline/guillemet/text.ts +11 -0
- package/src/parser/rules/inline/html/gate.ts +64 -0
- package/src/parser/rules/inline/{html.ts → html/index.ts} +9 -60
- package/src/parser/rules/inline/html/open.ts +37 -0
- package/src/parser/rules/inline/image/attributes.ts +22 -0
- package/src/parser/rules/inline/image/body.ts +36 -0
- package/src/parser/rules/inline/image/index.ts +89 -0
- package/src/parser/rules/inline/image/open.ts +56 -0
- package/src/parser/rules/inline/image/source.ts +62 -0
- package/src/parser/rules/inline/image/syntax.ts +76 -0
- package/src/parser/rules/inline/italic.ts +2 -30
- package/src/parser/rules/inline/line-break/backslash.ts +58 -0
- package/src/parser/rules/inline/line-break/elements.ts +9 -0
- package/src/parser/rules/inline/line-break/index.ts +3 -0
- package/src/parser/rules/inline/line-break/newline.ts +82 -0
- package/src/parser/rules/inline/line-break/underscore.ts +45 -0
- package/src/parser/rules/inline/link-anchor.ts +6 -81
- package/src/parser/rules/inline/link-bracket/anchor.ts +3 -0
- package/src/parser/rules/inline/link-bracket/direct-url.ts +5 -0
- package/src/parser/rules/inline/link-bracket/parsed.ts +81 -0
- package/src/parser/rules/inline/link-bracket/parts.ts +64 -0
- package/src/parser/rules/inline/link-bracket/prefix.ts +15 -0
- package/src/parser/rules/inline/link-single.ts +7 -98
- package/src/parser/rules/inline/link-star.ts +7 -69
- package/src/parser/rules/inline/link-triple/fallback.ts +10 -0
- package/src/parser/rules/inline/link-triple/index.ts +62 -0
- package/src/parser/rules/inline/link-triple/interwiki.ts +11 -0
- package/src/parser/rules/inline/link-triple/label.ts +35 -0
- package/src/parser/rules/inline/link-triple/syntax.ts +72 -0
- package/src/parser/rules/inline/link-triple/target.ts +36 -0
- package/src/parser/rules/inline/math-inline/index.ts +40 -0
- package/src/parser/rules/inline/math-inline/syntax.ts +55 -0
- package/src/parser/rules/inline/monospace.ts +2 -30
- package/src/parser/rules/inline/parsing/block-boundary.ts +42 -0
- package/src/parser/rules/inline/parsing/block-start-predicates.ts +117 -0
- package/src/parser/rules/inline/parsing/collect.ts +23 -0
- package/src/parser/rules/inline/parsing/inline-content.ts +115 -0
- package/src/parser/rules/inline/parsing/paragraph-boundary.ts +47 -0
- package/src/parser/rules/inline/parsing/plain-text.ts +69 -0
- package/src/parser/rules/inline/parsing/preserved-line-break.ts +11 -0
- package/src/parser/rules/inline/parsing/rules.ts +34 -0
- package/src/parser/rules/inline/parsing/simple-token.ts +26 -0
- package/src/parser/rules/inline/raw/angle.ts +40 -0
- package/src/parser/rules/inline/raw/double-at.ts +78 -0
- package/src/parser/rules/inline/raw/index.ts +26 -0
- package/src/parser/rules/inline/raw/result.ts +26 -0
- package/src/parser/rules/inline/size/content.ts +65 -0
- package/src/parser/rules/inline/size/index.ts +55 -0
- package/src/parser/rules/inline/size/open.ts +43 -0
- package/src/parser/rules/inline/size/value.ts +45 -0
- package/src/parser/rules/inline/span/content.ts +97 -0
- package/src/parser/rules/inline/span/elements.ts +108 -0
- package/src/parser/rules/inline/span/index.ts +79 -0
- package/src/parser/rules/inline/span/newline.ts +50 -0
- package/src/parser/rules/inline/span/syntax.ts +70 -0
- package/src/parser/rules/inline/{strikethrough.ts → strikethrough/index.ts} +5 -60
- package/src/parser/rules/inline/strikethrough/parse.ts +14 -0
- package/src/parser/rules/inline/strikethrough/syntax.ts +24 -0
- package/src/parser/rules/inline/subscript.ts +2 -39
- package/src/parser/rules/inline/superscript.ts +4 -39
- package/src/parser/rules/inline/text/element.ts +5 -0
- package/src/parser/rules/inline/{text.ts → text/index.ts} +5 -4
- package/src/parser/rules/inline/underline/child.ts +26 -0
- package/src/parser/rules/inline/underline/content.ts +29 -0
- package/src/parser/rules/inline/{underline.ts → underline/index.ts} +6 -49
- package/src/parser/rules/inline/user/element.ts +11 -0
- package/src/parser/rules/inline/user/index.ts +34 -0
- package/src/parser/rules/inline/user/syntax.ts +67 -0
- package/src/parser/rules/inline/utils.ts +4 -344
- package/src/parser/rules/tokens.ts +106 -0
- package/src/parser/rules/types.ts +9 -252
- package/src/parser/depth.ts +0 -251
- package/src/parser/parse.ts +0 -315
- package/src/parser/postprocess/spanStrip.ts +0 -697
- package/src/parser/preprocess/expr.ts +0 -265
- package/src/parser/preprocess/utils.ts +0 -250
- package/src/parser/preprocess/whitespace.ts +0 -111
- package/src/parser/rules/block/align.ts +0 -282
- package/src/parser/rules/block/bibliography.ts +0 -359
- package/src/parser/rules/block/block-list.ts +0 -689
- package/src/parser/rules/block/blockquote.ts +0 -238
- package/src/parser/rules/block/code.ts +0 -187
- package/src/parser/rules/block/collapsible.ts +0 -337
- package/src/parser/rules/block/definition-list.ts +0 -270
- package/src/parser/rules/block/div.ts +0 -400
- package/src/parser/rules/block/embed-block.ts +0 -153
- package/src/parser/rules/block/footnoteblock.ts +0 -200
- package/src/parser/rules/block/heading.ts +0 -142
- package/src/parser/rules/block/html.ts +0 -222
- package/src/parser/rules/block/iframe.ts +0 -239
- package/src/parser/rules/block/include.ts +0 -179
- package/src/parser/rules/block/list.ts +0 -244
- package/src/parser/rules/block/math.ts +0 -183
- package/src/parser/rules/block/module/include/resolve.ts +0 -556
- package/src/parser/rules/block/module/listpages/types.ts +0 -513
- package/src/parser/rules/block/module/walk.ts +0 -380
- package/src/parser/rules/block/module.ts +0 -164
- package/src/parser/rules/block/orphan-li.ts +0 -177
- package/src/parser/rules/block/paragraph.ts +0 -157
- package/src/parser/rules/block/table-block.ts +0 -726
- package/src/parser/rules/block/table.ts +0 -441
- package/src/parser/rules/block/tabview.ts +0 -331
- package/src/parser/rules/block/toc.ts +0 -129
- package/src/parser/rules/inline/anchor-name.ts +0 -154
- package/src/parser/rules/inline/anchor.ts +0 -327
- package/src/parser/rules/inline/bibcite.ts +0 -153
- package/src/parser/rules/inline/color.ts +0 -140
- package/src/parser/rules/inline/equation-ref.ts +0 -115
- package/src/parser/rules/inline/expr.ts +0 -526
- package/src/parser/rules/inline/footnote.ts +0 -223
- package/src/parser/rules/inline/image.ts +0 -328
- package/src/parser/rules/inline/line-break.ts +0 -326
- package/src/parser/rules/inline/link-triple.ts +0 -267
- package/src/parser/rules/inline/math-inline.ts +0 -126
- package/src/parser/rules/inline/raw.ts +0 -262
- package/src/parser/rules/inline/size.ts +0 -244
- package/src/parser/rules/inline/span.ts +0 -424
- package/src/parser/rules/inline/user.ts +0 -147
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ParseContext } from "../../types";
|
|
2
|
+
|
|
3
|
+
export type CollapsibleAttributes = Record<string, string>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parses collapsible attributes that may be spread across multiple lines.
|
|
7
|
+
*/
|
|
8
|
+
export function parseMultilineAttributes(
|
|
9
|
+
ctx: ParseContext,
|
|
10
|
+
startPos: number,
|
|
11
|
+
): { attrs: CollapsibleAttributes; consumed: number } {
|
|
12
|
+
const attrs: CollapsibleAttributes = {};
|
|
13
|
+
let pos = startPos;
|
|
14
|
+
let consumed = 0;
|
|
15
|
+
|
|
16
|
+
while (pos < ctx.tokens.length) {
|
|
17
|
+
const token = ctx.tokens[pos];
|
|
18
|
+
if (!token || token.type === "BLOCK_CLOSE" || token.type === "EOF") {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (token.type === "WHITESPACE" || token.type === "NEWLINE") {
|
|
23
|
+
pos++;
|
|
24
|
+
consumed++;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (token.type === "TEXT" || token.type === "IDENTIFIER") {
|
|
29
|
+
let name = token.value;
|
|
30
|
+
pos++;
|
|
31
|
+
consumed++;
|
|
32
|
+
|
|
33
|
+
while (
|
|
34
|
+
ctx.tokens[pos]?.type === "TEXT" &&
|
|
35
|
+
ctx.tokens[pos]?.value === "-" &&
|
|
36
|
+
(ctx.tokens[pos + 1]?.type === "IDENTIFIER" || ctx.tokens[pos + 1]?.type === "TEXT")
|
|
37
|
+
) {
|
|
38
|
+
name += "-";
|
|
39
|
+
pos++;
|
|
40
|
+
consumed++;
|
|
41
|
+
name += ctx.tokens[pos]?.value ?? "";
|
|
42
|
+
pos++;
|
|
43
|
+
consumed++;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const eqToken = ctx.tokens[pos];
|
|
47
|
+
if (eqToken?.type === "EQUALS") {
|
|
48
|
+
pos++;
|
|
49
|
+
consumed++;
|
|
50
|
+
const valueToken = ctx.tokens[pos];
|
|
51
|
+
if (valueToken?.type === "QUOTED_STRING") {
|
|
52
|
+
let value = valueToken.value;
|
|
53
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
54
|
+
value = value.slice(1, -1);
|
|
55
|
+
}
|
|
56
|
+
attrs[name] = value;
|
|
57
|
+
pos++;
|
|
58
|
+
consumed++;
|
|
59
|
+
} else if (valueToken?.type === "TEXT" || valueToken?.type === "IDENTIFIER") {
|
|
60
|
+
attrs[name] = valueToken.value;
|
|
61
|
+
pos++;
|
|
62
|
+
consumed++;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
attrs[name] = "true";
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return { attrs, consumed };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface CollapsibleToggleVisibility {
|
|
76
|
+
showTop: boolean;
|
|
77
|
+
showBottom: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function resolveToggleVisibility(
|
|
81
|
+
attrs: Record<string, string>,
|
|
82
|
+
): CollapsibleToggleVisibility {
|
|
83
|
+
const hideLocation = (attrs.hideLocation ?? attrs.hidelocation ?? "top").toLowerCase();
|
|
84
|
+
|
|
85
|
+
if (hideLocation === "both") {
|
|
86
|
+
return { showTop: true, showBottom: true };
|
|
87
|
+
}
|
|
88
|
+
if (hideLocation === "bottom") {
|
|
89
|
+
return { showTop: false, showBottom: true };
|
|
90
|
+
}
|
|
91
|
+
if (hideLocation === "neither" || hideLocation === "none") {
|
|
92
|
+
return { showTop: false, showBottom: false };
|
|
93
|
+
}
|
|
94
|
+
return { showTop: true, showBottom: false };
|
|
95
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Element } from "@wdprlib/ast";
|
|
2
|
+
import type { ParseContext } from "../../types";
|
|
3
|
+
import { parseBlocksUntil } from "../utils";
|
|
4
|
+
import { isCollapsibleClose } from "./tags";
|
|
5
|
+
|
|
6
|
+
const EXCLUDED_BLOCKS = new Set(["collapsible"]);
|
|
7
|
+
|
|
8
|
+
export function parseCollapsibleBody(
|
|
9
|
+
ctx: ParseContext,
|
|
10
|
+
startPos: number,
|
|
11
|
+
hasNewlineAfterOpen: boolean,
|
|
12
|
+
): { elements: Element[]; consumed: number } {
|
|
13
|
+
if (
|
|
14
|
+
!hasNewlineAfterOpen &&
|
|
15
|
+
ctx.tokens[startPos]?.type !== "EOF" &&
|
|
16
|
+
ctx.tokens[startPos]?.type !== "BLOCK_END_OPEN"
|
|
17
|
+
) {
|
|
18
|
+
return parseInlineCollapsibleBody(ctx, startPos);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const bodyCtx: ParseContext = { ...ctx, pos: startPos };
|
|
22
|
+
const closeCondition = (checkCtx: ParseContext): boolean => {
|
|
23
|
+
return isCollapsibleClose(checkCtx, checkCtx.pos);
|
|
24
|
+
};
|
|
25
|
+
const bodyResult = parseBlocksUntil(bodyCtx, closeCondition, {
|
|
26
|
+
excludedBlockNames: EXCLUDED_BLOCKS,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
elements: bodyResult.elements,
|
|
31
|
+
consumed: bodyResult.consumed,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseInlineCollapsibleBody(
|
|
36
|
+
ctx: ParseContext,
|
|
37
|
+
startPos: number,
|
|
38
|
+
): { elements: Element[]; consumed: number } {
|
|
39
|
+
const inlineElements: Element[] = [];
|
|
40
|
+
let pos = startPos;
|
|
41
|
+
let consumed = 0;
|
|
42
|
+
|
|
43
|
+
while (pos < ctx.tokens.length) {
|
|
44
|
+
const token = ctx.tokens[pos];
|
|
45
|
+
if (!token || token.type === "EOF" || token.type === "NEWLINE") break;
|
|
46
|
+
if (isCollapsibleClose(ctx, pos)) break;
|
|
47
|
+
inlineElements.push({ element: "text", data: token.value });
|
|
48
|
+
pos++;
|
|
49
|
+
consumed++;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (inlineElements.length === 0) {
|
|
53
|
+
return { elements: [], consumed };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
elements: [
|
|
58
|
+
{
|
|
59
|
+
element: "container",
|
|
60
|
+
data: {
|
|
61
|
+
type: "paragraph",
|
|
62
|
+
attributes: {},
|
|
63
|
+
elements: inlineElements,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
consumed,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block rule for Wikidot collapsible blocks: `[[collapsible]]...[[/collapsible]]`.
|
|
3
|
+
*
|
|
4
|
+
* A collapsible renders as a show/hide toggle with body content that can
|
|
5
|
+
* be expanded or collapsed. The opening tag accepts several attributes
|
|
6
|
+
* (which may span multiple lines):
|
|
7
|
+
*
|
|
8
|
+
* - `show` -- label text for the "show" link (default: "+ show block").
|
|
9
|
+
* - `hide` -- label text for the "hide" link (default: "- hide block").
|
|
10
|
+
* - `folded` -- when `"no"`, the block starts in the expanded state.
|
|
11
|
+
* - `hideLocation` -- where the toggle link appears: `"top"` (default),
|
|
12
|
+
* `"bottom"`, `"both"`, or `"neither"`/`"none"`.
|
|
13
|
+
*
|
|
14
|
+
* Key Wikidot-specific behaviours:
|
|
15
|
+
* - Collapsibles cannot nest. When the body parser encounters a second
|
|
16
|
+
* `[[collapsible]]`, it is treated as plain text. This is achieved by
|
|
17
|
+
* filtering the collapsible rule out of the block rule list for body parsing.
|
|
18
|
+
* - Orphaned `[[/collapsible]]` tags after the matched close are consumed and
|
|
19
|
+
* emitted as `<br />` + literal text, matching Wikidot rendering.
|
|
20
|
+
* - An inline form (`[[collapsible]]text[[/collapsible]]` on one line) is
|
|
21
|
+
* supported but uncommon.
|
|
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 { resolveToggleVisibility } from "./attributes";
|
|
29
|
+
import { parseCollapsibleBody } from "./body";
|
|
30
|
+
import { parseCollapsibleOpen } from "./open";
|
|
31
|
+
import { consumeOrphanedCollapsibleCloses } from "./orphans";
|
|
32
|
+
import { consumeCollapsibleCloseTag, isCollapsibleClose } from "./tags";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Block rule for `[[collapsible ...]]...[[/collapsible]]`.
|
|
36
|
+
*
|
|
37
|
+
* Parsing strategy:
|
|
38
|
+
* 1. Match BLOCK_OPEN + name "collapsible".
|
|
39
|
+
* 2. Parse multiline attributes (show, hide, folded, hideLocation, etc.).
|
|
40
|
+
* 3. If a NEWLINE follows the opening tag, parse body as block content
|
|
41
|
+
* with the collapsible rule itself excluded (to prevent nesting).
|
|
42
|
+
* Otherwise, parse inline content until close tag or end of line
|
|
43
|
+
* (inline form).
|
|
44
|
+
* 4. Consume the `[[/collapsible]]` closing tag.
|
|
45
|
+
* 5. Consume any orphaned `[[/collapsible]]` tags that follow, converting
|
|
46
|
+
* them to `<br />` + literal text.
|
|
47
|
+
* 6. Derive `show-top` / `show-bottom` booleans from the `hideLocation`
|
|
48
|
+
* attribute.
|
|
49
|
+
*/
|
|
50
|
+
export const collapsibleRule: BlockRule = {
|
|
51
|
+
name: "collapsible",
|
|
52
|
+
startTokens: ["BLOCK_OPEN"],
|
|
53
|
+
requiresLineStart: false,
|
|
54
|
+
|
|
55
|
+
parse(ctx: ParseContext): RuleResult<Element> {
|
|
56
|
+
const openToken = currentToken(ctx);
|
|
57
|
+
if (openToken.type !== "BLOCK_OPEN") {
|
|
58
|
+
return { success: false };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const openResult = parseCollapsibleOpen(ctx);
|
|
62
|
+
if (!openResult) {
|
|
63
|
+
return { success: false };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Record opening tag position for diagnostics
|
|
67
|
+
const openPosition = openToken.position;
|
|
68
|
+
|
|
69
|
+
let pos = openResult.bodyStart;
|
|
70
|
+
let consumed = openResult.consumed;
|
|
71
|
+
const bodyResult = parseCollapsibleBody(ctx, pos, openResult.hasNewlineAfterOpen);
|
|
72
|
+
consumed += bodyResult.consumed;
|
|
73
|
+
pos += bodyResult.consumed;
|
|
74
|
+
|
|
75
|
+
// Check for missing close tag
|
|
76
|
+
if (!isCollapsibleClose(ctx, pos)) {
|
|
77
|
+
ctx.diagnostics.push({
|
|
78
|
+
severity: "warning",
|
|
79
|
+
code: "unclosed-block",
|
|
80
|
+
message: "Missing closing tag [[/collapsible]] for [[collapsible]]",
|
|
81
|
+
position: openPosition,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Consume [[/collapsible]]
|
|
86
|
+
if (isCollapsibleClose(ctx, pos)) {
|
|
87
|
+
const closeConsumed = consumeCollapsibleCloseTag(ctx, pos);
|
|
88
|
+
consumed += closeConsumed;
|
|
89
|
+
pos += closeConsumed;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const orphanedResult = consumeOrphanedCollapsibleCloses(ctx, pos);
|
|
93
|
+
consumed += orphanedResult.consumed;
|
|
94
|
+
|
|
95
|
+
const toggleVisibility = resolveToggleVisibility(openResult.attrs);
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
success: true,
|
|
99
|
+
elements: [
|
|
100
|
+
{
|
|
101
|
+
element: "collapsible",
|
|
102
|
+
data: {
|
|
103
|
+
elements: bodyResult.elements,
|
|
104
|
+
attributes: {},
|
|
105
|
+
"start-open": openResult.attrs.folded === "no",
|
|
106
|
+
"show-text": openResult.attrs.show ?? null,
|
|
107
|
+
"hide-text": openResult.attrs.hide ?? null,
|
|
108
|
+
"show-top": toggleVisibility.showTop,
|
|
109
|
+
"show-bottom": toggleVisibility.showBottom,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
...orphanedResult.elements,
|
|
113
|
+
],
|
|
114
|
+
consumed,
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ParseContext } from "../../types";
|
|
2
|
+
import { parseBlockName } from "../utils";
|
|
3
|
+
import { parseMultilineAttributes, type CollapsibleAttributes } from "./attributes";
|
|
4
|
+
|
|
5
|
+
export interface CollapsibleOpenResult {
|
|
6
|
+
attrs: CollapsibleAttributes;
|
|
7
|
+
bodyStart: number;
|
|
8
|
+
consumed: number;
|
|
9
|
+
hasNewlineAfterOpen: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function parseCollapsibleOpen(ctx: ParseContext): CollapsibleOpenResult | null {
|
|
13
|
+
if (ctx.tokens[ctx.pos]?.type !== "BLOCK_OPEN") {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let pos = ctx.pos + 1;
|
|
18
|
+
let consumed = 1;
|
|
19
|
+
|
|
20
|
+
const nameResult = parseBlockName(ctx, pos);
|
|
21
|
+
if (!nameResult || nameResult.name !== "collapsible") {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
pos += nameResult.consumed;
|
|
26
|
+
consumed += nameResult.consumed;
|
|
27
|
+
|
|
28
|
+
const attrResult = parseMultilineAttributes(ctx, pos);
|
|
29
|
+
pos += attrResult.consumed;
|
|
30
|
+
consumed += attrResult.consumed;
|
|
31
|
+
|
|
32
|
+
if (ctx.tokens[pos]?.type !== "BLOCK_CLOSE") {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
pos++;
|
|
37
|
+
consumed++;
|
|
38
|
+
|
|
39
|
+
const hasNewlineAfterOpen = ctx.tokens[pos]?.type === "NEWLINE";
|
|
40
|
+
if (hasNewlineAfterOpen) {
|
|
41
|
+
pos++;
|
|
42
|
+
consumed++;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
attrs: attrResult.attrs,
|
|
47
|
+
bodyStart: pos,
|
|
48
|
+
consumed,
|
|
49
|
+
hasNewlineAfterOpen,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Element } from "@wdprlib/ast";
|
|
2
|
+
import type { ParseContext } from "../../types";
|
|
3
|
+
import { isCollapsibleClose } from "./tags";
|
|
4
|
+
|
|
5
|
+
export function consumeOrphanedCollapsibleCloses(
|
|
6
|
+
ctx: ParseContext,
|
|
7
|
+
startPos: number,
|
|
8
|
+
): { elements: Element[]; consumed: number } {
|
|
9
|
+
const elements: Element[] = [];
|
|
10
|
+
let pos = startPos;
|
|
11
|
+
let consumed = 0;
|
|
12
|
+
|
|
13
|
+
while (isCollapsibleClose(ctx, pos)) {
|
|
14
|
+
elements.push({ element: "line-break" });
|
|
15
|
+
|
|
16
|
+
while (pos < ctx.tokens.length) {
|
|
17
|
+
const token = ctx.tokens[pos];
|
|
18
|
+
if (!token || token.type === "NEWLINE" || token.type === "EOF") break;
|
|
19
|
+
elements.push({ element: "text", data: token.value });
|
|
20
|
+
consumed++;
|
|
21
|
+
pos++;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
25
|
+
consumed++;
|
|
26
|
+
pos++;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { elements, consumed };
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ParseContext } from "../../types";
|
|
2
|
+
import { parseBlockName } from "../utils";
|
|
3
|
+
|
|
4
|
+
export function isCollapsibleClose(ctx: ParseContext, pos: number): boolean {
|
|
5
|
+
if (ctx.tokens[pos]?.type !== "BLOCK_END_OPEN") return false;
|
|
6
|
+
const nameResult = parseBlockName(ctx, pos + 1);
|
|
7
|
+
return nameResult?.name === "collapsible";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function consumeCollapsibleCloseTag(ctx: ParseContext, pos: number): number {
|
|
11
|
+
let closeConsumed = 1;
|
|
12
|
+
const nameResult = parseBlockName(ctx, pos + 1);
|
|
13
|
+
if (nameResult) closeConsumed += nameResult.consumed;
|
|
14
|
+
if (ctx.tokens[pos + closeConsumed]?.type === "BLOCK_CLOSE") closeConsumed++;
|
|
15
|
+
if (ctx.tokens[pos + closeConsumed]?.type === "NEWLINE") closeConsumed++;
|
|
16
|
+
return closeConsumed;
|
|
17
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ParseContext } from "../../types";
|
|
2
|
+
|
|
3
|
+
export interface BlockCommentConsumeResult {
|
|
4
|
+
consumed: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function consumeBlockComment(ctx: ParseContext): BlockCommentConsumeResult | null {
|
|
8
|
+
let pos = ctx.pos + 1;
|
|
9
|
+
let consumed = 1;
|
|
10
|
+
|
|
11
|
+
while (pos < ctx.tokens.length) {
|
|
12
|
+
const token = ctx.tokens[pos];
|
|
13
|
+
if (!token) {
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (token.type === "COMMENT_CLOSE") {
|
|
18
|
+
consumed++;
|
|
19
|
+
pos++;
|
|
20
|
+
|
|
21
|
+
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
22
|
+
consumed++;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return { consumed };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (token.type === "EOF") {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pos++;
|
|
33
|
+
consumed++;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
* @module
|
|
17
17
|
*/
|
|
18
18
|
import type { Element } from "@wdprlib/ast";
|
|
19
|
-
import type { BlockRule, ParseContext, RuleResult } from "
|
|
19
|
+
import type { BlockRule, ParseContext, RuleResult } from "../../types";
|
|
20
|
+
import { consumeBlockComment } from "./consume";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Block rule for line-start comments (`[!-- ... --]`).
|
|
@@ -29,45 +30,18 @@ export const blockCommentRule: BlockRule = {
|
|
|
29
30
|
requiresLineStart: true,
|
|
30
31
|
|
|
31
32
|
parse(ctx: ParseContext): RuleResult<Element> {
|
|
32
|
-
|
|
33
|
-
let consumed = 1;
|
|
34
|
-
|
|
35
|
-
// Consume all tokens until we find --]
|
|
36
|
-
while (pos < ctx.tokens.length) {
|
|
37
|
-
const token = ctx.tokens[pos];
|
|
38
|
-
if (!token) {
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (token.type === "COMMENT_CLOSE") {
|
|
43
|
-
consumed++;
|
|
44
|
-
pos++;
|
|
45
|
-
|
|
46
|
-
// Consume trailing newline if present
|
|
47
|
-
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
48
|
-
consumed++;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Return empty elements - comment is discarded
|
|
52
|
-
return {
|
|
53
|
-
success: true,
|
|
54
|
-
elements: [],
|
|
55
|
-
consumed,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (token.type === "EOF") {
|
|
60
|
-
// Unterminated comment — let the inline comment rule emit the diagnostic
|
|
61
|
-
// to avoid duplication when the paragraph fallback retries this token.
|
|
62
|
-
return { success: false };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
pos++;
|
|
66
|
-
consumed++;
|
|
67
|
-
}
|
|
33
|
+
const result = consumeBlockComment(ctx);
|
|
68
34
|
|
|
69
35
|
// Unterminated comment — let the inline comment rule emit the diagnostic
|
|
70
36
|
// to avoid duplication when the paragraph fallback retries this token.
|
|
71
|
-
|
|
37
|
+
if (!result) {
|
|
38
|
+
return { success: false };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
success: true,
|
|
43
|
+
elements: [],
|
|
44
|
+
consumed: result.consumed,
|
|
45
|
+
};
|
|
72
46
|
},
|
|
73
47
|
};
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
* @module
|
|
20
20
|
*/
|
|
21
21
|
import type { Element } from "@wdprlib/ast";
|
|
22
|
-
import type { BlockRule, ParseContext, RuleResult } from "
|
|
23
|
-
import {
|
|
22
|
+
import type { BlockRule, ParseContext, RuleResult } from "../../types";
|
|
23
|
+
import { parseContentSeparatorSyntax } from "./syntax";
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Block rule for the content separator (`====`).
|
|
@@ -33,38 +33,8 @@ export const contentSeparatorRule: BlockRule = {
|
|
|
33
33
|
requiresLineStart: true,
|
|
34
34
|
|
|
35
35
|
parse(ctx: ParseContext): RuleResult<Element> {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
if (!first.lineStart) {
|
|
39
|
-
return { success: false };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Count consecutive = tokens at line start
|
|
43
|
-
let pos = ctx.pos;
|
|
44
|
-
let equalsCount = 0;
|
|
45
|
-
|
|
46
|
-
while (ctx.tokens[pos]?.type === "EQUALS") {
|
|
47
|
-
equalsCount++;
|
|
48
|
-
pos++;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Need at least 4 equals signs for content separator
|
|
52
|
-
if (equalsCount < 4) {
|
|
53
|
-
return { success: false };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Must be followed by newline or EOF
|
|
57
|
-
const nextToken = ctx.tokens[pos];
|
|
58
|
-
if (nextToken && nextToken.type !== "NEWLINE" && nextToken.type !== "EOF") {
|
|
59
|
-
return { success: false };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let consumed = equalsCount;
|
|
63
|
-
|
|
64
|
-
// Consume newline if present
|
|
65
|
-
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
66
|
-
consumed++;
|
|
67
|
-
}
|
|
36
|
+
const syntax = parseContentSeparatorSyntax(ctx);
|
|
37
|
+
if (!syntax) return { success: false };
|
|
68
38
|
|
|
69
39
|
return {
|
|
70
40
|
success: true,
|
|
@@ -73,7 +43,7 @@ export const contentSeparatorRule: BlockRule = {
|
|
|
73
43
|
element: "content-separator",
|
|
74
44
|
},
|
|
75
45
|
],
|
|
76
|
-
consumed,
|
|
46
|
+
consumed: syntax.consumed,
|
|
77
47
|
};
|
|
78
48
|
},
|
|
79
49
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ParseContext } from "../../types";
|
|
2
|
+
|
|
3
|
+
export interface ContentSeparatorSyntax {
|
|
4
|
+
consumed: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function parseContentSeparatorSyntax(ctx: ParseContext): ContentSeparatorSyntax | null {
|
|
8
|
+
const first = ctx.tokens[ctx.pos];
|
|
9
|
+
if (first?.type !== "EQUALS" || !first.lineStart) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let pos = ctx.pos;
|
|
14
|
+
let equalsCount = 0;
|
|
15
|
+
|
|
16
|
+
while (ctx.tokens[pos]?.type === "EQUALS") {
|
|
17
|
+
equalsCount++;
|
|
18
|
+
pos++;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (equalsCount < 4) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const nextToken = ctx.tokens[pos];
|
|
26
|
+
if (nextToken && nextToken.type !== "NEWLINE" && nextToken.type !== "EOF") {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
consumed: equalsCount + (nextToken?.type === "NEWLINE" ? 1 : 0),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ParseContext } from "../../types";
|
|
2
|
+
import { parseDefinitionItem, type ParsedDefinitionItem } from "./items";
|
|
3
|
+
|
|
4
|
+
export interface DefinitionListParseResult {
|
|
5
|
+
items: ParsedDefinitionItem[];
|
|
6
|
+
consumed: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function collectDefinitionItems(ctx: ParseContext): DefinitionListParseResult {
|
|
10
|
+
const items: ParsedDefinitionItem[] = [];
|
|
11
|
+
let pos = ctx.pos;
|
|
12
|
+
let consumed = 0;
|
|
13
|
+
|
|
14
|
+
while (pos < ctx.tokens.length) {
|
|
15
|
+
const token = ctx.tokens[pos];
|
|
16
|
+
if (!token || token.type === "EOF") {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (token.type !== "COLON" || !token.lineStart) {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const result = parseDefinitionItem(ctx, pos);
|
|
25
|
+
if (!result) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
items.push(result.item);
|
|
30
|
+
pos += result.consumed;
|
|
31
|
+
consumed += result.consumed;
|
|
32
|
+
|
|
33
|
+
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
34
|
+
pos++;
|
|
35
|
+
consumed++;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return { items, consumed };
|
|
40
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Block rule for Wikidot definition lists written with the `: key : value` syntax.
|
|
4
|
+
*
|
|
5
|
+
* Each item starts at the beginning of a line with a COLON, followed by
|
|
6
|
+
* mandatory whitespace, the key (term), a second COLON, and then the value
|
|
7
|
+
* (definition). Multiple consecutive items form a single `<dl>` block.
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* : Apple : A fruit that grows on trees.
|
|
11
|
+
* : Banana : A yellow curved fruit.
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Key parsing details:
|
|
15
|
+
* - Whitespace after the first colon is required (`": key"` not `":key"`).
|
|
16
|
+
* - The key portion supports inline markup (bold, links, etc.).
|
|
17
|
+
* - The value continues until a double newline, a new definition entry, or
|
|
18
|
+
* the end of the document.
|
|
19
|
+
* - A single newline within the value does NOT break the entry -- parsing
|
|
20
|
+
* continues on the next line.
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import type { Element } from "@wdprlib/ast";
|
|
25
|
+
import type { BlockRule, ParseContext, RuleResult } from "../../types";
|
|
26
|
+
import { collectDefinitionItems } from "./collect";
|
|
27
|
+
import { toDefinitionListItems } from "./items";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Block rule for Wikidot definition lists (`: key : value`).
|
|
31
|
+
*
|
|
32
|
+
* Parsing strategy:
|
|
33
|
+
* 1. Verify the first token is a line-start COLON.
|
|
34
|
+
* 2. Repeatedly call `parseDefinitionItem()` to collect entries.
|
|
35
|
+
* 3. Stop when the current token is no longer a line-start COLON (i.e.
|
|
36
|
+
* the definition list block has ended).
|
|
37
|
+
* 4. Convert internal items into the AST {@link DefinitionListItem} format.
|
|
38
|
+
* 5. Emit a single `definition-list` element.
|
|
39
|
+
*/
|
|
40
|
+
export const definitionListRule: BlockRule = {
|
|
41
|
+
name: "definitionList",
|
|
42
|
+
startTokens: ["COLON"],
|
|
43
|
+
requiresLineStart: true,
|
|
44
|
+
|
|
45
|
+
parse(ctx: ParseContext): RuleResult<Element> {
|
|
46
|
+
const result = collectDefinitionItems(ctx);
|
|
47
|
+
|
|
48
|
+
if (result.items.length === 0) {
|
|
49
|
+
return { success: false };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
success: true,
|
|
54
|
+
elements: [
|
|
55
|
+
{
|
|
56
|
+
element: "definition-list",
|
|
57
|
+
data: toDefinitionListItems(result.items),
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
consumed: result.consumed,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|