@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
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Position as Position2, Point, Version as Version2, Element as
|
|
1
|
+
import { Position as Position2, Point, Version as Version2, Element as Element7, SyntaxTree as SyntaxTree3, ContainerType, ContainerData, AttributeMap, VariableMap, Alignment, LinkType, LinkLocation, LinkLabel, PageRef as PageRef3, ImageSource, FloatAlignment, ListType, ListItem, ListData, CodeBlockData as CodeBlockData2, TabData, TableCell, TableRow, TableData, DefinitionListItem, Module as Module4, CollapsibleData, ClearFloat, AnchorTarget, HeaderType, AlignType, HeadingLevel, Heading, DateItem, Embed, TocEntry as TocEntry2, Diagnostic as Diagnostic2, DiagnosticSeverity, ParseResult as ParseResult3 } from "@wdprlib/ast";
|
|
2
2
|
import { createPoint, createPosition, text, container, paragraph, bold, italics, heading, lineBreak, horizontalRule, link, list, listItemElements, listItemSubList } from "@wdprlib/ast";
|
|
3
3
|
import { WikitextMode, WikitextSettings as WikitextSettings4 } from "@wdprlib/ast";
|
|
4
4
|
import { createSettings, DEFAULT_SETTINGS } from "@wdprlib/ast";
|
|
@@ -62,6 +62,12 @@ interface LexerOptions {
|
|
|
62
62
|
* when source-map information is not needed.
|
|
63
63
|
*/
|
|
64
64
|
trackPositions?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Coalesce ordinary text outside `[[...]]` openers into larger TEXT tokens.
|
|
67
|
+
* This keeps block names and attributes tokenized normally while reducing
|
|
68
|
+
* token volume for large documents.
|
|
69
|
+
*/
|
|
70
|
+
compactTextRuns?: boolean;
|
|
65
71
|
}
|
|
66
72
|
/**
|
|
67
73
|
* Converts a Wikidot markup source string into a flat array of {@link Token}s.
|
|
@@ -80,6 +86,7 @@ declare class Lexer {
|
|
|
80
86
|
private state;
|
|
81
87
|
private options;
|
|
82
88
|
private splitBlockClosePositions;
|
|
89
|
+
private lastNonWhitespaceType;
|
|
83
90
|
/**
|
|
84
91
|
* Nesting depth of block-opener context (between `[[` / `[[/` and the
|
|
85
92
|
* matching `]]`). Used to scope `QUOTED_STRING` recognition so that
|
|
@@ -111,10 +118,6 @@ declare class Lexer {
|
|
|
111
118
|
*/
|
|
112
119
|
private findInvalidAnchorNameEnd;
|
|
113
120
|
/**
|
|
114
|
-
* Check if source matches pattern at current position
|
|
115
|
-
*/
|
|
116
|
-
private match;
|
|
117
|
-
/**
|
|
118
121
|
* Advance position by n characters
|
|
119
122
|
*/
|
|
120
123
|
private advance;
|
|
@@ -126,14 +129,12 @@ declare class Lexer {
|
|
|
126
129
|
* Add token
|
|
127
130
|
*/
|
|
128
131
|
private addToken;
|
|
132
|
+
private emitTokenAction;
|
|
133
|
+
private emitTokenActions;
|
|
129
134
|
/**
|
|
130
135
|
* Scan a single token
|
|
131
136
|
*/
|
|
132
137
|
private scanToken;
|
|
133
|
-
/**
|
|
134
|
-
* Check if character is alphanumeric (for identifier tokens)
|
|
135
|
-
*/
|
|
136
|
-
private isAlphanumeric;
|
|
137
138
|
}
|
|
138
139
|
/**
|
|
139
140
|
* Tokenise a Wikidot markup source string in one call.
|
|
@@ -147,7 +148,8 @@ declare class Lexer {
|
|
|
147
148
|
* @group Lexer
|
|
148
149
|
*/
|
|
149
150
|
declare function tokenize(source: string, options?: LexerOptions): Token[];
|
|
150
|
-
import {
|
|
151
|
+
import { ParseResult as ParseResult2 } from "@wdprlib/ast";
|
|
152
|
+
import { WikitextSettings } from "@wdprlib/ast";
|
|
151
153
|
/**
|
|
152
154
|
* Configuration for the {@link Parser} and the {@link parse} function.
|
|
153
155
|
*
|
|
@@ -171,41 +173,26 @@ interface ParserOptions {
|
|
|
171
173
|
settings?: WikitextSettings;
|
|
172
174
|
/**
|
|
173
175
|
* Page tags consulted when expanding `[[iftags]]` directives that are
|
|
174
|
-
* embedded inside another block's opener
|
|
175
|
-
* `[[div_ class="x" [[iftags +foo]]style="..."[[/iftags]]]]`. Such
|
|
176
|
-
* iftags must be collapsed at text level *before* tokenization;
|
|
177
|
-
* otherwise the outer opener loses its well-formed structure and the
|
|
178
|
-
* whole `[[div_ ... ]]` line is emitted as raw text.
|
|
176
|
+
* embedded inside another block's opener.
|
|
179
177
|
*
|
|
180
178
|
* Values:
|
|
181
|
-
* - omitted / `undefined`: no preprocess pass.
|
|
182
|
-
*
|
|
183
|
-
* - `
|
|
184
|
-
* no tags (lossy fallback that keeps tokenization working when real
|
|
185
|
-
* tags are unknown). Block-level iftags remain in the AST for
|
|
186
|
-
* `resolveModules` to evaluate later via `getPageTags`.
|
|
187
|
-
* - `string[]`: every iftags block is evaluated against the given
|
|
188
|
-
* tags eagerly; no `if-tags` nodes survive in the AST.
|
|
179
|
+
* - omitted / `undefined`: no preprocess pass.
|
|
180
|
+
* - `null`: opener-embedded iftags only, evaluated as if the page has no tags.
|
|
181
|
+
* - `string[]`: every iftags block is evaluated against the given tags eagerly.
|
|
189
182
|
*/
|
|
190
183
|
pageTags?: string[] | null;
|
|
191
184
|
}
|
|
185
|
+
import { ParseResult } from "@wdprlib/ast";
|
|
192
186
|
/**
|
|
193
187
|
* Converts a token stream into a Wikidot {@link SyntaxTree}.
|
|
194
188
|
*
|
|
195
|
-
* The parser consumes tokens produced by the `Lexer` and emits a
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* After the main parse pass, two post-processing steps run:
|
|
189
|
+
* The parser consumes tokens produced by the `Lexer` and emits a tree of
|
|
190
|
+
* {@link Element} nodes. Block-level rules are tried in priority order; when
|
|
191
|
+
* none match, the fallback paragraph rule collects inline tokens until the
|
|
192
|
+
* next blank line.
|
|
201
193
|
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* 2. **Internal-flag cleanup** — all `_`-prefixed bookkeeping fields
|
|
205
|
-
* are removed from the final AST.
|
|
206
|
-
*
|
|
207
|
-
* For most use-cases the standalone {@link parse} function is simpler
|
|
208
|
-
* than constructing a `Parser` directly.
|
|
194
|
+
* For most use-cases the standalone {@link parse} function is simpler than
|
|
195
|
+
* constructing a `Parser` directly.
|
|
209
196
|
*
|
|
210
197
|
* @group Parser
|
|
211
198
|
*/
|
|
@@ -219,26 +206,10 @@ declare class Parser {
|
|
|
219
206
|
* @since 2.0.0
|
|
220
207
|
*/
|
|
221
208
|
parse(): ParseResult;
|
|
222
|
-
/**
|
|
223
|
-
* Check if at end of tokens
|
|
224
|
-
*/
|
|
225
209
|
private isAtEnd;
|
|
226
|
-
/**
|
|
227
|
-
* Get current token
|
|
228
|
-
*/
|
|
229
210
|
private currentToken;
|
|
230
|
-
/**
|
|
231
|
-
* Create EOF token
|
|
232
|
-
*/
|
|
233
211
|
private eofToken;
|
|
234
|
-
/**
|
|
235
|
-
* Skip whitespace tokens
|
|
236
|
-
*/
|
|
237
212
|
private skipWhitespace;
|
|
238
|
-
/**
|
|
239
|
-
* Parse block element(s)
|
|
240
|
-
* Returns an array because some rules (like list) may return multiple elements
|
|
241
|
-
*/
|
|
242
213
|
private parseBlock;
|
|
243
214
|
}
|
|
244
215
|
/**
|
|
@@ -253,8 +224,8 @@ declare class Parser {
|
|
|
253
224
|
*
|
|
254
225
|
* @since 2.0.0
|
|
255
226
|
*/
|
|
256
|
-
declare function parse(source: string, options?: ParserOptions):
|
|
257
|
-
import { Element as
|
|
227
|
+
declare function parse(source: string, options?: ParserOptions): ParseResult2;
|
|
228
|
+
import { Element as Element3 } from "@wdprlib/ast";
|
|
258
229
|
/**
|
|
259
230
|
* Parser function type for re-parsing substituted template output as wikitext.
|
|
260
231
|
*
|
|
@@ -266,9 +237,62 @@ import { Element as Element2 } from "@wdprlib/ast";
|
|
|
266
237
|
* @returns Object containing the parsed elements
|
|
267
238
|
*/
|
|
268
239
|
type ParseFunction = (input: string) => {
|
|
269
|
-
elements:
|
|
240
|
+
elements: Element3[];
|
|
270
241
|
};
|
|
271
242
|
/**
|
|
243
|
+
* ListPages query parameters for page selection.
|
|
244
|
+
*
|
|
245
|
+
* @security All string fields contain untrusted user input from wikitext.
|
|
246
|
+
* When using these values in database queries:
|
|
247
|
+
* - NEVER interpolate directly into SQL/NoSQL query strings.
|
|
248
|
+
* - ALWAYS use parameterized queries or prepared statements.
|
|
249
|
+
* - For ORDER BY clauses, use a whitelist of allowed column names.
|
|
250
|
+
*/
|
|
251
|
+
interface ListPagesQuery {
|
|
252
|
+
/** Page type selector */
|
|
253
|
+
pagetype?: "normal" | "hidden" | "*";
|
|
254
|
+
/** Category selector. @untrusted User input - use parameterized queries. */
|
|
255
|
+
category?: string;
|
|
256
|
+
/** Tag selector, e.g. "+fruit -admin". @untrusted User input. */
|
|
257
|
+
tags?: string;
|
|
258
|
+
/** Parent page selector. @untrusted User input. */
|
|
259
|
+
parent?: string;
|
|
260
|
+
/** Link target selector. @untrusted User input. */
|
|
261
|
+
linkTo?: string;
|
|
262
|
+
/** Created date selector. @untrusted User input. */
|
|
263
|
+
createdAt?: string;
|
|
264
|
+
/** Updated date selector. @untrusted User input. */
|
|
265
|
+
updatedAt?: string;
|
|
266
|
+
/** Author selector. @untrusted User input. */
|
|
267
|
+
createdBy?: string;
|
|
268
|
+
/** Rating selector. @untrusted User input. */
|
|
269
|
+
rating?: string;
|
|
270
|
+
/** Votes selector. @untrusted User input. */
|
|
271
|
+
votes?: string;
|
|
272
|
+
/** Page name selector. @untrusted User input. */
|
|
273
|
+
name?: string;
|
|
274
|
+
/** Full page name selector (category:name). @untrusted User input. */
|
|
275
|
+
fullname?: string;
|
|
276
|
+
/** Range selector relative to current page */
|
|
277
|
+
range?: "." | "before" | "after" | "others";
|
|
278
|
+
/** Data form field selectors. @untrusted Both keys and values are user input. */
|
|
279
|
+
dataFormFields?: Record<string, string>;
|
|
280
|
+
/** Ordering specification. @untrusted Use whitelist validation for ORDER BY. */
|
|
281
|
+
order?: string;
|
|
282
|
+
/** Pagination offset */
|
|
283
|
+
offset?: number;
|
|
284
|
+
/** Maximum number of results */
|
|
285
|
+
limit?: number;
|
|
286
|
+
/** Results per page */
|
|
287
|
+
perPage?: number;
|
|
288
|
+
/** Reverse order */
|
|
289
|
+
reverse?: boolean;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* All supported ListPages template variables.
|
|
293
|
+
*/
|
|
294
|
+
type ListPagesVariable = "created_at" | "created_by" | "created_by_unix" | "created_by_id" | "created_by_linked" | "updated_at" | "updated_by" | "updated_by_unix" | "updated_by_id" | "updated_by_linked" | "commented_at" | "commented_by" | "commented_by_unix" | "commented_by_id" | "commented_by_linked" | "name" | "category" | "fullname" | "title" | "title_linked" | "link" | "parent_name" | "parent_category" | "parent_fullname" | "parent_title" | "parent_title_linked" | "content" | "content_n" | "preview" | "preview_n" | "summary" | "first_paragraph" | "tags" | "tags_linked" | "_tags" | "_tags_linked" | "form_data" | "form_raw" | "form_label" | "form_hint" | "children" | "comments" | "size" | "rating" | "rating_votes" | "rating_percent" | "revisions" | "index" | "total" | "limit" | "total_or_limit" | "site_title" | "site_name" | "site_domain";
|
|
295
|
+
/**
|
|
272
296
|
*
|
|
273
297
|
* Type definitions for the ListUsers module.
|
|
274
298
|
*
|
|
@@ -353,126 +377,7 @@ interface ListUsersVariableContext {
|
|
|
353
377
|
*/
|
|
354
378
|
type ListUsersCompiledTemplate = (ctx: ListUsersVariableContext) => string;
|
|
355
379
|
/**
|
|
356
|
-
*
|
|
357
|
-
* Type definitions for the ListPages module system.
|
|
358
|
-
*
|
|
359
|
-
* This file defines the complete type vocabulary for the ListPages lifecycle:
|
|
360
|
-
*
|
|
361
|
-
* - **Query types**: Raw and normalized representations of ListPages filter/sort parameters
|
|
362
|
-
* - **Variable types**: The `%%variable%%` names supported in ListPages templates
|
|
363
|
-
* - **Data requirement types**: What the parser tells the application it needs to fetch
|
|
364
|
-
* - **External data types**: What the application provides back (page data, user info, site context)
|
|
365
|
-
* - **Template types**: Compiled template function signatures and their execution context
|
|
366
|
-
* - **Normalized query types**: Structured representations of parsed query parameters
|
|
367
|
-
*
|
|
368
|
-
* Security note: Several fields contain untrusted user input from wikitext.
|
|
369
|
-
* See `ListPagesQuery` documentation for safe usage guidelines.
|
|
370
|
-
*
|
|
371
|
-
* @module
|
|
372
|
-
*/
|
|
373
|
-
/**
|
|
374
|
-
* ListPages query parameters for page selection
|
|
375
|
-
*
|
|
376
|
-
* @security All string fields contain **untrusted user input** from wikitext.
|
|
377
|
-
* When using these values in database queries:
|
|
378
|
-
* - **NEVER** interpolate directly into SQL/NoSQL query strings
|
|
379
|
-
* - **ALWAYS** use parameterized queries or prepared statements
|
|
380
|
-
* - For ORDER BY clauses, use a whitelist of allowed column names
|
|
381
|
-
*
|
|
382
|
-
* @example Safe usage with SQL
|
|
383
|
-
* ```typescript
|
|
384
|
-
* // GOOD: Parameterized query
|
|
385
|
-
* db.query("SELECT * FROM pages WHERE category = ?", [query.category]);
|
|
386
|
-
*
|
|
387
|
-
* // BAD: String interpolation (SQL injection vulnerable!)
|
|
388
|
-
* db.query(`SELECT * FROM pages WHERE category = '${query.category}'`);
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
interface ListPagesQuery {
|
|
392
|
-
/** Page type selector */
|
|
393
|
-
pagetype?: "normal" | "hidden" | "*";
|
|
394
|
-
/**
|
|
395
|
-
* Category selector
|
|
396
|
-
* @untrusted User input - use parameterized queries
|
|
397
|
-
*/
|
|
398
|
-
category?: string;
|
|
399
|
-
/**
|
|
400
|
-
* Tag selector (e.g., "+fruit -admin")
|
|
401
|
-
* @untrusted User input - use parameterized queries
|
|
402
|
-
*/
|
|
403
|
-
tags?: string;
|
|
404
|
-
/**
|
|
405
|
-
* Parent page selector
|
|
406
|
-
* @untrusted User input - use parameterized queries
|
|
407
|
-
*/
|
|
408
|
-
parent?: string;
|
|
409
|
-
/**
|
|
410
|
-
* Link target selector
|
|
411
|
-
* @untrusted User input - use parameterized queries
|
|
412
|
-
*/
|
|
413
|
-
linkTo?: string;
|
|
414
|
-
/**
|
|
415
|
-
* Created date selector
|
|
416
|
-
* @untrusted User input - use parameterized queries
|
|
417
|
-
*/
|
|
418
|
-
createdAt?: string;
|
|
419
|
-
/**
|
|
420
|
-
* Updated date selector
|
|
421
|
-
* @untrusted User input - use parameterized queries
|
|
422
|
-
*/
|
|
423
|
-
updatedAt?: string;
|
|
424
|
-
/**
|
|
425
|
-
* Author selector
|
|
426
|
-
* @untrusted User input - use parameterized queries
|
|
427
|
-
*/
|
|
428
|
-
createdBy?: string;
|
|
429
|
-
/**
|
|
430
|
-
* Rating selector
|
|
431
|
-
* @untrusted User input - use parameterized queries
|
|
432
|
-
*/
|
|
433
|
-
rating?: string;
|
|
434
|
-
/**
|
|
435
|
-
* Votes selector
|
|
436
|
-
* @untrusted User input - use parameterized queries
|
|
437
|
-
*/
|
|
438
|
-
votes?: string;
|
|
439
|
-
/**
|
|
440
|
-
* Page name selector
|
|
441
|
-
* @untrusted User input - use parameterized queries
|
|
442
|
-
*/
|
|
443
|
-
name?: string;
|
|
444
|
-
/**
|
|
445
|
-
* Full page name selector (category:name)
|
|
446
|
-
* @untrusted User input - use parameterized queries
|
|
447
|
-
*/
|
|
448
|
-
fullname?: string;
|
|
449
|
-
/** Range selector relative to current page */
|
|
450
|
-
range?: "." | "before" | "after" | "others";
|
|
451
|
-
/**
|
|
452
|
-
* Data form field selectors
|
|
453
|
-
* @untrusted Both keys and values are user input
|
|
454
|
-
*/
|
|
455
|
-
dataFormFields?: Record<string, string>;
|
|
456
|
-
/**
|
|
457
|
-
* Ordering specification
|
|
458
|
-
* @untrusted User input - use whitelist validation for ORDER BY
|
|
459
|
-
*/
|
|
460
|
-
order?: string;
|
|
461
|
-
/** Pagination offset */
|
|
462
|
-
offset?: number;
|
|
463
|
-
/** Maximum number of results */
|
|
464
|
-
limit?: number;
|
|
465
|
-
/** Results per page */
|
|
466
|
-
perPage?: number;
|
|
467
|
-
/** Reverse order */
|
|
468
|
-
reverse?: boolean;
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* All supported ListPages template variables
|
|
472
|
-
*/
|
|
473
|
-
type ListPagesVariable = "created_at" | "created_by" | "created_by_unix" | "created_by_id" | "created_by_linked" | "updated_at" | "updated_by" | "updated_by_unix" | "updated_by_id" | "updated_by_linked" | "commented_at" | "commented_by" | "commented_by_unix" | "commented_by_id" | "commented_by_linked" | "name" | "category" | "fullname" | "title" | "title_linked" | "link" | "parent_name" | "parent_category" | "parent_fullname" | "parent_title" | "parent_title_linked" | "content" | "content_n" | "preview" | "preview_n" | "summary" | "first_paragraph" | "tags" | "tags_linked" | "_tags" | "_tags_linked" | "form_data" | "form_raw" | "form_label" | "form_hint" | "children" | "comments" | "size" | "rating" | "rating_votes" | "rating_percent" | "revisions" | "index" | "total" | "limit" | "total_or_limit" | "site_title" | "site_name" | "site_domain";
|
|
474
|
-
/**
|
|
475
|
-
* Data requirement for a single ListPages module
|
|
380
|
+
* Data requirement for a single ListPages module.
|
|
476
381
|
*/
|
|
477
382
|
interface ListPagesDataRequirement {
|
|
478
383
|
/** Unique identifier for this module instance */
|
|
@@ -485,33 +390,32 @@ interface ListPagesDataRequirement {
|
|
|
485
390
|
contentSectionIndices?: number[];
|
|
486
391
|
/** Lengths needed for preview(n) */
|
|
487
392
|
previewLengths?: number[];
|
|
488
|
-
/** Field names needed for form_data{field} etc */
|
|
393
|
+
/** Field names needed for form_data{field} etc. */
|
|
489
394
|
formFields?: string[];
|
|
490
395
|
/** Prefix for tags_linked|prefix */
|
|
491
396
|
tagsLinkPrefix?: string;
|
|
492
397
|
/** Prefix for _tags_linked|prefix */
|
|
493
398
|
hiddenTagsLinkPrefix?: string;
|
|
494
399
|
/**
|
|
495
|
-
* URL attribute prefix for multiple ListPages modules
|
|
496
|
-
* When set, URL parameters are prefixed
|
|
400
|
+
* URL attribute prefix for multiple ListPages modules.
|
|
401
|
+
* When set, URL parameters are prefixed, e.g. "page2" -> "/page2_limit/1".
|
|
497
402
|
*/
|
|
498
403
|
urlAttrPrefix?: string;
|
|
499
404
|
/**
|
|
500
|
-
* Raw attribute values before URL resolution
|
|
501
|
-
* Contains original string values that may include "@URL" or "@URL|default"
|
|
502
|
-
* External applications should use these to resolve URL parameters
|
|
405
|
+
* Raw attribute values before URL resolution.
|
|
406
|
+
* Contains original string values that may include "@URL" or "@URL|default".
|
|
503
407
|
*/
|
|
504
408
|
rawAttributes: Record<string, string>;
|
|
505
409
|
}
|
|
506
410
|
/**
|
|
507
|
-
* All data requirements from parsing
|
|
411
|
+
* All data requirements from parsing.
|
|
508
412
|
*/
|
|
509
413
|
interface DataRequirements {
|
|
510
414
|
listPages: ListPagesDataRequirement[];
|
|
511
415
|
listUsers: ListUsersDataRequirement[];
|
|
512
416
|
}
|
|
513
417
|
/**
|
|
514
|
-
* User information
|
|
418
|
+
* User information.
|
|
515
419
|
*/
|
|
516
420
|
interface UserInfo {
|
|
517
421
|
id: number;
|
|
@@ -519,7 +423,7 @@ interface UserInfo {
|
|
|
519
423
|
unixName: string;
|
|
520
424
|
}
|
|
521
425
|
/**
|
|
522
|
-
* Page data provided by external source
|
|
426
|
+
* Page data provided by an external source.
|
|
523
427
|
*/
|
|
524
428
|
interface PageData {
|
|
525
429
|
name: string;
|
|
@@ -552,7 +456,7 @@ interface PageData {
|
|
|
552
456
|
revisions: number;
|
|
553
457
|
}
|
|
554
458
|
/**
|
|
555
|
-
* Site context information
|
|
459
|
+
* Site context information.
|
|
556
460
|
*/
|
|
557
461
|
interface SiteContext {
|
|
558
462
|
title: string;
|
|
@@ -560,7 +464,7 @@ interface SiteContext {
|
|
|
560
464
|
domain: string;
|
|
561
465
|
}
|
|
562
466
|
/**
|
|
563
|
-
* External data for a single ListPages module
|
|
467
|
+
* External data for a single ListPages module.
|
|
564
468
|
*/
|
|
565
469
|
interface ListPagesExternalData {
|
|
566
470
|
pages: PageData[];
|
|
@@ -568,73 +472,48 @@ interface ListPagesExternalData {
|
|
|
568
472
|
site: SiteContext;
|
|
569
473
|
}
|
|
570
474
|
/**
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
* Called by resolveModules for each ListPages module in the AST.
|
|
574
|
-
* Receives a normalized query with all `@URL` parameters resolved.
|
|
575
|
-
* Return null/undefined to skip the module (outputs nothing).
|
|
576
|
-
*
|
|
577
|
-
* @param query - Normalized query with structured types (tags, category, order, etc.)
|
|
578
|
-
* @param requirement - Original data requirement (for accessing id, neededVariables, etc.)
|
|
579
|
-
*/
|
|
580
|
-
type ListPagesDataFetcher = (query: NormalizedListPagesQuery, requirement: ListPagesDataRequirement) => ListPagesExternalData | null | undefined | Promise<ListPagesExternalData | null | undefined>;
|
|
581
|
-
/**
|
|
582
|
-
* Context passed to compiled template
|
|
583
|
-
*/
|
|
584
|
-
interface VariableContext {
|
|
585
|
-
page: PageData;
|
|
586
|
-
index: number;
|
|
587
|
-
total: number;
|
|
588
|
-
limit?: number;
|
|
589
|
-
site: SiteContext;
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* Compiled template function
|
|
593
|
-
*/
|
|
594
|
-
type CompiledTemplate = (ctx: VariableContext) => string;
|
|
595
|
-
/**
|
|
596
|
-
* Normalized tags selector
|
|
475
|
+
* Normalized tags selector.
|
|
597
476
|
*/
|
|
598
477
|
interface NormalizedTags {
|
|
599
|
-
/** AND conditions - pages must have
|
|
478
|
+
/** AND conditions - pages must have all of these tags (+tag). */
|
|
600
479
|
all: string[];
|
|
601
|
-
/** OR conditions - pages must have
|
|
480
|
+
/** OR conditions - pages must have any of these tags (no prefix). */
|
|
602
481
|
any: string[];
|
|
603
|
-
/** NOT conditions - pages must
|
|
482
|
+
/** NOT conditions - pages must not have these tags (-tag). */
|
|
604
483
|
none: string[];
|
|
605
|
-
/** Special selector */
|
|
484
|
+
/** Special selector. */
|
|
606
485
|
special: "same-visible" | "same-all" | "none" | null;
|
|
607
486
|
}
|
|
608
487
|
/**
|
|
609
|
-
* Normalized category selector
|
|
488
|
+
* Normalized category selector.
|
|
610
489
|
*/
|
|
611
490
|
interface NormalizedCategory {
|
|
612
|
-
/** Categories to include */
|
|
491
|
+
/** Categories to include. */
|
|
613
492
|
include: string[];
|
|
614
|
-
/** Categories to exclude (-category) */
|
|
493
|
+
/** Categories to exclude (-category). */
|
|
615
494
|
exclude: string[];
|
|
616
|
-
/** Select all categories (*) */
|
|
495
|
+
/** Select all categories (*). */
|
|
617
496
|
all: boolean;
|
|
618
|
-
/** Select current category (.) */
|
|
497
|
+
/** Select current category (.). */
|
|
619
498
|
current: boolean;
|
|
620
499
|
}
|
|
621
500
|
/**
|
|
622
|
-
* Order field options
|
|
501
|
+
* Order field options.
|
|
623
502
|
*/
|
|
624
503
|
type OrderField = "created_at" | "updated_at" | "title" | "fullname" | "rating" | "votes" | "revisions" | "comments" | "size" | "random";
|
|
625
504
|
/**
|
|
626
|
-
* Order direction
|
|
505
|
+
* Order direction.
|
|
627
506
|
*/
|
|
628
507
|
type OrderDirection = "asc" | "desc";
|
|
629
508
|
/**
|
|
630
|
-
* Normalized order specification
|
|
509
|
+
* Normalized order specification.
|
|
631
510
|
*/
|
|
632
511
|
interface NormalizedOrder {
|
|
633
512
|
field: OrderField;
|
|
634
513
|
direction: OrderDirection;
|
|
635
514
|
}
|
|
636
515
|
/**
|
|
637
|
-
* Normalized parent selector
|
|
516
|
+
* Normalized parent selector.
|
|
638
517
|
*/
|
|
639
518
|
type NormalizedParent = {
|
|
640
519
|
type: "none";
|
|
@@ -649,11 +528,11 @@ type NormalizedParent = {
|
|
|
649
528
|
name: string;
|
|
650
529
|
};
|
|
651
530
|
/**
|
|
652
|
-
* Date comparison operators
|
|
531
|
+
* Date comparison operators.
|
|
653
532
|
*/
|
|
654
533
|
type DateComparisonOp = "=" | "<" | ">" | "<=" | ">=" | "<>";
|
|
655
534
|
/**
|
|
656
|
-
* Normalized date selector
|
|
535
|
+
* Normalized date selector.
|
|
657
536
|
*/
|
|
658
537
|
type NormalizedDateSelector = {
|
|
659
538
|
type: "year";
|
|
@@ -672,24 +551,21 @@ type NormalizedDateSelector = {
|
|
|
672
551
|
count: number;
|
|
673
552
|
};
|
|
674
553
|
/**
|
|
675
|
-
* Numeric comparison operators
|
|
554
|
+
* Numeric comparison operators.
|
|
676
555
|
*/
|
|
677
556
|
type NumericComparisonOp = "=" | "<" | ">" | "<=" | ">=";
|
|
678
557
|
/**
|
|
679
|
-
* Normalized numeric selector
|
|
558
|
+
* Normalized numeric selector for rating/votes.
|
|
680
559
|
*/
|
|
681
560
|
interface NormalizedNumericSelector {
|
|
682
561
|
op: NumericComparisonOp;
|
|
683
562
|
value: number;
|
|
684
563
|
}
|
|
685
564
|
/**
|
|
686
|
-
* Fully normalized ListPages query
|
|
565
|
+
* Fully normalized ListPages query.
|
|
687
566
|
*
|
|
688
|
-
* All string fields are parsed
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
* Note: This is structural normalization, not full validation.
|
|
692
|
-
* Invalid inputs are either rejected (return undefined) or ignored.
|
|
567
|
+
* All string fields are parsed into structured selector objects. Use
|
|
568
|
+
* `normalizeQuery()` to convert from `ListPagesQuery`.
|
|
693
569
|
*/
|
|
694
570
|
interface NormalizedListPagesQuery {
|
|
695
571
|
pagetype?: "normal" | "hidden" | "*";
|
|
@@ -713,6 +589,28 @@ interface NormalizedListPagesQuery {
|
|
|
713
589
|
reverse?: boolean;
|
|
714
590
|
}
|
|
715
591
|
/**
|
|
592
|
+
* Callback to fetch data for a ListPages module.
|
|
593
|
+
*
|
|
594
|
+
* Called by resolveModules for each ListPages module in the AST. Receives a
|
|
595
|
+
* normalized query with all `@URL` parameters resolved. Return null/undefined
|
|
596
|
+
* to skip the module.
|
|
597
|
+
*/
|
|
598
|
+
type ListPagesDataFetcher = (query: NormalizedListPagesQuery, requirement: ListPagesDataRequirement) => ListPagesExternalData | null | undefined | Promise<ListPagesExternalData | null | undefined>;
|
|
599
|
+
/**
|
|
600
|
+
* Context passed to a compiled ListPages template.
|
|
601
|
+
*/
|
|
602
|
+
interface VariableContext {
|
|
603
|
+
page: PageData;
|
|
604
|
+
index: number;
|
|
605
|
+
total: number;
|
|
606
|
+
limit?: number;
|
|
607
|
+
site: SiteContext;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Compiled template function.
|
|
611
|
+
*/
|
|
612
|
+
type CompiledTemplate = (ctx: VariableContext) => string;
|
|
613
|
+
/**
|
|
716
614
|
* Callback to retrieve the current page's tags during the resolve phase.
|
|
717
615
|
*
|
|
718
616
|
* Called when evaluating `[[iftags]]` conditions. The application must provide
|
|
@@ -721,6 +619,107 @@ interface NormalizedListPagesQuery {
|
|
|
721
619
|
* @returns Array of tag names for the current page
|
|
722
620
|
*/
|
|
723
621
|
type IfTagsResolver = () => string[];
|
|
622
|
+
import { PageRef as PageRef2, WikitextSettings as WikitextSettings3 } from "@wdprlib/ast";
|
|
623
|
+
interface IncludeAssignment {
|
|
624
|
+
key: string;
|
|
625
|
+
value: string;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Callback to fetch page content for include resolution.
|
|
629
|
+
* Returns the wikitext source of the page, or null if the page does not exist.
|
|
630
|
+
*
|
|
631
|
+
* @security The fetcher is called with user-provided page references.
|
|
632
|
+
* Implementations should validate and sanitize page references before
|
|
633
|
+
* using them in database queries or file system access.
|
|
634
|
+
*/
|
|
635
|
+
type IncludeFetcher = (pageRef: PageRef2) => string | null;
|
|
636
|
+
/**
|
|
637
|
+
* Async callback to fetch page content for include resolution.
|
|
638
|
+
* Returns a promise of the wikitext source, or null if the page does not exist.
|
|
639
|
+
*
|
|
640
|
+
* @security The fetcher is called with user-provided page references.
|
|
641
|
+
* Implementations should validate and sanitize page references before
|
|
642
|
+
* using them in database queries or file system access.
|
|
643
|
+
*/
|
|
644
|
+
type AsyncIncludeFetcher = (pageRef: PageRef2) => Promise<string | null>;
|
|
645
|
+
/**
|
|
646
|
+
* Options for resolveIncludes / resolveIncludesAsync.
|
|
647
|
+
*/
|
|
648
|
+
interface ResolveIncludesOptions {
|
|
649
|
+
/**
|
|
650
|
+
* Maximum number of expansion iterations (default: 10).
|
|
651
|
+
*
|
|
652
|
+
* Each iteration replaces all `[[include]]` directives in the current
|
|
653
|
+
* source with fetched content. Iteration stops when the source is
|
|
654
|
+
* unchanged or this limit is reached.
|
|
655
|
+
*/
|
|
656
|
+
maxIterations?: number;
|
|
657
|
+
/** Wikitext settings. If enablePageSyntax is false, includes are not expanded. */
|
|
658
|
+
settings?: WikitextSettings3;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* A single include directive found in raw source text.
|
|
662
|
+
*
|
|
663
|
+
* This represents the directive as it existed during the include expansion
|
|
664
|
+
* phase. It does not imply that the target exists, and it does not include
|
|
665
|
+
* nested dependencies introduced by the target source.
|
|
666
|
+
*/
|
|
667
|
+
interface IncludeReference {
|
|
668
|
+
/** Target page reference parsed from the directive. */
|
|
669
|
+
location: PageRef2;
|
|
670
|
+
/** Variable assignments parsed from the directive, preserving source order. */
|
|
671
|
+
assignments: IncludeAssignment[];
|
|
672
|
+
/** Index of the opening `[[`. */
|
|
673
|
+
start: number;
|
|
674
|
+
/** Index just past the closing `]]`. */
|
|
675
|
+
end: number;
|
|
676
|
+
/** Text between `[[include ` and the closing `]]`. */
|
|
677
|
+
inner: string;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Include dependency observed during iterative expansion.
|
|
681
|
+
*
|
|
682
|
+
* Unlike `IncludeReference`, this is collected after a fetchable include layer
|
|
683
|
+
* has actually been expanded. If an included page introduces another include,
|
|
684
|
+
* that nested directive appears as a later `IncludeDependency` with a higher
|
|
685
|
+
* `iteration`.
|
|
686
|
+
*/
|
|
687
|
+
interface IncludeDependency extends IncludeReference {
|
|
688
|
+
/** Zero-based expansion iteration where this directive was observed. */
|
|
689
|
+
iteration: number;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Trace data for one include expansion iteration.
|
|
693
|
+
*
|
|
694
|
+
* `directives` is the scan result before replacements for that iteration.
|
|
695
|
+
* `changed` is false for stable self-includes where replacing the directive
|
|
696
|
+
* produces the same source again; the resolver stops at that point.
|
|
697
|
+
*/
|
|
698
|
+
interface IncludeIterationTrace {
|
|
699
|
+
/** Zero-based expansion iteration. */
|
|
700
|
+
iteration: number;
|
|
701
|
+
/** Include directives found in the source for this iteration. */
|
|
702
|
+
directives: IncludeReference[];
|
|
703
|
+
/** Whether replacing the directives changed the source. */
|
|
704
|
+
changed: boolean;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Result returned by trace-enabled include expansion.
|
|
708
|
+
*
|
|
709
|
+
* The `source` field is intended to be byte-for-byte equivalent to
|
|
710
|
+
* `resolveIncludes(source, fetcher, options)` for the same inputs. The rest of
|
|
711
|
+
* the object is diagnostic data for dependency collection and cache planning.
|
|
712
|
+
*/
|
|
713
|
+
interface ResolveIncludesTraceResult {
|
|
714
|
+
/** Final expanded source. */
|
|
715
|
+
source: string;
|
|
716
|
+
/** Include dependencies observed across all expansion iterations. */
|
|
717
|
+
dependencies: IncludeDependency[];
|
|
718
|
+
/** Per-iteration include scan and change information. */
|
|
719
|
+
iterations: IncludeIterationTrace[];
|
|
720
|
+
/** True when expansion stopped with directives still present after hitting the iteration cap. */
|
|
721
|
+
reachedMaxIterations: boolean;
|
|
722
|
+
}
|
|
724
723
|
/**
|
|
725
724
|
* Callback bag for supplying external data during module resolution.
|
|
726
725
|
*
|
|
@@ -752,6 +751,15 @@ interface DataProvider {
|
|
|
752
751
|
*/
|
|
753
752
|
fetchListUsers?: ListUsersDataFetcher;
|
|
754
753
|
/**
|
|
754
|
+
* Fetch raw wikitext for `[[include]]` directives that are created during
|
|
755
|
+
* module secondary transformations such as ListPages/ListUsers item rendering.
|
|
756
|
+
*
|
|
757
|
+
* Top-level include expansion still uses `resolveIncludes()` directly before
|
|
758
|
+
* parsing. This callback is only for module-rendered wikitext that needs its
|
|
759
|
+
* own include pass before being parsed again.
|
|
760
|
+
*/
|
|
761
|
+
fetchInclude?: IncludeFetcher;
|
|
762
|
+
/**
|
|
755
763
|
* Return the current page's tags for `[[iftags]]` evaluation.
|
|
756
764
|
*
|
|
757
765
|
* If provided, `[[iftags]]` blocks are evaluated and either kept or
|
|
@@ -803,70 +811,27 @@ declare function extractDataRequirements(ast: SyntaxTree): ExtractionResult;
|
|
|
803
811
|
*/
|
|
804
812
|
declare function compileTemplate(template: string): CompiledTemplate;
|
|
805
813
|
/**
|
|
806
|
-
* Parse tags string into structured format
|
|
807
|
-
*
|
|
808
|
-
* Syntax:
|
|
809
|
-
* - `+tag`: AND condition (must have this tag)
|
|
810
|
-
* - `-tag`: NOT condition (must not have this tag)
|
|
811
|
-
* - `tag`: OR condition (any of these tags)
|
|
812
|
-
* - `=`: same visible tags as current page
|
|
813
|
-
* - `==`: exact same tags as current page
|
|
814
|
-
* - `-`: pages with no tags
|
|
814
|
+
* Parse tags string into structured format.
|
|
815
815
|
*/
|
|
816
816
|
declare function parseTags(value: string): NormalizedTags;
|
|
817
817
|
/**
|
|
818
|
-
* Parse category string into structured format
|
|
819
|
-
*
|
|
820
|
-
* Syntax:
|
|
821
|
-
* - `*`: all categories
|
|
822
|
-
* - `.`: current category
|
|
823
|
-
* - `-category`: exclude category
|
|
824
|
-
* - `category`: include category
|
|
825
|
-
* - Multiple categories separated by comma, semicolon, or whitespace
|
|
818
|
+
* Parse category string into structured format.
|
|
826
819
|
*/
|
|
827
820
|
declare function parseCategory(value: string): NormalizedCategory;
|
|
828
821
|
/**
|
|
829
|
-
* Parse order string into structured format
|
|
830
|
-
*
|
|
831
|
-
* Supports both formats:
|
|
832
|
-
* - camelCase: `dateCreatedDesc`, `titleAsc`, `ratingDesc`
|
|
833
|
-
* - Space-separated: `created_at desc`, `title asc`
|
|
834
|
-
*
|
|
835
|
-
* Default: { field: "created_at", direction: "desc" }
|
|
822
|
+
* Parse order string into structured format.
|
|
836
823
|
*/
|
|
837
824
|
declare function parseOrder(value: string): NormalizedOrder;
|
|
838
825
|
/**
|
|
839
|
-
* Parse parent string into structured format
|
|
840
|
-
*
|
|
841
|
-
* Syntax:
|
|
842
|
-
* - `-`: orphan pages (no parent)
|
|
843
|
-
* - `=`: sibling pages (same parent as current)
|
|
844
|
-
* - `-=`: pages with different parent
|
|
845
|
-
* - `.`: children of current page
|
|
846
|
-
* - `page-name`: children of specific page
|
|
847
|
-
*
|
|
848
|
-
* Returns undefined for empty/whitespace-only input.
|
|
826
|
+
* Parse parent string into structured format.
|
|
849
827
|
*/
|
|
850
828
|
declare function parseParent(value: string): NormalizedParent | undefined;
|
|
851
829
|
/**
|
|
852
|
-
* Parse date selector string into structured format
|
|
853
|
-
*
|
|
854
|
-
* Syntax:
|
|
855
|
-
* - `yyyy`: year only
|
|
856
|
-
* - `yyyy.mm`: year and month
|
|
857
|
-
* - `>=yyyy.mm.dd`: comparison with date
|
|
858
|
-
* - `last 7 days`: relative date
|
|
830
|
+
* Parse date selector string into structured format.
|
|
859
831
|
*/
|
|
860
832
|
declare function parseDateSelector(value: string): NormalizedDateSelector | undefined;
|
|
861
833
|
/**
|
|
862
|
-
* Parse numeric selector string into structured format
|
|
863
|
-
*
|
|
864
|
-
* Syntax:
|
|
865
|
-
* - `5`: equals 5
|
|
866
|
-
* - `>=10`: greater than or equal to 10
|
|
867
|
-
* - `<0`: less than 0
|
|
868
|
-
*
|
|
869
|
-
* Returns undefined for non-numeric or infinite values.
|
|
834
|
+
* Parse numeric selector string into structured format.
|
|
870
835
|
*/
|
|
871
836
|
declare function parseNumericSelector(value: string): NormalizedNumericSelector | undefined;
|
|
872
837
|
/**
|
|
@@ -897,71 +862,49 @@ declare function normalizeQuery(query: ListPagesQuery): NormalizedListPagesQuery
|
|
|
897
862
|
* unmatched iftags removed entirely.
|
|
898
863
|
*/
|
|
899
864
|
declare function preprocessIftags(source: string, pageTags: string[] | null): string;
|
|
900
|
-
import { PageRef, WikitextSettings as WikitextSettings3 } from "@wdprlib/ast";
|
|
901
|
-
/**
|
|
902
|
-
* Callback to fetch page content for include resolution.
|
|
903
|
-
* Returns the wikitext source of the page, or null if the page does not exist.
|
|
904
|
-
*
|
|
905
|
-
* @security The fetcher is called with user-provided page references.
|
|
906
|
-
* Implementations should validate and sanitize page references before
|
|
907
|
-
* using them in database queries or file system access.
|
|
908
|
-
*/
|
|
909
|
-
type IncludeFetcher = (pageRef: PageRef) => string | null;
|
|
910
|
-
/**
|
|
911
|
-
* Async callback to fetch page content for include resolution.
|
|
912
|
-
* Returns a promise of the wikitext source, or null if the page does not exist.
|
|
913
|
-
*
|
|
914
|
-
* @security The fetcher is called with user-provided page references.
|
|
915
|
-
* Implementations should validate and sanitize page references before
|
|
916
|
-
* using them in database queries or file system access.
|
|
917
|
-
*/
|
|
918
|
-
type AsyncIncludeFetcher = (pageRef: PageRef) => Promise<string | null>;
|
|
919
|
-
/**
|
|
920
|
-
* Options for resolveIncludes / resolveIncludesAsync
|
|
921
|
-
*/
|
|
922
|
-
interface ResolveIncludesOptions {
|
|
923
|
-
/**
|
|
924
|
-
* Maximum number of expansion iterations (default: 10).
|
|
925
|
-
*
|
|
926
|
-
* Each iteration replaces all `[[include]]` directives in the current
|
|
927
|
-
* source with fetched content. Iteration stops when the source is
|
|
928
|
-
* unchanged or this limit is reached.
|
|
929
|
-
*/
|
|
930
|
-
maxIterations?: number;
|
|
931
|
-
/** Wikitext settings. If enablePageSyntax is false, includes are not expanded. */
|
|
932
|
-
settings?: WikitextSettings3;
|
|
933
|
-
}
|
|
934
865
|
/**
|
|
935
866
|
* Expand all [[include]] directives in the source text.
|
|
936
867
|
*
|
|
937
868
|
* Uses Wikidot-compatible iterative expansion: each iteration replaces
|
|
938
|
-
* all include directives in the current source with fetched
|
|
939
|
-
* variable-substituted
|
|
869
|
+
* all include directives in the current source with fetched and
|
|
870
|
+
* variable-substituted content. Iteration continues until no further
|
|
940
871
|
* changes occur or `maxIterations` is reached.
|
|
941
|
-
*
|
|
942
|
-
* @example
|
|
943
|
-
* ```ts
|
|
944
|
-
* const expanded = resolveIncludes(source, fetcher);
|
|
945
|
-
* const ast = parse(expanded);
|
|
946
|
-
* ```
|
|
947
872
|
*/
|
|
948
873
|
declare function resolveIncludes(source: string, fetcher: IncludeFetcher, options?: ResolveIncludesOptions): string;
|
|
949
874
|
/**
|
|
875
|
+
* Expand all [[include]] directives and return dependency/iteration trace data.
|
|
876
|
+
*
|
|
877
|
+
* This follows the same sync expansion behavior as {@link resolveIncludes};
|
|
878
|
+
* the additional trace data is intended for application-level dependency
|
|
879
|
+
* graphs, cache invalidation, and diagnostics.
|
|
880
|
+
*/
|
|
881
|
+
declare function resolveIncludesWithTrace(source: string, fetcher: IncludeFetcher, options?: ResolveIncludesOptions): ResolveIncludesTraceResult;
|
|
882
|
+
/**
|
|
950
883
|
* Async version of {@link resolveIncludes}.
|
|
951
884
|
*
|
|
952
885
|
* Expand all [[include]] directives using an async fetcher, allowing
|
|
953
886
|
* page content to be loaded from async sources such as databases.
|
|
954
|
-
*
|
|
955
|
-
* @example
|
|
956
|
-
* ```ts
|
|
957
|
-
* const expanded = await resolveIncludesAsync(source, async (ref) => {
|
|
958
|
-
* return await db.getPageContent(ref.page);
|
|
959
|
-
* });
|
|
960
|
-
* const ast = parse(expanded);
|
|
961
|
-
* ```
|
|
962
887
|
*/
|
|
963
888
|
declare function resolveIncludesAsync(source: string, fetcher: AsyncIncludeFetcher, options?: ResolveIncludesOptions): Promise<string>;
|
|
964
889
|
/**
|
|
890
|
+
* Extract include directives from raw source without fetching or expanding them.
|
|
891
|
+
*
|
|
892
|
+
* This uses the same scanner and directive parser as `resolveIncludes`, so it
|
|
893
|
+
* reports only directives that the include expansion pass would recognize.
|
|
894
|
+
*
|
|
895
|
+
* This is a source-phase API. It intentionally does not evaluate later syntax
|
|
896
|
+
* such as comments, expressions, or iftags. Wikidot expands includes before
|
|
897
|
+
* those phases, so an include inside a later comment block is still reported,
|
|
898
|
+
* while a token that only becomes `[[include ...]]` after comment/expression/
|
|
899
|
+
* iftags processing is not reported.
|
|
900
|
+
*
|
|
901
|
+
* The result is not a complete transitive dependency graph. Nested includes
|
|
902
|
+
* only become visible after fetching and expanding the current layer; use
|
|
903
|
+
* `resolveIncludesWithTrace` when the caller needs observed dependency edges
|
|
904
|
+
* across iterative expansion.
|
|
905
|
+
*/
|
|
906
|
+
declare function extractIncludeReferences(source: string, options?: ResolveIncludesOptions): IncludeReference[];
|
|
907
|
+
/**
|
|
965
908
|
* Compile a ListUsers template string into an executable function.
|
|
966
909
|
*
|
|
967
910
|
* The template is split into alternating static strings and dynamic getter
|
|
@@ -981,7 +924,7 @@ declare function compileListUsersTemplate(template: string): ListUsersCompiledTe
|
|
|
981
924
|
* @returns Deduplicated array of referenced variable names
|
|
982
925
|
*/
|
|
983
926
|
declare function extractListUsersVariables(template: string): ListUsersVariable[];
|
|
984
|
-
import { Element as
|
|
927
|
+
import { Element as Element6, Module as Module3 } from "@wdprlib/ast";
|
|
985
928
|
/**
|
|
986
929
|
* Narrowed type for the list-users variant of the Module discriminated union.
|
|
987
930
|
*/
|
|
@@ -1008,9 +951,22 @@ declare function isListUsersModule(module: Module3): module is ListUsersModuleDa
|
|
|
1008
951
|
* @param parse - Parser function for re-parsing the substituted template as wikitext
|
|
1009
952
|
* @returns Array of AST elements produced by parsing the rendered template
|
|
1010
953
|
*/
|
|
1011
|
-
declare function resolveListUsers(_module: ListUsersModuleData, data: ListUsersExternalData, compiledTemplate: ListUsersCompiledTemplate, parse: ParseFunction):
|
|
954
|
+
declare function resolveListUsers(_module: ListUsersModuleData, data: ListUsersExternalData, compiledTemplate: ListUsersCompiledTemplate, parse: ParseFunction): Element6[];
|
|
1012
955
|
import { SyntaxTree as SyntaxTree2 } from "@wdprlib/ast";
|
|
1013
956
|
/**
|
|
957
|
+
* Transform module-generated wikitext before it is parsed back into AST nodes.
|
|
958
|
+
*
|
|
959
|
+
* Applications can use this hook to inject include resolution, parse caches, or
|
|
960
|
+
* diagnostics for ListPages/ListUsers secondary transformations.
|
|
961
|
+
*
|
|
962
|
+
* This hook receives the string after module variables such as `%%title%%` have
|
|
963
|
+
* already been substituted. Returning a different string changes what is parsed
|
|
964
|
+
* for that module item. When this hook is supplied it replaces the built-in
|
|
965
|
+
* secondary include pass, so callers that still need Wikidot-style secondary
|
|
966
|
+
* includes must call `resolveIncludes()` or equivalent logic from the hook.
|
|
967
|
+
*/
|
|
968
|
+
type ModuleSourceTransform = (source: string) => string;
|
|
969
|
+
/**
|
|
1014
970
|
* Configuration for {@link resolveModules}.
|
|
1015
971
|
*
|
|
1016
972
|
* Callers must supply pre-extracted requirements and pre-compiled
|
|
@@ -1043,6 +999,26 @@ interface ResolveOptions {
|
|
|
1043
999
|
* with the corresponding values from this path.
|
|
1044
1000
|
*/
|
|
1045
1001
|
urlPath?: string;
|
|
1002
|
+
/**
|
|
1003
|
+
* Maximum include expansion iterations for secondary transformations inside
|
|
1004
|
+
* modules such as ListPages/ListUsers. Defaults to Wikidot's observed
|
|
1005
|
+
* secondary transformation limit.
|
|
1006
|
+
*/
|
|
1007
|
+
includeMaxIterations?: number;
|
|
1008
|
+
/**
|
|
1009
|
+
* Transform module-generated wikitext before re-parsing it.
|
|
1010
|
+
*
|
|
1011
|
+
* When omitted, `resolveModules()` preserves the existing default: if
|
|
1012
|
+
* `dataProvider.fetchInclude` is present, secondary `[[include]]` expansion
|
|
1013
|
+
* is performed with `includeMaxIterations`; otherwise the source is parsed
|
|
1014
|
+
* unchanged. When supplied, this hook owns the whole transformation.
|
|
1015
|
+
*
|
|
1016
|
+
* This is the extension point for application-level parse/include caches. The
|
|
1017
|
+
* parser package does not persist cache entries itself because cache keys and
|
|
1018
|
+
* invalidation depend on site/page revisions, tags, URL parameters, and user
|
|
1019
|
+
* state outside wdpr.
|
|
1020
|
+
*/
|
|
1021
|
+
transformModuleSource?: ModuleSourceTransform;
|
|
1046
1022
|
}
|
|
1047
1023
|
/**
|
|
1048
1024
|
* Resolve all modules in the AST
|
|
@@ -1060,4 +1036,4 @@ interface ResolveOptions {
|
|
|
1060
1036
|
*/
|
|
1061
1037
|
declare function resolveModules(ast: SyntaxTree2, dataProvider: DataProvider, options: ResolveOptions): Promise<SyntaxTree2>;
|
|
1062
1038
|
import { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
|
|
1063
|
-
export { tokenize, text, resolveModules, resolveListUsers, resolveIncludesAsync, resolveIncludes, preprocessIftags, parseTags, parseParent, parseOrder, parseNumericSelector, parseDateSelector, parseCategory, parse, paragraph, normalizeQuery, listItemSubList, listItemElements, list, link, lineBreak, italics, isListUsersModule, horizontalRule, heading, extractListUsersVariables, extractDataRequirements, createToken, createSettings, createPosition, createPoint, container, compileTemplate, compileListUsersTemplate, bold, WikitextSettings4 as WikitextSettings, WikitextMode, Version2 as Version, VariableMap, VariableContext, UserInfo, TokenType, Token, TocEntry2 as TocEntry, TableRow, TableData, TableCell, TabData, SyntaxTree3 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesOptions, Position2 as Position, Point, ParserOptions, Parser,
|
|
1039
|
+
export { tokenize, text, resolveModules, resolveListUsers, resolveIncludesWithTrace, resolveIncludesAsync, resolveIncludes, preprocessIftags, parseTags, parseParent, parseOrder, parseNumericSelector, parseDateSelector, parseCategory, parse, paragraph, normalizeQuery, listItemSubList, listItemElements, list, link, lineBreak, italics, isListUsersModule, horizontalRule, heading, extractListUsersVariables, extractIncludeReferences, extractDataRequirements, createToken, createSettings, createPosition, createPoint, container, compileTemplate, compileListUsersTemplate, bold, WikitextSettings4 as WikitextSettings, WikitextMode, Version2 as Version, VariableMap, VariableContext, UserInfo, TokenType, Token, TocEntry2 as TocEntry, TableRow, TableData, TableCell, TabData, SyntaxTree3 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesTraceResult, ResolveIncludesOptions, Position2 as Position, Point, ParserOptions, Parser, ParseResult3 as ParseResult, ParseFunction, PageRef3 as PageRef, PageData, NormalizedTags, NormalizedParent, NormalizedOrder, NormalizedNumericSelector, NormalizedListPagesQuery, NormalizedDateSelector, NormalizedCategory, ModuleSourceTransform, Module4 as Module, ListUsersVariableContext, ListUsersVariable, ListUsersUserData, ListUsersExternalData, ListUsersDataRequirement, ListUsersDataFetcher, ListUsersCompiledTemplate, ListType, ListPagesVariable, ListPagesQuery, ListPagesExternalData, ListPagesDataRequirement, ListPagesDataFetcher, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LexerOptions, Lexer, IncludeReference, IncludeIterationTrace, IncludeFetcher, IncludeDependency, ImageSource, HeadingLevel, Heading, HeaderType, FloatAlignment, ExtractionResult, Embed, Element7 as Element, DiagnosticSeverity, Diagnostic2 as Diagnostic, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AsyncIncludeFetcher, AnchorTarget, Alignment, AlignType };
|