@wdprlib/parser 3.1.2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +10456 -8230
- package/dist/index.d.cts +313 -337
- package/dist/index.d.ts +313 -337
- package/dist/index.js +10460 -8234
- package/package.json +5 -3
- package/src/index.ts +170 -0
- package/src/lexer/anchor.ts +48 -0
- package/src/lexer/index.ts +21 -0
- package/src/lexer/lexer.ts +201 -0
- package/src/lexer/options.ts +19 -0
- package/src/lexer/punctuation.ts +70 -0
- package/src/lexer/quoted-string.ts +16 -0
- package/src/lexer/runs.ts +85 -0
- package/src/lexer/spacing-actions.ts +24 -0
- package/src/lexer/state.ts +103 -0
- package/src/lexer/syntax-actions.ts +80 -0
- package/src/lexer/text-actions.ts +41 -0
- package/src/lexer/token-actions.ts +136 -0
- package/src/lexer/token-factory.ts +62 -0
- package/src/lexer/tokenize.ts +18 -0
- package/src/lexer/tokens.ts +141 -0
- package/src/parser/constants.ts +175 -0
- package/src/parser/depth/index.ts +111 -0
- package/src/parser/depth/stack.ts +82 -0
- package/src/parser/index.ts +18 -0
- package/src/parser/parse/block.ts +42 -0
- package/src/parser/parse/context.ts +26 -0
- package/src/parser/parse/footnotes.ts +25 -0
- package/src/parser/parse/index.ts +42 -0
- package/src/parser/parse/options.ts +34 -0
- package/src/parser/parse/parser.ts +79 -0
- package/src/parser/parse/plain-non-ascii.ts +129 -0
- package/src/parser/parse/result.ts +57 -0
- package/src/parser/parse/source.ts +11 -0
- package/src/parser/postprocess/divAdjacentParagraph.ts +76 -0
- package/src/parser/postprocess/index.ts +15 -0
- package/src/parser/postprocess/spanStrip/clean-element.ts +168 -0
- package/src/parser/postprocess/spanStrip/cleanup.ts +25 -0
- package/src/parser/postprocess/spanStrip/empty-spans.ts +36 -0
- package/src/parser/postprocess/spanStrip/escaped.ts +78 -0
- package/src/parser/postprocess/spanStrip/factory.ts +23 -0
- package/src/parser/postprocess/spanStrip/index.ts +8 -0
- package/src/parser/postprocess/spanStrip/merge.ts +117 -0
- package/src/parser/postprocess/spanStrip/predicates.ts +59 -0
- package/src/parser/postprocess/spanStrip/split.ts +67 -0
- package/src/parser/preprocess/expr/chars.ts +15 -0
- package/src/parser/preprocess/expr/evaluate.ts +22 -0
- package/src/parser/preprocess/expr/index.ts +45 -0
- package/src/parser/preprocess/expr/kind.ts +19 -0
- package/src/parser/preprocess/expr/parse.ts +103 -0
- package/src/parser/preprocess/expr/scan.ts +34 -0
- package/src/parser/preprocess/expr/types.ts +14 -0
- package/src/parser/preprocess/index.ts +38 -0
- package/src/parser/preprocess/typography.ts +132 -0
- package/src/parser/preprocess/utils/bracket-depths.ts +98 -0
- package/src/parser/preprocess/utils/index.ts +13 -0
- package/src/parser/preprocess/utils/raw-regions.ts +153 -0
- package/src/parser/preprocess/whitespace/detection.ts +39 -0
- package/src/parser/preprocess/whitespace/index.ts +79 -0
- package/src/parser/preprocess/whitespace/leading-spaces.ts +11 -0
- package/src/parser/preprocess/whitespace/patterns.ts +23 -0
- package/src/parser/rules/block/align/body.ts +46 -0
- package/src/parser/rules/block/align/element.ts +13 -0
- package/src/parser/rules/block/align/index.ts +90 -0
- package/src/parser/rules/block/align/syntax.ts +113 -0
- package/src/parser/rules/block/bibliography/body.ts +81 -0
- package/src/parser/rules/block/bibliography/entries.ts +49 -0
- package/src/parser/rules/block/bibliography/entry-content.ts +73 -0
- package/src/parser/rules/block/bibliography/entry-key.ts +83 -0
- package/src/parser/rules/block/bibliography/index.ts +90 -0
- package/src/parser/rules/block/bibliography/open.ts +53 -0
- package/src/parser/rules/block/block-list/bare-content.ts +105 -0
- package/src/parser/rules/block/block-list/bare-paragraph.ts +60 -0
- package/src/parser/rules/block/block-list/index.ts +51 -0
- package/src/parser/rules/block/block-list/item-content.ts +132 -0
- package/src/parser/rules/block/block-list/li-content.ts +107 -0
- package/src/parser/rules/block/block-list/li-item.ts +77 -0
- package/src/parser/rules/block/block-list/list-block.ts +100 -0
- package/src/parser/rules/block/block-list/open.ts +51 -0
- package/src/parser/rules/block/block-list/tags.ts +50 -0
- package/src/parser/rules/block/blockquote/build.ts +62 -0
- package/src/parser/rules/block/blockquote/index.ts +80 -0
- package/src/parser/rules/block/blockquote/line.ts +79 -0
- package/src/parser/rules/block/blockquote/lines.ts +39 -0
- package/src/parser/rules/block/center/index.ts +72 -0
- package/src/parser/rules/block/center/open.ts +27 -0
- package/src/parser/rules/block/clear-float/index.ts +51 -0
- package/src/parser/rules/block/clear-float/syntax.ts +43 -0
- package/src/parser/rules/block/code/attributes.ts +30 -0
- package/src/parser/rules/block/code/content.ts +57 -0
- package/src/parser/rules/block/code/index.ts +100 -0
- package/src/parser/rules/block/collapsible/attributes.ts +95 -0
- package/src/parser/rules/block/collapsible/body.ts +69 -0
- package/src/parser/rules/block/collapsible/index.ts +117 -0
- package/src/parser/rules/block/collapsible/open.ts +51 -0
- package/src/parser/rules/block/collapsible/orphans.ts +31 -0
- package/src/parser/rules/block/collapsible/tags.ts +17 -0
- package/src/parser/rules/block/comment/consume.ts +37 -0
- package/src/parser/rules/block/comment/index.ts +47 -0
- package/src/parser/rules/block/content-separator/index.ts +49 -0
- package/src/parser/rules/block/content-separator/syntax.ts +33 -0
- package/src/parser/rules/block/definition-list/collect.ts +40 -0
- package/src/parser/rules/block/definition-list/index.ts +63 -0
- package/src/parser/rules/block/definition-list/item-key.ts +95 -0
- package/src/parser/rules/block/definition-list/item-value.ts +56 -0
- package/src/parser/rules/block/definition-list/items.ts +54 -0
- package/src/parser/rules/block/div/body.ts +41 -0
- package/src/parser/rules/block/div/close.ts +41 -0
- package/src/parser/rules/block/div/failed.ts +117 -0
- package/src/parser/rules/block/div/index.ts +112 -0
- package/src/parser/rules/block/div/nesting.ts +37 -0
- package/src/parser/rules/block/div/open.ts +59 -0
- package/src/parser/rules/block/div/paragraph-strip.ts +44 -0
- package/src/parser/rules/block/embed-block/content.ts +53 -0
- package/src/parser/rules/block/embed-block/index.ts +91 -0
- package/src/parser/rules/block/embed-block/open.ts +52 -0
- package/src/parser/rules/block/embed-block/tags.ts +5 -0
- package/src/parser/rules/block/footnoteblock/attributes.ts +73 -0
- package/src/parser/rules/block/footnoteblock/index.ts +82 -0
- package/src/parser/rules/block/footnoteblock/open.ts +53 -0
- package/src/parser/rules/block/heading/index.ts +87 -0
- package/src/parser/rules/block/heading/open.ts +50 -0
- package/src/parser/rules/block/heading/toc-text.ts +26 -0
- package/src/parser/rules/block/horizontal-rule/index.ts +44 -0
- package/src/parser/rules/block/horizontal-rule/syntax.ts +21 -0
- package/src/parser/rules/block/html/body.ts +114 -0
- package/src/parser/rules/block/html/diagnostics.ts +11 -0
- package/src/parser/rules/block/html/index.ts +95 -0
- package/src/parser/rules/block/html/open.ts +36 -0
- package/src/parser/rules/block/iframe/attributes.ts +106 -0
- package/src/parser/rules/block/iframe/index.ts +73 -0
- package/src/parser/rules/block/iframe/open.ts +58 -0
- package/src/parser/rules/block/iframe/source.ts +24 -0
- package/src/parser/rules/block/iframe/url.ts +38 -0
- package/src/parser/rules/block/iftags/body.ts +48 -0
- package/src/parser/rules/block/iftags/condition.ts +24 -0
- package/src/parser/rules/block/iftags/index.ts +108 -0
- package/src/parser/rules/block/include/arguments.ts +48 -0
- package/src/parser/rules/block/include/index.ts +75 -0
- package/src/parser/rules/block/include/location.ts +24 -0
- package/src/parser/rules/block/include/variables.ts +37 -0
- package/src/parser/rules/block/index.ts +127 -0
- package/src/parser/rules/block/list/index.ts +73 -0
- package/src/parser/rules/block/list/line.ts +77 -0
- package/src/parser/rules/block/list/native.ts +89 -0
- package/src/parser/rules/block/math/content.ts +54 -0
- package/src/parser/rules/block/math/index.ts +106 -0
- package/src/parser/rules/block/math/name.ts +35 -0
- package/src/parser/rules/block/module/backlinks/index.ts +31 -0
- package/src/parser/rules/block/module/backlinks/types.ts +21 -0
- package/src/parser/rules/block/module/body.ts +92 -0
- package/src/parser/rules/block/module/categories/index.ts +34 -0
- package/src/parser/rules/block/module/categories/types.ts +21 -0
- package/src/parser/rules/block/module/css/index.ts +37 -0
- package/src/parser/rules/block/module/element.ts +33 -0
- package/src/parser/rules/block/module/iftags/condition.ts +109 -0
- package/src/parser/rules/block/module/iftags/index.ts +26 -0
- package/src/parser/rules/block/module/iftags/preprocess.ts +140 -0
- package/src/parser/rules/block/module/iftags/resolve.ts +73 -0
- package/src/parser/rules/block/module/iftags/types.ts +63 -0
- package/src/parser/rules/block/module/include/directive.ts +91 -0
- package/src/parser/rules/block/module/include/index.ts +29 -0
- package/src/parser/rules/block/module/include/references.ts +42 -0
- package/src/parser/rules/block/module/include/resolve/cache.ts +44 -0
- package/src/parser/rules/block/module/include/resolve/index.ts +106 -0
- package/src/parser/rules/block/module/include/resolve/iterate.ts +202 -0
- package/src/parser/rules/block/module/include/resolve/replace.ts +31 -0
- package/src/parser/rules/block/module/include/resolve/types.ts +105 -0
- package/src/parser/rules/block/module/include/scanner.ts +121 -0
- package/src/parser/rules/block/module/index.ts +134 -0
- package/src/parser/rules/block/module/join/index.ts +34 -0
- package/src/parser/rules/block/module/join/types.ts +23 -0
- package/src/parser/rules/block/module/listpages/compiler.ts +73 -0
- package/src/parser/rules/block/module/listpages/extract.ts +76 -0
- package/src/parser/rules/block/module/listpages/extraction/listpages.ts +42 -0
- package/src/parser/rules/block/module/listpages/extraction/listusers.ts +30 -0
- package/src/parser/rules/block/module/listpages/extraction/query.ts +51 -0
- package/src/parser/rules/block/module/listpages/extraction/result.ts +18 -0
- package/src/parser/rules/block/module/listpages/extraction/template.ts +96 -0
- package/src/parser/rules/block/module/listpages/extraction/variables.ts +58 -0
- package/src/parser/rules/block/module/listpages/index.ts +83 -0
- package/src/parser/rules/block/module/listpages/normalization/date-selector.ts +53 -0
- package/src/parser/rules/block/module/listpages/normalization/numeric-selector.ts +32 -0
- package/src/parser/rules/block/module/listpages/normalization/order-parent.ts +82 -0
- package/src/parser/rules/block/module/listpages/normalization/selectors.ts +2 -0
- package/src/parser/rules/block/module/listpages/normalization/tags-category.ts +86 -0
- package/src/parser/rules/block/module/listpages/normalize.ts +74 -0
- package/src/parser/rules/block/module/listpages/parser.ts +106 -0
- package/src/parser/rules/block/module/listpages/resolution/items.ts +43 -0
- package/src/parser/rules/block/module/listpages/resolution/wrapper.ts +42 -0
- package/src/parser/rules/block/module/listpages/resolve.ts +60 -0
- package/src/parser/rules/block/module/listpages/template/format/content.ts +41 -0
- package/src/parser/rules/block/module/listpages/template/format/date.ts +116 -0
- package/src/parser/rules/block/module/listpages/template/format/index.ts +4 -0
- package/src/parser/rules/block/module/listpages/template/format/tags.ts +7 -0
- package/src/parser/rules/block/module/listpages/template/format/user.ts +9 -0
- package/src/parser/rules/block/module/listpages/template/getters/index.ts +36 -0
- package/src/parser/rules/block/module/listpages/template/getters/parameterized.ts +60 -0
- package/src/parser/rules/block/module/listpages/template/getters/simple.ts +65 -0
- package/src/parser/rules/block/module/listpages/template/getters/types.ts +3 -0
- package/src/parser/rules/block/module/listpages/template/syntax.ts +97 -0
- package/src/parser/rules/block/module/listpages/types/data-fetcher.ts +15 -0
- package/src/parser/rules/block/module/listpages/types/data-requirements.ts +52 -0
- package/src/parser/rules/block/module/listpages/types/external-data.ts +77 -0
- package/src/parser/rules/block/module/listpages/types/index.ts +17 -0
- package/src/parser/rules/block/module/listpages/types/normalized-query.ts +120 -0
- package/src/parser/rules/block/module/listpages/types/query.ts +67 -0
- package/src/parser/rules/block/module/listpages/types/template.ts +17 -0
- package/src/parser/rules/block/module/listpages/types/variables.ts +69 -0
- package/src/parser/rules/block/module/listpages/url-resolution/fields.ts +48 -0
- package/src/parser/rules/block/module/listpages/url-resolution/params.ts +19 -0
- package/src/parser/rules/block/module/listpages/url-resolution/query.ts +24 -0
- package/src/parser/rules/block/module/listpages/url-resolution/resolve.ts +53 -0
- package/src/parser/rules/block/module/listpages/url-resolution/value.ts +25 -0
- package/src/parser/rules/block/module/listpages/url-resolver.ts +29 -0
- package/src/parser/rules/block/module/listusers/compiler.ts +56 -0
- package/src/parser/rules/block/module/listusers/extract.ts +40 -0
- package/src/parser/rules/block/module/listusers/getters.ts +21 -0
- package/src/parser/rules/block/module/listusers/index.ts +36 -0
- package/src/parser/rules/block/module/listusers/parser.ts +54 -0
- package/src/parser/rules/block/module/listusers/resolve.ts +58 -0
- package/src/parser/rules/block/module/listusers/types.ts +93 -0
- package/src/parser/rules/block/module/listusers/variables.ts +15 -0
- package/src/parser/rules/block/module/mapping.ts +61 -0
- package/src/parser/rules/block/module/open.ts +57 -0
- package/src/parser/rules/block/module/page-tree/index.ts +38 -0
- package/src/parser/rules/block/module/page-tree/types.ts +29 -0
- package/src/parser/rules/block/module/rate/index.ts +28 -0
- package/src/parser/rules/block/module/rate/types.ts +19 -0
- package/src/parser/rules/block/module/resolution/contexts.ts +78 -0
- package/src/parser/rules/block/module/resolution/data-maps.ts +39 -0
- package/src/parser/rules/block/module/resolution/dynamic-modules.ts +93 -0
- package/src/parser/rules/block/module/resolution/styles.ts +53 -0
- package/src/parser/rules/block/module/resolution/walk-resolve.ts +107 -0
- package/src/parser/rules/block/module/resolve.ts +198 -0
- package/src/parser/rules/block/module/rule.ts +56 -0
- package/src/parser/rules/block/module/types-common.ts +70 -0
- package/src/parser/rules/block/module/types.ts +61 -0
- package/src/parser/rules/block/module/utils.ts +43 -0
- package/src/parser/rules/block/module/walk/children.ts +35 -0
- package/src/parser/rules/block/module/walk/index.ts +9 -0
- package/src/parser/rules/block/module/walk/map/index.ts +2 -0
- package/src/parser/rules/block/module/walk/map/stateful-definition-list.ts +25 -0
- package/src/parser/rules/block/module/walk/map/stateful-list.ts +40 -0
- package/src/parser/rules/block/module/walk/map/stateful-table.ts +23 -0
- package/src/parser/rules/block/module/walk/map/stateful-tabs.ts +19 -0
- package/src/parser/rules/block/module/walk/map/stateful.ts +71 -0
- package/src/parser/rules/block/module/walk/map/stateless-definition-list.ts +12 -0
- package/src/parser/rules/block/module/walk/map/stateless-list.ts +29 -0
- package/src/parser/rules/block/module/walk/map/stateless-table.ts +11 -0
- package/src/parser/rules/block/module/walk/map/stateless-tabs.ts +5 -0
- package/src/parser/rules/block/module/walk/map/stateless.ts +51 -0
- package/src/parser/rules/block/module/walk/map/types.ts +6 -0
- package/src/parser/rules/block/module/walk/traverse.ts +65 -0
- package/src/parser/rules/block/orphan-li/content.ts +60 -0
- package/src/parser/rules/block/orphan-li/index.ts +75 -0
- package/src/parser/rules/block/orphan-li/open.ts +25 -0
- package/src/parser/rules/block/orphan-li/tags.ts +40 -0
- package/src/parser/rules/block/paragraph/content.ts +12 -0
- package/src/parser/rules/block/paragraph/index.ts +60 -0
- package/src/parser/rules/block/paragraph/normalize.ts +52 -0
- package/src/parser/rules/block/paragraph/span-markers.ts +52 -0
- package/src/parser/rules/block/parsing/attributes/index.ts +32 -0
- package/src/parser/rules/block/parsing/attributes/names.ts +93 -0
- package/src/parser/rules/block/parsing/attributes/scanner.ts +75 -0
- package/src/parser/rules/block/parsing/attributes/values.ts +26 -0
- package/src/parser/rules/block/parsing/block-item.ts +29 -0
- package/src/parser/rules/block/parsing/content.ts +127 -0
- package/src/parser/rules/block/parsing/end-condition.ts +51 -0
- package/src/parser/rules/block/parsing/inline-content.ts +105 -0
- package/src/parser/rules/block/parsing/inline-newline.ts +41 -0
- package/src/parser/rules/block/parsing/non-boundary.ts +24 -0
- package/src/parser/rules/block/parsing/rule-dispatch.ts +44 -0
- package/src/parser/rules/block/table/index.ts +80 -0
- package/src/parser/rules/block/table/pipe/cell-start.ts +69 -0
- package/src/parser/rules/block/table/pipe/cell.ts +106 -0
- package/src/parser/rules/block/table/pipe/index.ts +2 -0
- package/src/parser/rules/block/table/pipe/row.ts +88 -0
- package/src/parser/rules/block/table/pipe/tokens.ts +14 -0
- package/src/parser/rules/block/table/pipe/trim.ts +50 -0
- package/src/parser/rules/block/table-block/body.ts +79 -0
- package/src/parser/rules/block/table-block/cell-attributes.ts +33 -0
- package/src/parser/rules/block/table-block/cell-boundary.ts +99 -0
- package/src/parser/rules/block/table-block/cell-content/index.ts +88 -0
- package/src/parser/rules/block/table-block/cell-content/segments.ts +134 -0
- package/src/parser/rules/block/table-block/cell-newline.ts +47 -0
- package/src/parser/rules/block/table-block/cell.ts +64 -0
- package/src/parser/rules/block/table-block/index.ts +113 -0
- package/src/parser/rules/block/table-block/row-boundary.ts +75 -0
- package/src/parser/rules/block/table-block/structure.ts +80 -0
- package/src/parser/rules/block/tabview/body.ts +64 -0
- package/src/parser/rules/block/tabview/index.ts +90 -0
- package/src/parser/rules/block/tabview/open.ts +50 -0
- package/src/parser/rules/block/tabview/tab.ts +92 -0
- package/src/parser/rules/block/tabview/tags.ts +30 -0
- package/src/parser/rules/block/toc/element.ts +11 -0
- package/src/parser/rules/block/toc/index.ts +44 -0
- package/src/parser/rules/block/toc/open.ts +84 -0
- package/src/parser/rules/block/utils.ts +15 -0
- package/src/parser/rules/common/attribute-safety.ts +109 -0
- package/src/parser/rules/common/block-name.ts +33 -0
- package/src/parser/rules/common/index.ts +2 -0
- package/src/parser/rules/contracts/index.ts +3 -0
- package/src/parser/rules/contracts/parse-context.ts +38 -0
- package/src/parser/rules/contracts/rule.ts +43 -0
- package/src/parser/rules/contracts/scope.ts +31 -0
- package/src/parser/rules/index.ts +49 -0
- package/src/parser/rules/inline/anchor/attributes.ts +54 -0
- package/src/parser/rules/inline/anchor/child.ts +26 -0
- package/src/parser/rules/inline/anchor/close.ts +34 -0
- package/src/parser/rules/inline/anchor/content.ts +59 -0
- package/src/parser/rules/inline/anchor/index.ts +103 -0
- package/src/parser/rules/inline/anchor/newline.ts +26 -0
- package/src/parser/rules/inline/anchor/open.ts +47 -0
- package/src/parser/rules/inline/anchor/paragraph-strip.ts +14 -0
- package/src/parser/rules/inline/anchor/syntax.ts +40 -0
- package/src/parser/rules/inline/anchor-name/index.ts +38 -0
- package/src/parser/rules/inline/anchor-name/name.ts +39 -0
- package/src/parser/rules/inline/anchor-name/syntax.ts +46 -0
- package/src/parser/rules/inline/bibcite/element.ts +14 -0
- package/src/parser/rules/inline/bibcite/index.ts +34 -0
- package/src/parser/rules/inline/bibcite/syntax.ts +64 -0
- package/src/parser/rules/inline/bold.ts +49 -0
- package/src/parser/rules/inline/color/index.ts +35 -0
- package/src/parser/rules/inline/color/syntax.ts +69 -0
- package/src/parser/rules/inline/comment/consume.ts +31 -0
- package/src/parser/rules/inline/comment/index.ts +64 -0
- package/src/parser/rules/inline/equation-ref/element.ts +8 -0
- package/src/parser/rules/inline/equation-ref/index.ts +34 -0
- package/src/parser/rules/inline/equation-ref/syntax.ts +45 -0
- package/src/parser/rules/inline/expr/branch.ts +104 -0
- package/src/parser/rules/inline/expr/conditional-branch.ts +27 -0
- package/src/parser/rules/inline/expr/conditional.ts +80 -0
- package/src/parser/rules/inline/expr/depth.ts +25 -0
- package/src/parser/rules/inline/expr/elements.ts +39 -0
- package/src/parser/rules/inline/expr/index.ts +84 -0
- package/src/parser/rules/inline/expr/syntax.ts +45 -0
- package/src/parser/rules/inline/footnote/child.ts +22 -0
- package/src/parser/rules/inline/footnote/close.ts +33 -0
- package/src/parser/rules/inline/footnote/content.ts +54 -0
- package/src/parser/rules/inline/footnote/elements.ts +38 -0
- package/src/parser/rules/inline/footnote/index.ts +54 -0
- package/src/parser/rules/inline/footnote/newline.ts +27 -0
- package/src/parser/rules/inline/footnote/open.ts +38 -0
- package/src/parser/rules/inline/formatting/container.ts +50 -0
- package/src/parser/rules/inline/guillemet/index.ts +56 -0
- package/src/parser/rules/inline/guillemet/text.ts +11 -0
- package/src/parser/rules/inline/html/gate.ts +64 -0
- package/src/parser/rules/inline/html/index.ts +81 -0
- package/src/parser/rules/inline/html/open.ts +37 -0
- package/src/parser/rules/inline/image/attributes.ts +22 -0
- package/src/parser/rules/inline/image/body.ts +36 -0
- package/src/parser/rules/inline/image/index.ts +89 -0
- package/src/parser/rules/inline/image/open.ts +56 -0
- package/src/parser/rules/inline/image/source.ts +62 -0
- package/src/parser/rules/inline/image/syntax.ts +76 -0
- package/src/parser/rules/inline/index.ts +150 -0
- package/src/parser/rules/inline/italic.ts +46 -0
- package/src/parser/rules/inline/line-break/backslash.ts +58 -0
- package/src/parser/rules/inline/line-break/elements.ts +9 -0
- package/src/parser/rules/inline/line-break/index.ts +3 -0
- package/src/parser/rules/inline/line-break/newline.ts +82 -0
- package/src/parser/rules/inline/line-break/underscore.ts +45 -0
- package/src/parser/rules/inline/link-anchor.ts +72 -0
- package/src/parser/rules/inline/link-bracket/anchor.ts +3 -0
- package/src/parser/rules/inline/link-bracket/direct-url.ts +5 -0
- package/src/parser/rules/inline/link-bracket/parsed.ts +81 -0
- package/src/parser/rules/inline/link-bracket/parts.ts +64 -0
- package/src/parser/rules/inline/link-bracket/prefix.ts +15 -0
- package/src/parser/rules/inline/link-single.ts +73 -0
- package/src/parser/rules/inline/link-star.ts +72 -0
- package/src/parser/rules/inline/link-triple/fallback.ts +10 -0
- package/src/parser/rules/inline/link-triple/index.ts +62 -0
- package/src/parser/rules/inline/link-triple/interwiki.ts +11 -0
- package/src/parser/rules/inline/link-triple/label.ts +35 -0
- package/src/parser/rules/inline/link-triple/syntax.ts +72 -0
- package/src/parser/rules/inline/link-triple/target.ts +36 -0
- package/src/parser/rules/inline/math-inline/index.ts +40 -0
- package/src/parser/rules/inline/math-inline/syntax.ts +55 -0
- package/src/parser/rules/inline/monospace.ts +50 -0
- package/src/parser/rules/inline/parsing/block-boundary.ts +42 -0
- package/src/parser/rules/inline/parsing/block-start-predicates.ts +117 -0
- package/src/parser/rules/inline/parsing/collect.ts +23 -0
- package/src/parser/rules/inline/parsing/inline-content.ts +115 -0
- package/src/parser/rules/inline/parsing/paragraph-boundary.ts +47 -0
- package/src/parser/rules/inline/parsing/plain-text.ts +69 -0
- package/src/parser/rules/inline/parsing/preserved-line-break.ts +11 -0
- package/src/parser/rules/inline/parsing/rules.ts +34 -0
- package/src/parser/rules/inline/parsing/simple-token.ts +26 -0
- package/src/parser/rules/inline/raw/angle.ts +40 -0
- package/src/parser/rules/inline/raw/double-at.ts +78 -0
- package/src/parser/rules/inline/raw/index.ts +26 -0
- package/src/parser/rules/inline/raw/result.ts +26 -0
- package/src/parser/rules/inline/size/content.ts +65 -0
- package/src/parser/rules/inline/size/index.ts +55 -0
- package/src/parser/rules/inline/size/open.ts +43 -0
- package/src/parser/rules/inline/size/value.ts +45 -0
- package/src/parser/rules/inline/span/content.ts +97 -0
- package/src/parser/rules/inline/span/elements.ts +108 -0
- package/src/parser/rules/inline/span/index.ts +79 -0
- package/src/parser/rules/inline/span/newline.ts +50 -0
- package/src/parser/rules/inline/span/syntax.ts +70 -0
- package/src/parser/rules/inline/strikethrough/index.ts +60 -0
- package/src/parser/rules/inline/strikethrough/parse.ts +14 -0
- package/src/parser/rules/inline/strikethrough/syntax.ts +24 -0
- package/src/parser/rules/inline/subscript.ts +47 -0
- package/src/parser/rules/inline/superscript.ts +49 -0
- package/src/parser/rules/inline/text/element.ts +5 -0
- package/src/parser/rules/inline/text/index.ts +85 -0
- package/src/parser/rules/inline/underline/child.ts +26 -0
- package/src/parser/rules/inline/underline/content.ts +29 -0
- package/src/parser/rules/inline/underline/index.ts +84 -0
- package/src/parser/rules/inline/user/element.ts +11 -0
- package/src/parser/rules/inline/user/index.ts +34 -0
- package/src/parser/rules/inline/user/syntax.ts +67 -0
- package/src/parser/rules/inline/utils.ts +4 -0
- package/src/parser/rules/tokens.ts +106 -0
- package/src/parser/rules/types.ts +9 -0
- package/src/parser/toc.ts +130 -0
|
@@ -0,0 +1,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
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Block rule for Wikidot comments: `[!-- ... --]`.
|
|
4
|
+
*
|
|
5
|
+
* Comments may span multiple lines and are completely stripped from the
|
|
6
|
+
* rendered output. The parser consumes all tokens from COMMENT_OPEN
|
|
7
|
+
* (`[!--`) through the matching COMMENT_CLOSE (`--]`), inclusive, plus
|
|
8
|
+
* any trailing newline.
|
|
9
|
+
*
|
|
10
|
+
* If the closing `--]` is never found (unterminated comment), the rule
|
|
11
|
+
* fails and tokens are left for other rules to handle.
|
|
12
|
+
*
|
|
13
|
+
* This rule requires line start so that inline comments appearing mid-line
|
|
14
|
+
* are handled by a separate inline rule instead.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import type { Element } from "@wdprlib/ast";
|
|
19
|
+
import type { BlockRule, ParseContext, RuleResult } from "../../types";
|
|
20
|
+
import { consumeBlockComment } from "./consume";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Block rule for line-start comments (`[!-- ... --]`).
|
|
24
|
+
*
|
|
25
|
+
* Returns an empty elements array on success -- comments produce no output.
|
|
26
|
+
*/
|
|
27
|
+
export const blockCommentRule: BlockRule = {
|
|
28
|
+
name: "blockComment",
|
|
29
|
+
startTokens: ["COMMENT_OPEN"],
|
|
30
|
+
requiresLineStart: true,
|
|
31
|
+
|
|
32
|
+
parse(ctx: ParseContext): RuleResult<Element> {
|
|
33
|
+
const result = consumeBlockComment(ctx);
|
|
34
|
+
|
|
35
|
+
// Unterminated comment — let the inline comment rule emit the diagnostic
|
|
36
|
+
// to avoid duplication when the paragraph fallback retries this token.
|
|
37
|
+
if (!result) {
|
|
38
|
+
return { success: false };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
success: true,
|
|
43
|
+
elements: [],
|
|
44
|
+
consumed: result.consumed,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Block rule for the Wikidot content separator: `====` (four or more `=`
|
|
4
|
+
* signs at the start of a line).
|
|
5
|
+
*
|
|
6
|
+
* A content separator is a structural divider in Wikidot pages, distinct
|
|
7
|
+
* from a horizontal rule (`----`). It signals a semantic section boundary
|
|
8
|
+
* rather than a visual line.
|
|
9
|
+
*
|
|
10
|
+
* Conditions:
|
|
11
|
+
* - Must start at line start.
|
|
12
|
+
* - Requires at least four consecutive EQUALS tokens.
|
|
13
|
+
* - Must be followed by NEWLINE or EOF (no trailing text allowed).
|
|
14
|
+
*
|
|
15
|
+
* A single `=` followed by whitespace is the center-alignment rule, and
|
|
16
|
+
* two or three `=` signs are not special -- only four or more trigger this
|
|
17
|
+
* rule.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import type { Element } from "@wdprlib/ast";
|
|
22
|
+
import type { BlockRule, ParseContext, RuleResult } from "../../types";
|
|
23
|
+
import { parseContentSeparatorSyntax } from "./syntax";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Block rule for the content separator (`====`).
|
|
27
|
+
*
|
|
28
|
+
* Produces a `content-separator` element with no data payload.
|
|
29
|
+
*/
|
|
30
|
+
export const contentSeparatorRule: BlockRule = {
|
|
31
|
+
name: "content-separator",
|
|
32
|
+
startTokens: ["EQUALS"],
|
|
33
|
+
requiresLineStart: true,
|
|
34
|
+
|
|
35
|
+
parse(ctx: ParseContext): RuleResult<Element> {
|
|
36
|
+
const syntax = parseContentSeparatorSyntax(ctx);
|
|
37
|
+
if (!syntax) return { success: false };
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
success: true,
|
|
41
|
+
elements: [
|
|
42
|
+
{
|
|
43
|
+
element: "content-separator",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
consumed: syntax.consumed,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
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
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Element } from "@wdprlib/ast";
|
|
2
|
+
import type { ParseContext } from "../../types";
|
|
3
|
+
import { parseInlineUntil } from "../../inline/utils";
|
|
4
|
+
|
|
5
|
+
export interface DefinitionItemKeyResult {
|
|
6
|
+
keyString: string;
|
|
7
|
+
key: Element[];
|
|
8
|
+
consumed: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function parseDefinitionItemKey(
|
|
12
|
+
ctx: ParseContext,
|
|
13
|
+
startPos: number,
|
|
14
|
+
): DefinitionItemKeyResult | null {
|
|
15
|
+
let pos = startPos;
|
|
16
|
+
let consumed = 0;
|
|
17
|
+
|
|
18
|
+
const colonToken = ctx.tokens[pos];
|
|
19
|
+
if (!colonToken || colonToken.type !== "COLON" || !colonToken.lineStart) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
pos++;
|
|
23
|
+
consumed++;
|
|
24
|
+
|
|
25
|
+
const whitespaceAfterColon = ctx.tokens[pos];
|
|
26
|
+
if (!whitespaceAfterColon || whitespaceAfterColon.type !== "WHITESPACE") {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
31
|
+
pos++;
|
|
32
|
+
consumed++;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const keyTokens: string[] = [];
|
|
36
|
+
const key: Element[] = [];
|
|
37
|
+
let foundSecondColon = false;
|
|
38
|
+
|
|
39
|
+
while (pos < ctx.tokens.length) {
|
|
40
|
+
const token = ctx.tokens[pos];
|
|
41
|
+
if (!token || token.type === "NEWLINE" || token.type === "EOF") {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
if (token.type === "COLON") {
|
|
45
|
+
foundSecondColon = true;
|
|
46
|
+
pos++;
|
|
47
|
+
consumed++;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const inlineCtx: ParseContext = { ...ctx, pos };
|
|
52
|
+
const result = parseInlineUntil(inlineCtx, "COLON");
|
|
53
|
+
if (result.elements.length > 0) {
|
|
54
|
+
key.push(...result.elements);
|
|
55
|
+
for (let i = 0; i < result.consumed; i++) {
|
|
56
|
+
const t = ctx.tokens[pos + i];
|
|
57
|
+
if (t) keyTokens.push(t.value);
|
|
58
|
+
}
|
|
59
|
+
pos += result.consumed;
|
|
60
|
+
consumed += result.consumed;
|
|
61
|
+
} else {
|
|
62
|
+
keyTokens.push(token.value);
|
|
63
|
+
pos++;
|
|
64
|
+
consumed++;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!foundSecondColon) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
trimTrailingWhitespaceText(key);
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
keyString: keyTokens.join("").trim(),
|
|
76
|
+
key,
|
|
77
|
+
consumed,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function trimTrailingWhitespaceText(nodes: Element[]): void {
|
|
82
|
+
while (nodes.length > 0) {
|
|
83
|
+
const lastNode = nodes[nodes.length - 1];
|
|
84
|
+
if (
|
|
85
|
+
lastNode &&
|
|
86
|
+
lastNode.element === "text" &&
|
|
87
|
+
typeof lastNode.data === "string" &&
|
|
88
|
+
lastNode.data.trim() === ""
|
|
89
|
+
) {
|
|
90
|
+
nodes.pop();
|
|
91
|
+
} else {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Element } from "@wdprlib/ast";
|
|
2
|
+
import type { ParseContext } from "../../types";
|
|
3
|
+
import { parseInlineUntil } from "../../inline/utils";
|
|
4
|
+
|
|
5
|
+
export interface DefinitionItemValueResult {
|
|
6
|
+
value: Element[];
|
|
7
|
+
consumed: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function parseDefinitionItemValue(
|
|
11
|
+
ctx: ParseContext,
|
|
12
|
+
startPos: number,
|
|
13
|
+
): DefinitionItemValueResult {
|
|
14
|
+
const value: Element[] = [];
|
|
15
|
+
let pos = startPos;
|
|
16
|
+
let consumed = 0;
|
|
17
|
+
|
|
18
|
+
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
19
|
+
pos++;
|
|
20
|
+
consumed++;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
while (pos < ctx.tokens.length) {
|
|
24
|
+
const token = ctx.tokens[pos];
|
|
25
|
+
if (!token || token.type === "EOF") {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (token.type === "NEWLINE") {
|
|
30
|
+
const nextToken = ctx.tokens[pos + 1];
|
|
31
|
+
if (nextToken?.type === "COLON" && nextToken.lineStart) {
|
|
32
|
+
pos++;
|
|
33
|
+
consumed++;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (nextToken?.type === "NEWLINE" || !nextToken || nextToken.type === "EOF") {
|
|
37
|
+
pos++;
|
|
38
|
+
consumed++;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const inlineCtx: ParseContext = { ...ctx, pos };
|
|
44
|
+
const result = parseInlineUntil(inlineCtx, "NEWLINE");
|
|
45
|
+
if (result.elements.length > 0) {
|
|
46
|
+
value.push(...result.elements);
|
|
47
|
+
pos += result.consumed;
|
|
48
|
+
consumed += result.consumed;
|
|
49
|
+
} else {
|
|
50
|
+
pos++;
|
|
51
|
+
consumed++;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { value, consumed };
|
|
56
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { DefinitionListItem, Element } from "@wdprlib/ast";
|
|
2
|
+
import type { ParseContext } from "../../types";
|
|
3
|
+
import { parseDefinitionItemKey } from "./item-key";
|
|
4
|
+
import { parseDefinitionItemValue } from "./item-value";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal representation of one definition list item before conversion
|
|
8
|
+
* to the AST's DefinitionListItem format.
|
|
9
|
+
*/
|
|
10
|
+
export interface ParsedDefinitionItem {
|
|
11
|
+
/** Raw string of the key, used for `key_string` in the AST. */
|
|
12
|
+
keyString: string;
|
|
13
|
+
/** Parsed inline elements representing the key / term. */
|
|
14
|
+
key: Element[];
|
|
15
|
+
/** Parsed inline elements representing the value / definition. */
|
|
16
|
+
value: Element[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Parses a single definition list entry of the form `: key : value`.
|
|
21
|
+
*
|
|
22
|
+
* The function expects `startPos` to point at a line-start COLON token.
|
|
23
|
+
* It consumes the first colon, mandatory whitespace, key tokens up to
|
|
24
|
+
* the second colon, then value tokens until a double newline, a new entry,
|
|
25
|
+
* or end of input.
|
|
26
|
+
*/
|
|
27
|
+
export function parseDefinitionItem(
|
|
28
|
+
ctx: ParseContext,
|
|
29
|
+
startPos: number,
|
|
30
|
+
): { item: ParsedDefinitionItem; consumed: number } | null {
|
|
31
|
+
const keyResult = parseDefinitionItemKey(ctx, startPos);
|
|
32
|
+
if (!keyResult) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const valueResult = parseDefinitionItemValue(ctx, startPos + keyResult.consumed);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
item: {
|
|
40
|
+
keyString: keyResult.keyString,
|
|
41
|
+
key: keyResult.key,
|
|
42
|
+
value: valueResult.value,
|
|
43
|
+
},
|
|
44
|
+
consumed: keyResult.consumed + valueResult.consumed,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function toDefinitionListItems(items: ParsedDefinitionItem[]): DefinitionListItem[] {
|
|
49
|
+
return items.map((item) => ({
|
|
50
|
+
key_string: item.keyString,
|
|
51
|
+
key: item.key,
|
|
52
|
+
value: item.value,
|
|
53
|
+
}));
|
|
54
|
+
}
|