@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,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches the opening `[[include` token at the start of a line.
|
|
3
|
+
*
|
|
4
|
+
* The `m` flag makes `^` match at line boundaries, enforcing the Wikidot
|
|
5
|
+
* rule that `[[include]]` must appear at the start of a line. The trailing
|
|
6
|
+
* `\s` separates the directive name from its arguments. The actual extent
|
|
7
|
+
* of each directive is found by scanIncludeDirectives, which balances nested
|
|
8
|
+
* `[[ ... ]]` so that block markup inside a parameter value does not terminate
|
|
9
|
+
* the directive at the first `]]`.
|
|
10
|
+
*/
|
|
11
|
+
const INCLUDE_OPEN_PATTERN = /^\[\[include\s/gim;
|
|
12
|
+
const OPEN_BRACKET = 91;
|
|
13
|
+
const CLOSE_BRACKET = 93;
|
|
14
|
+
|
|
15
|
+
/** A located `[[include ...]]` directive with bracket-balanced extent. */
|
|
16
|
+
export interface IncludeDirectiveMatch {
|
|
17
|
+
/** Index of the opening `[[`. */
|
|
18
|
+
start: number;
|
|
19
|
+
/** Index just past the closing `]]`. */
|
|
20
|
+
end: number;
|
|
21
|
+
/** Text between `[[include ` and the closing `]]`. */
|
|
22
|
+
inner: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Find all `[[include ...]]` directives in `source`, choosing each
|
|
27
|
+
* closing `]]` so that block markup inside a parameter value does not
|
|
28
|
+
* end the directive prematurely.
|
|
29
|
+
*/
|
|
30
|
+
export function scanIncludeDirectives(source: string): IncludeDirectiveMatch[] {
|
|
31
|
+
const matches: IncludeDirectiveMatch[] = [];
|
|
32
|
+
const opener = INCLUDE_OPEN_PATTERN;
|
|
33
|
+
opener.lastIndex = 0;
|
|
34
|
+
let match: RegExpExecArray | null;
|
|
35
|
+
|
|
36
|
+
while ((match = opener.exec(source)) !== null) {
|
|
37
|
+
const start = match.index;
|
|
38
|
+
const contentStart = start + match[0].length;
|
|
39
|
+
const firstNewline = source.indexOf("\n", start);
|
|
40
|
+
|
|
41
|
+
let depth = 0;
|
|
42
|
+
let linkDepth = 0;
|
|
43
|
+
let i = start;
|
|
44
|
+
let closeEnd = -1;
|
|
45
|
+
|
|
46
|
+
while (i < source.length) {
|
|
47
|
+
const ch = source.charCodeAt(i);
|
|
48
|
+
const next = source.charCodeAt(i + 1);
|
|
49
|
+
const nextNext = source.charCodeAt(i + 2);
|
|
50
|
+
|
|
51
|
+
if (ch === OPEN_BRACKET && next === OPEN_BRACKET && nextNext === OPEN_BRACKET) {
|
|
52
|
+
linkDepth++;
|
|
53
|
+
i += 3;
|
|
54
|
+
} else if (
|
|
55
|
+
linkDepth > 0 &&
|
|
56
|
+
ch === CLOSE_BRACKET &&
|
|
57
|
+
next === CLOSE_BRACKET &&
|
|
58
|
+
nextNext === CLOSE_BRACKET
|
|
59
|
+
) {
|
|
60
|
+
linkDepth--;
|
|
61
|
+
i += 3;
|
|
62
|
+
} else if (linkDepth > 0) {
|
|
63
|
+
i++;
|
|
64
|
+
} else if (ch === OPEN_BRACKET && next === OPEN_BRACKET) {
|
|
65
|
+
depth++;
|
|
66
|
+
i += 2;
|
|
67
|
+
} else if (ch === CLOSE_BRACKET && next === CLOSE_BRACKET) {
|
|
68
|
+
const closeStart = i;
|
|
69
|
+
depth--;
|
|
70
|
+
i += 2;
|
|
71
|
+
|
|
72
|
+
if (depth <= 0) {
|
|
73
|
+
const innerSoFar = source.slice(contentStart, closeStart);
|
|
74
|
+
if (hasAttributes(innerSoFar)) {
|
|
75
|
+
while (i < source.length && source[i] === "]") {
|
|
76
|
+
i++;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const onOpenerLine = firstNewline === -1 || closeStart < firstNewline;
|
|
80
|
+
if (onOpenerLine || isRestOfLineBlank(source, i)) {
|
|
81
|
+
closeEnd = i;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
i++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (closeEnd === -1) {
|
|
91
|
+
opener.lastIndex = start + 2;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
matches.push({ start, end: closeEnd, inner: source.slice(contentStart, closeEnd - 2) });
|
|
96
|
+
opener.lastIndex = closeEnd;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return matches;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Returns true when the directive's inner content carries an attribute section,
|
|
104
|
+
* either pipe-delimited (`|key=value`) or space-separated after the page name.
|
|
105
|
+
*/
|
|
106
|
+
function hasAttributes(innerSoFar: string): boolean {
|
|
107
|
+
if (innerSoFar.includes("|")) return true;
|
|
108
|
+
const trimmed = innerSoFar.trimStart();
|
|
109
|
+
const whitespaceIndex = trimmed.search(/\s/);
|
|
110
|
+
if (whitespaceIndex === -1) return false;
|
|
111
|
+
return trimmed.slice(whitespaceIndex).trim().length > 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function isRestOfLineBlank(source: string, pos: number): boolean {
|
|
115
|
+
for (let i = pos; i < source.length; i++) {
|
|
116
|
+
const ch = source[i];
|
|
117
|
+
if (ch === "\n") return true;
|
|
118
|
+
if (ch !== " " && ch !== "\t" && ch !== "\r") return false;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module system for Wikidot dynamic constructs.
|
|
3
|
+
*
|
|
4
|
+
* Wikidot supports several "module" blocks (`[[module ListPages]]`,
|
|
5
|
+
* `[[module ListUsers]]`, `[[module CSS]]`, etc.) and pseudo-blocks
|
|
6
|
+
* (`[[include]]`, `[[iftags]]`) that require external data to resolve.
|
|
7
|
+
*
|
|
8
|
+
* This barrel module re-exports everything needed to:
|
|
9
|
+
*
|
|
10
|
+
* 1. **Extract** data requirements from a parsed AST
|
|
11
|
+
* ({@link extractDataRequirements})
|
|
12
|
+
* 2. **Compile** body templates that contain `%%variable%%` placeholders
|
|
13
|
+
* ({@link compileTemplate}, {@link compileListUsersTemplate})
|
|
14
|
+
* 3. **Resolve** modules by injecting fetched data back into the AST
|
|
15
|
+
* ({@link resolveModules})
|
|
16
|
+
* 4. **Resolve includes** by fetching and inlining included pages
|
|
17
|
+
* ({@link resolveIncludes})
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// Module rule types and registry
|
|
23
|
+
export type { ModuleRule } from "./types";
|
|
24
|
+
export { MODULE_RULES, getModuleRuleByName } from "./mapping";
|
|
25
|
+
export { moduleRule } from "./rule";
|
|
26
|
+
|
|
27
|
+
// Module parsers
|
|
28
|
+
export { rateModuleRule } from "./rate/index";
|
|
29
|
+
export { cssModuleRule } from "./css/index";
|
|
30
|
+
export { backlinksModuleRule } from "./backlinks/index";
|
|
31
|
+
export { categoriesModuleRule } from "./categories/index";
|
|
32
|
+
export { joinModuleRule } from "./join/index";
|
|
33
|
+
export { pageTreeModuleRule } from "./page-tree/index";
|
|
34
|
+
export { listPagesModuleRule } from "./listpages/parser";
|
|
35
|
+
export { listUsersModuleRule } from "./listusers/parser";
|
|
36
|
+
|
|
37
|
+
// Module data types (parser-only modules)
|
|
38
|
+
export type { RateModuleData } from "./rate/types";
|
|
39
|
+
export type { BacklinksModuleData } from "./backlinks/types";
|
|
40
|
+
export type { CategoriesModuleData } from "./categories/types";
|
|
41
|
+
export type { JoinModuleData } from "./join/types";
|
|
42
|
+
export type { PageTreeModuleData } from "./page-tree/types";
|
|
43
|
+
|
|
44
|
+
// Common types
|
|
45
|
+
export type { DataProvider } from "./types-common";
|
|
46
|
+
|
|
47
|
+
// ListPages module
|
|
48
|
+
export type {
|
|
49
|
+
ListPagesQuery,
|
|
50
|
+
ListPagesVariable,
|
|
51
|
+
ListPagesDataRequirement,
|
|
52
|
+
DataRequirements,
|
|
53
|
+
UserInfo,
|
|
54
|
+
PageData,
|
|
55
|
+
SiteContext,
|
|
56
|
+
ListPagesExternalData,
|
|
57
|
+
ListPagesDataFetcher,
|
|
58
|
+
VariableContext,
|
|
59
|
+
CompiledTemplate,
|
|
60
|
+
ExtractionResult,
|
|
61
|
+
ParseFunction,
|
|
62
|
+
ListPagesModuleData,
|
|
63
|
+
// Normalized types
|
|
64
|
+
NormalizedListPagesQuery,
|
|
65
|
+
NormalizedTags,
|
|
66
|
+
NormalizedCategory,
|
|
67
|
+
NormalizedOrder,
|
|
68
|
+
NormalizedParent,
|
|
69
|
+
NormalizedDateSelector,
|
|
70
|
+
NormalizedNumericSelector,
|
|
71
|
+
} from "./listpages";
|
|
72
|
+
export {
|
|
73
|
+
extractDataRequirements,
|
|
74
|
+
isListPagesModule,
|
|
75
|
+
resolveListPages,
|
|
76
|
+
compileTemplate,
|
|
77
|
+
// Query normalization (for advanced use cases)
|
|
78
|
+
normalizeQuery,
|
|
79
|
+
parseTags,
|
|
80
|
+
parseCategory,
|
|
81
|
+
parseOrder,
|
|
82
|
+
parseParent,
|
|
83
|
+
parseDateSelector,
|
|
84
|
+
parseNumericSelector,
|
|
85
|
+
} from "./listpages";
|
|
86
|
+
|
|
87
|
+
// IfTags module
|
|
88
|
+
export type { TagCondition, IfTagsResolver, IfTagsData, IfTagsResolveResult } from "./iftags";
|
|
89
|
+
export {
|
|
90
|
+
parseTagCondition,
|
|
91
|
+
evaluateTagCondition,
|
|
92
|
+
isIfTagsElement,
|
|
93
|
+
resolveIfTags,
|
|
94
|
+
preprocessIftags,
|
|
95
|
+
} from "./iftags";
|
|
96
|
+
|
|
97
|
+
// Include module
|
|
98
|
+
export type { IncludeFetcher, AsyncIncludeFetcher, ResolveIncludesOptions } from "./include";
|
|
99
|
+
export type {
|
|
100
|
+
IncludeReference,
|
|
101
|
+
IncludeDependency,
|
|
102
|
+
IncludeIterationTrace,
|
|
103
|
+
ResolveIncludesTraceResult,
|
|
104
|
+
} from "./include";
|
|
105
|
+
export {
|
|
106
|
+
extractIncludeReferences,
|
|
107
|
+
resolveIncludes,
|
|
108
|
+
resolveIncludesAsync,
|
|
109
|
+
resolveIncludesWithTrace,
|
|
110
|
+
} from "./include";
|
|
111
|
+
|
|
112
|
+
// ListUsers module
|
|
113
|
+
export type {
|
|
114
|
+
ListUsersVariable,
|
|
115
|
+
ListUsersUserData,
|
|
116
|
+
ListUsersDataRequirement,
|
|
117
|
+
ListUsersExternalData,
|
|
118
|
+
ListUsersDataFetcher,
|
|
119
|
+
ListUsersVariableContext,
|
|
120
|
+
ListUsersCompiledTemplate,
|
|
121
|
+
ListUsersModuleData,
|
|
122
|
+
} from "./listusers";
|
|
123
|
+
export {
|
|
124
|
+
listUsersModuleRule as listUsersRule,
|
|
125
|
+
extractListUsersVariables,
|
|
126
|
+
compileListUsersTemplate,
|
|
127
|
+
isListUsersModule,
|
|
128
|
+
resolveListUsers,
|
|
129
|
+
} from "./listusers";
|
|
130
|
+
|
|
131
|
+
// Module resolver
|
|
132
|
+
export type { ModuleSourceTransform, ResolveOptions } from "./resolve";
|
|
133
|
+
export { resolveModules } from "./resolve";
|
|
134
|
+
export { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Parser rule for the Wikidot `[[module Join]]` block.
|
|
4
|
+
*
|
|
5
|
+
* Renders a "Join this site" button. Accepts an optional `button` attribute
|
|
6
|
+
* to customize the button text.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { ModuleRule } from "../types";
|
|
12
|
+
import type { JoinModuleData } from "./types";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Module rule for `[[module Join]]`.
|
|
16
|
+
*
|
|
17
|
+
* Extracts the `button` attribute as the custom button text. All other
|
|
18
|
+
* attributes are passed through in the `attributes` record for the
|
|
19
|
+
* rendering application to handle.
|
|
20
|
+
*/
|
|
21
|
+
export const joinModuleRule: ModuleRule = {
|
|
22
|
+
name: "module-join",
|
|
23
|
+
acceptsNames: ["join"],
|
|
24
|
+
hasBody: false,
|
|
25
|
+
|
|
26
|
+
parse(_ctx, _pos, args): JoinModuleData {
|
|
27
|
+
const { button, ...rest } = args;
|
|
28
|
+
return {
|
|
29
|
+
module: "join",
|
|
30
|
+
"button-text": button ?? null,
|
|
31
|
+
attributes: rest,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Type definitions for the Join module.
|
|
4
|
+
*
|
|
5
|
+
* The `[[module Join]]` block renders a "Join this site" button that allows
|
|
6
|
+
* visitors to apply for site membership.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* AST data for a `[[module Join]]` element.
|
|
13
|
+
*
|
|
14
|
+
* The rendering application should display a membership application button
|
|
15
|
+
* with the specified text.
|
|
16
|
+
*/
|
|
17
|
+
export interface JoinModuleData {
|
|
18
|
+
module: "join";
|
|
19
|
+
/** Custom button text, or null to use the default "Join this Site" text */
|
|
20
|
+
"button-text": string | null;
|
|
21
|
+
/** Additional attributes passed to the module */
|
|
22
|
+
attributes: Record<string, string>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Template compiler for the ListPages module.
|
|
4
|
+
*
|
|
5
|
+
* Compiles ListPages template strings (e.g., `"%%title%% by %%created_by%%"`)
|
|
6
|
+
* into executable functions that can be called repeatedly with different page
|
|
7
|
+
* data for fast rendering. The compilation step splits the template into static
|
|
8
|
+
* string segments and dynamic getter functions, avoiding repeated regex matching
|
|
9
|
+
* during rendering.
|
|
10
|
+
*
|
|
11
|
+
* Supported variable syntax:
|
|
12
|
+
* - `%%name%%` - Simple variable (e.g., `%%title%%`, `%%rating%%`)
|
|
13
|
+
* - `%%name{param}%%` - Parameterized variable (e.g., `%%content{2}%%`, `%%form_data{color}%%`)
|
|
14
|
+
* - `%%name(param)%%` - Parenthesized parameter (e.g., `%%preview(100)%%`)
|
|
15
|
+
* - `%%name|format%%` - Formatted variable (e.g., `%%created_at|%Y-%m-%d%%`, `%%tags_linked|/tag/%%`)
|
|
16
|
+
*
|
|
17
|
+
* The compiled function is a closure over the parsed template parts, providing
|
|
18
|
+
* O(n) rendering time proportional to the number of template segments.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { CompiledTemplate, VariableContext } from "./types";
|
|
24
|
+
import { createVariableGetter } from "./template/getters";
|
|
25
|
+
import { scanTemplateVariables } from "./template/syntax";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Compile a ListPages template string into an executable function.
|
|
29
|
+
*
|
|
30
|
+
* The template is split into alternating static strings and dynamic getter
|
|
31
|
+
* functions. The returned function concatenates these parts with the getter
|
|
32
|
+
* functions evaluated against the provided variable context.
|
|
33
|
+
*
|
|
34
|
+
* @param template - The template string containing `%%variable%%` placeholders
|
|
35
|
+
* @returns A compiled function that accepts a `VariableContext` and returns the rendered string
|
|
36
|
+
*/
|
|
37
|
+
export function compileTemplate(template: string): CompiledTemplate {
|
|
38
|
+
const parts: (string | ((ctx: VariableContext) => string))[] = [];
|
|
39
|
+
let lastIndex = 0;
|
|
40
|
+
|
|
41
|
+
// Split template into static and dynamic parts
|
|
42
|
+
for (const match of scanTemplateVariables(template)) {
|
|
43
|
+
// Add static part before this match
|
|
44
|
+
if (match.index > lastIndex) {
|
|
45
|
+
parts.push(template.slice(lastIndex, match.index));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Convert variable to getter function
|
|
49
|
+
const getter = createVariableGetter(
|
|
50
|
+
match.name.toLowerCase(),
|
|
51
|
+
match.braceParam,
|
|
52
|
+
match.parenParam,
|
|
53
|
+
match.format,
|
|
54
|
+
);
|
|
55
|
+
parts.push(getter);
|
|
56
|
+
|
|
57
|
+
lastIndex = match.index + match.raw.length;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Add remaining static part
|
|
61
|
+
if (lastIndex < template.length) {
|
|
62
|
+
parts.push(template.slice(lastIndex));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Return compiled function
|
|
66
|
+
return (ctx: VariableContext): string => {
|
|
67
|
+
let result = "";
|
|
68
|
+
for (const part of parts) {
|
|
69
|
+
result += typeof part === "string" ? part : part(ctx);
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Data requirement extraction from parsed ASTs.
|
|
4
|
+
*
|
|
5
|
+
* After parsing, the AST may contain ListPages and ListUsers module nodes that
|
|
6
|
+
* need external data (page lists, user information) to be resolved. This module
|
|
7
|
+
* analyzes the AST to find all such modules, determines what variables their
|
|
8
|
+
* templates use (and therefore what data fields the external provider must supply),
|
|
9
|
+
* and pre-compiles their templates for efficient rendering during the resolution phase.
|
|
10
|
+
*
|
|
11
|
+
* The extraction result includes:
|
|
12
|
+
* - `DataRequirements` listing all ListPages/ListUsers queries with their needed variables
|
|
13
|
+
* - Pre-compiled template functions keyed by module ID for fast rendering
|
|
14
|
+
*
|
|
15
|
+
* This is the first phase of the three-phase ListPages lifecycle:
|
|
16
|
+
* 1. **Extract** (this module) - Analyze AST, determine data needs, compile templates
|
|
17
|
+
* 2. **Fetch** (external) - Application fetches data based on requirements
|
|
18
|
+
* 3. **Resolve** - Substitute fetched data into compiled templates and re-parse
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { SyntaxTree } from "@wdprlib/ast";
|
|
24
|
+
import { walkElements } from "../walk";
|
|
25
|
+
import {
|
|
26
|
+
extractListPagesModule,
|
|
27
|
+
isListPagesModule,
|
|
28
|
+
type ListPagesExtractionState,
|
|
29
|
+
} from "./extraction/listpages";
|
|
30
|
+
import {
|
|
31
|
+
extractListUsersModule,
|
|
32
|
+
isListUsersModule,
|
|
33
|
+
type ListUsersExtractionState,
|
|
34
|
+
} from "./extraction/listusers";
|
|
35
|
+
import type { ExtractionResult } from "./extraction/result";
|
|
36
|
+
export type { ExtractionResult } from "./extraction/result";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Extract all data requirements from a parsed AST.
|
|
40
|
+
*
|
|
41
|
+
* Walks the entire AST to find ListPages and ListUsers module elements,
|
|
42
|
+
* analyzes their templates to determine which variables are used, builds
|
|
43
|
+
* query objects from their attributes, and pre-compiles their templates.
|
|
44
|
+
*
|
|
45
|
+
* Each module is assigned a sequential ID (separate counters for ListPages
|
|
46
|
+
* and ListUsers) that is used to correlate requirements with fetched data
|
|
47
|
+
* and compiled templates during the resolution phase.
|
|
48
|
+
*
|
|
49
|
+
* @param ast - The parsed syntax tree to analyze
|
|
50
|
+
* @returns Extraction result containing requirements and compiled templates
|
|
51
|
+
*/
|
|
52
|
+
export function extractDataRequirements(ast: SyntaxTree): ExtractionResult {
|
|
53
|
+
const result: ExtractionResult = {
|
|
54
|
+
requirements: {
|
|
55
|
+
listPages: [],
|
|
56
|
+
listUsers: [],
|
|
57
|
+
},
|
|
58
|
+
compiledListPagesTemplates: new Map(),
|
|
59
|
+
compiledListUsersTemplates: new Map(),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const listPagesState: ListPagesExtractionState = { nextId: 0 };
|
|
63
|
+
const listUsersState: ListUsersExtractionState = { nextId: 0 };
|
|
64
|
+
|
|
65
|
+
walkElements(ast.elements, (element) => {
|
|
66
|
+
if (element.element !== "module") return;
|
|
67
|
+
|
|
68
|
+
if (isListPagesModule(element.data)) {
|
|
69
|
+
extractListPagesModule(element.data, listPagesState, result);
|
|
70
|
+
} else if (isListUsersModule(element.data)) {
|
|
71
|
+
extractListUsersModule(element.data, listUsersState, result);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Module } from "@wdprlib/ast";
|
|
2
|
+
import type { ListPagesQuery } from "../types";
|
|
3
|
+
import { compileTemplate } from "../compiler";
|
|
4
|
+
import { buildQuery } from "./query";
|
|
5
|
+
import { DEFAULT_BODY_TEMPLATE, extractVariablesFromTemplate } from "./template";
|
|
6
|
+
import type { ExtractionResult } from "./result";
|
|
7
|
+
|
|
8
|
+
export type ListPagesModuleForExtraction = Extract<Module, { module: "list-pages" }>;
|
|
9
|
+
|
|
10
|
+
export interface ListPagesExtractionState {
|
|
11
|
+
nextId: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isListPagesModule(module: Module): module is ListPagesModuleForExtraction {
|
|
15
|
+
return module.module === "list-pages";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function extractListPagesModule(
|
|
19
|
+
listPages: ListPagesModuleForExtraction,
|
|
20
|
+
state: ListPagesExtractionState,
|
|
21
|
+
result: ExtractionResult,
|
|
22
|
+
): void {
|
|
23
|
+
const id = state.nextId++;
|
|
24
|
+
const body = listPages.body ?? DEFAULT_BODY_TEMPLATE;
|
|
25
|
+
const extraction = extractVariablesFromTemplate(body);
|
|
26
|
+
const query: ListPagesQuery = buildQuery(listPages);
|
|
27
|
+
|
|
28
|
+
result.requirements.listPages.push({
|
|
29
|
+
id,
|
|
30
|
+
query,
|
|
31
|
+
neededVariables: extraction.variables,
|
|
32
|
+
contentSectionIndices: extraction.contentIndices,
|
|
33
|
+
previewLengths: extraction.previewLengths,
|
|
34
|
+
formFields: extraction.formFields,
|
|
35
|
+
tagsLinkPrefix: extraction.tagsLinkPrefix,
|
|
36
|
+
hiddenTagsLinkPrefix: extraction.hiddenTagsLinkPrefix,
|
|
37
|
+
urlAttrPrefix: listPages["url-attr-prefix"],
|
|
38
|
+
rawAttributes: listPages.attributes ?? {},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
result.compiledListPagesTemplates.set(id, compileTemplate(body));
|
|
42
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Module } from "@wdprlib/ast";
|
|
2
|
+
import { compileListUsersTemplate, extractListUsersVariables } from "../../listusers/extract";
|
|
3
|
+
import type { ExtractionResult } from "./result";
|
|
4
|
+
|
|
5
|
+
export type ListUsersModuleForExtraction = Extract<Module, { module: "list-users" }>;
|
|
6
|
+
|
|
7
|
+
export interface ListUsersExtractionState {
|
|
8
|
+
nextId: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isListUsersModule(module: Module): module is ListUsersModuleForExtraction {
|
|
12
|
+
return module.module === "list-users";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function extractListUsersModule(
|
|
16
|
+
listUsers: ListUsersModuleForExtraction,
|
|
17
|
+
state: ListUsersExtractionState,
|
|
18
|
+
result: ExtractionResult,
|
|
19
|
+
): void {
|
|
20
|
+
const id = state.nextId++;
|
|
21
|
+
const body = listUsers.body ?? "";
|
|
22
|
+
|
|
23
|
+
result.requirements.listUsers.push({
|
|
24
|
+
id,
|
|
25
|
+
users: listUsers.users,
|
|
26
|
+
neededVariables: extractListUsersVariables(body),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
result.compiledListUsersTemplates.set(id, compileListUsersTemplate(body));
|
|
30
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Module } from "@wdprlib/ast";
|
|
2
|
+
import type { ListPagesQuery } from "../types";
|
|
3
|
+
|
|
4
|
+
type ListPagesModuleData = Extract<Module, { module: "list-pages" }>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Build a ListPagesQuery from the parsed module attributes.
|
|
8
|
+
*
|
|
9
|
+
* Maps module attribute names, which use kebab-case in the AST, to the query's
|
|
10
|
+
* camelCase property names. Data form fields prefixed with `_` are grouped under
|
|
11
|
+
* `dataFormFields`.
|
|
12
|
+
*/
|
|
13
|
+
export function buildQuery(module: ListPagesModuleData): ListPagesQuery {
|
|
14
|
+
return {
|
|
15
|
+
pagetype: module.pagetype as ListPagesQuery["pagetype"],
|
|
16
|
+
category: module.category,
|
|
17
|
+
tags: module.tags,
|
|
18
|
+
parent: module.parent,
|
|
19
|
+
linkTo: module["link-to"],
|
|
20
|
+
createdAt: module["created-at"],
|
|
21
|
+
updatedAt: module["updated-at"],
|
|
22
|
+
createdBy: module["created-by"],
|
|
23
|
+
rating: module.rating,
|
|
24
|
+
votes: module.votes,
|
|
25
|
+
name: module.name,
|
|
26
|
+
fullname: module.fullname,
|
|
27
|
+
range: module.range as ListPagesQuery["range"],
|
|
28
|
+
order: module.order,
|
|
29
|
+
offset: module.offset,
|
|
30
|
+
limit: module.limit,
|
|
31
|
+
perPage: module["per-page"],
|
|
32
|
+
reverse: module.reverse,
|
|
33
|
+
dataFormFields: extractDataFormFields(module.attributes),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function extractDataFormFields(
|
|
38
|
+
attributes: Record<string, string>,
|
|
39
|
+
): Record<string, string> | undefined {
|
|
40
|
+
const fields: Record<string, string> = {};
|
|
41
|
+
let hasFields = false;
|
|
42
|
+
|
|
43
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
44
|
+
if (key.startsWith("_")) {
|
|
45
|
+
fields[key.slice(1)] = value;
|
|
46
|
+
hasFields = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return hasFields ? fields : undefined;
|
|
51
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DataRequirements, CompiledTemplate } from "../types";
|
|
2
|
+
import type { ListUsersCompiledTemplate } from "../../listusers/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Complete result of extracting data requirements from an AST.
|
|
6
|
+
*
|
|
7
|
+
* Contains everything needed to fetch external data and then resolve modules:
|
|
8
|
+
* the data requirements tell the application what to fetch, and the pre-compiled
|
|
9
|
+
* templates are used during the resolution phase to efficiently render results.
|
|
10
|
+
*/
|
|
11
|
+
export interface ExtractionResult {
|
|
12
|
+
/** Data requirements for external fetching */
|
|
13
|
+
requirements: DataRequirements;
|
|
14
|
+
/** Pre-compiled ListPages templates keyed by module id */
|
|
15
|
+
compiledListPagesTemplates: Map<number, CompiledTemplate>;
|
|
16
|
+
/** Pre-compiled ListUsers templates keyed by module id */
|
|
17
|
+
compiledListUsersTemplates: Map<number, ListUsersCompiledTemplate>;
|
|
18
|
+
}
|