@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,96 @@
|
|
|
1
|
+
import type { ListPagesVariable } from "../types";
|
|
2
|
+
import { scanTemplateVariables } from "../template/syntax";
|
|
3
|
+
import { normalizeVariableName } from "./variables";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default template used when a ListPages module has no body specified.
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_BODY_TEMPLATE = `+ %%title_linked%%
|
|
9
|
+
|
|
10
|
+
by %%created_by_linked%% %%created_at%%
|
|
11
|
+
|
|
12
|
+
%%summary%%`;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal result of analyzing a ListPages template string for variable usage.
|
|
16
|
+
*/
|
|
17
|
+
export interface TemplateExtraction {
|
|
18
|
+
variables: ListPagesVariable[];
|
|
19
|
+
contentIndices: number[];
|
|
20
|
+
previewLengths: number[];
|
|
21
|
+
formFields: string[];
|
|
22
|
+
tagsLinkPrefix?: string;
|
|
23
|
+
hiddenTagsLinkPrefix?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Extract all variable references from a ListPages template string.
|
|
28
|
+
*/
|
|
29
|
+
export function extractVariablesFromTemplate(template: string): TemplateExtraction {
|
|
30
|
+
const variables = new Set<ListPagesVariable>();
|
|
31
|
+
const contentIndices = new Set<number>();
|
|
32
|
+
const previewLengths = new Set<number>();
|
|
33
|
+
const formFields = new Set<string>();
|
|
34
|
+
let tagsLinkPrefix: string | undefined;
|
|
35
|
+
let hiddenTagsLinkPrefix: string | undefined;
|
|
36
|
+
|
|
37
|
+
for (const match of scanTemplateVariables(template)) {
|
|
38
|
+
const varName = match.name.toLowerCase();
|
|
39
|
+
|
|
40
|
+
if (match.braceParam !== undefined) {
|
|
41
|
+
switch (varName) {
|
|
42
|
+
case "content":
|
|
43
|
+
contentIndices.add(Number(match.braceParam));
|
|
44
|
+
variables.add("content_n");
|
|
45
|
+
continue;
|
|
46
|
+
case "form_data":
|
|
47
|
+
formFields.add(match.braceParam);
|
|
48
|
+
variables.add("form_data");
|
|
49
|
+
continue;
|
|
50
|
+
case "form_raw":
|
|
51
|
+
formFields.add(match.braceParam);
|
|
52
|
+
variables.add("form_raw");
|
|
53
|
+
continue;
|
|
54
|
+
case "form_label":
|
|
55
|
+
formFields.add(match.braceParam);
|
|
56
|
+
variables.add("form_label");
|
|
57
|
+
continue;
|
|
58
|
+
case "form_hint":
|
|
59
|
+
formFields.add(match.braceParam);
|
|
60
|
+
variables.add("form_hint");
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (match.parenParam !== undefined && varName === "preview") {
|
|
66
|
+
previewLengths.add(Number(match.parenParam));
|
|
67
|
+
variables.add("preview_n");
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (varName === "tags_linked") {
|
|
72
|
+
if (match.format) tagsLinkPrefix = match.format;
|
|
73
|
+
variables.add("tags_linked");
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (varName === "_tags_linked") {
|
|
77
|
+
if (match.format) hiddenTagsLinkPrefix = match.format;
|
|
78
|
+
variables.add("_tags_linked");
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const normalized = normalizeVariableName(varName);
|
|
83
|
+
if (normalized) {
|
|
84
|
+
variables.add(normalized);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
variables: Array.from(variables),
|
|
90
|
+
contentIndices: Array.from(contentIndices).sort((a, b) => a - b),
|
|
91
|
+
previewLengths: Array.from(previewLengths).sort((a, b) => a - b),
|
|
92
|
+
formFields: Array.from(formFields).sort(),
|
|
93
|
+
tagsLinkPrefix,
|
|
94
|
+
hiddenTagsLinkPrefix,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ListPagesVariable } from "../types";
|
|
2
|
+
|
|
3
|
+
const KNOWN_VARIABLES: ReadonlySet<ListPagesVariable> = new Set([
|
|
4
|
+
"created_at",
|
|
5
|
+
"created_by",
|
|
6
|
+
"created_by_unix",
|
|
7
|
+
"created_by_id",
|
|
8
|
+
"created_by_linked",
|
|
9
|
+
"updated_at",
|
|
10
|
+
"updated_by",
|
|
11
|
+
"updated_by_unix",
|
|
12
|
+
"updated_by_id",
|
|
13
|
+
"updated_by_linked",
|
|
14
|
+
"commented_at",
|
|
15
|
+
"commented_by",
|
|
16
|
+
"commented_by_unix",
|
|
17
|
+
"commented_by_id",
|
|
18
|
+
"commented_by_linked",
|
|
19
|
+
"name",
|
|
20
|
+
"category",
|
|
21
|
+
"fullname",
|
|
22
|
+
"title",
|
|
23
|
+
"title_linked",
|
|
24
|
+
"link",
|
|
25
|
+
"parent_name",
|
|
26
|
+
"parent_category",
|
|
27
|
+
"parent_fullname",
|
|
28
|
+
"parent_title",
|
|
29
|
+
"parent_title_linked",
|
|
30
|
+
"content",
|
|
31
|
+
"preview",
|
|
32
|
+
"summary",
|
|
33
|
+
"first_paragraph",
|
|
34
|
+
"tags",
|
|
35
|
+
"_tags",
|
|
36
|
+
"children",
|
|
37
|
+
"comments",
|
|
38
|
+
"size",
|
|
39
|
+
"rating",
|
|
40
|
+
"rating_votes",
|
|
41
|
+
"rating_percent",
|
|
42
|
+
"revisions",
|
|
43
|
+
"index",
|
|
44
|
+
"total",
|
|
45
|
+
"limit",
|
|
46
|
+
"total_or_limit",
|
|
47
|
+
"site_title",
|
|
48
|
+
"site_name",
|
|
49
|
+
"site_domain",
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export function normalizeVariableName(name: string): ListPagesVariable | null {
|
|
53
|
+
if (KNOWN_VARIABLES.has(name as ListPagesVariable)) {
|
|
54
|
+
return name as ListPagesVariable;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* ListPages module for Wikidot's `[[module ListPages ...]]` block.
|
|
4
|
+
*
|
|
5
|
+
* This is the most feature-rich Wikidot module, enabling dynamic page listings
|
|
6
|
+
* with filtering, sorting, pagination, and template-based rendering. The module
|
|
7
|
+
* follows a three-phase lifecycle:
|
|
8
|
+
*
|
|
9
|
+
* 1. **Parse** - Convert `[[module ListPages ...]]` markup into an AST node
|
|
10
|
+
* 2. **Extract** - Analyze the AST to determine what data is needed (queries, template variables)
|
|
11
|
+
* 3. **Resolve** - Substitute fetched data into templates and re-parse as wikitext
|
|
12
|
+
*
|
|
13
|
+
* This barrel module re-exports all public types and functions from the sub-modules:
|
|
14
|
+
* - `parser` - Module rule for parsing ListPages markup
|
|
15
|
+
* - `types` - Query, variable, data requirement, and normalized query types
|
|
16
|
+
* - `extract` - AST analysis and data requirement extraction
|
|
17
|
+
* - `resolve` - Data substitution and template rendering
|
|
18
|
+
* - `compiler` - Template string compilation into executable functions
|
|
19
|
+
* - `url-resolver` - `@URL|default` parameter resolution for HPC support
|
|
20
|
+
* - `normalize` - Raw query string parsing into structured types
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// Parser
|
|
26
|
+
export { listPagesModuleRule } from "./parser";
|
|
27
|
+
|
|
28
|
+
// Types
|
|
29
|
+
export type {
|
|
30
|
+
ListPagesQuery,
|
|
31
|
+
ListPagesVariable,
|
|
32
|
+
ListPagesDataRequirement,
|
|
33
|
+
DataRequirements,
|
|
34
|
+
UserInfo,
|
|
35
|
+
PageData,
|
|
36
|
+
SiteContext,
|
|
37
|
+
ListPagesExternalData,
|
|
38
|
+
ListPagesDataFetcher,
|
|
39
|
+
VariableContext,
|
|
40
|
+
CompiledTemplate,
|
|
41
|
+
// Normalized types
|
|
42
|
+
NormalizedListPagesQuery,
|
|
43
|
+
NormalizedTags,
|
|
44
|
+
NormalizedCategory,
|
|
45
|
+
NormalizedOrder,
|
|
46
|
+
NormalizedParent,
|
|
47
|
+
NormalizedDateSelector,
|
|
48
|
+
NormalizedNumericSelector,
|
|
49
|
+
OrderField,
|
|
50
|
+
OrderDirection,
|
|
51
|
+
DateComparisonOp,
|
|
52
|
+
NumericComparisonOp,
|
|
53
|
+
} from "./types";
|
|
54
|
+
|
|
55
|
+
// Extraction
|
|
56
|
+
export type { ExtractionResult } from "./extract";
|
|
57
|
+
export { extractDataRequirements } from "./extract";
|
|
58
|
+
|
|
59
|
+
// Resolution
|
|
60
|
+
export type { ParseFunction, ListPagesModuleData } from "./resolve";
|
|
61
|
+
export { isListPagesModule, resolveListPages } from "./resolve";
|
|
62
|
+
|
|
63
|
+
// Compiler
|
|
64
|
+
export { compileTemplate } from "./compiler";
|
|
65
|
+
|
|
66
|
+
// URL Resolution
|
|
67
|
+
export {
|
|
68
|
+
parseUrlParams,
|
|
69
|
+
resolveUrlValue,
|
|
70
|
+
resolveQuery,
|
|
71
|
+
resolveAndNormalizeQuery,
|
|
72
|
+
} from "./url-resolver";
|
|
73
|
+
|
|
74
|
+
// Query Normalization
|
|
75
|
+
export {
|
|
76
|
+
normalizeQuery,
|
|
77
|
+
parseTags,
|
|
78
|
+
parseCategory,
|
|
79
|
+
parseOrder,
|
|
80
|
+
parseParent,
|
|
81
|
+
parseDateSelector,
|
|
82
|
+
parseNumericSelector,
|
|
83
|
+
} from "./normalize";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { DateComparisonOp, NormalizedDateSelector } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Date comparison operators, ordered longest-first.
|
|
5
|
+
*/
|
|
6
|
+
const DATE_COMPARISON_OPS: DateComparisonOp[] = ["<=", ">=", "<>", "<", ">", "="];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Pattern for relative date expressions like "last 7 days".
|
|
10
|
+
*/
|
|
11
|
+
const RELATIVE_DATE_PATTERN = /^last\s+(?:(\d+)\s+)?(day|week|month)s?$/i;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Parse date selector string into structured format.
|
|
15
|
+
*/
|
|
16
|
+
export function parseDateSelector(value: string): NormalizedDateSelector | undefined {
|
|
17
|
+
const trimmed = value.trim();
|
|
18
|
+
if (!trimmed) return undefined;
|
|
19
|
+
|
|
20
|
+
const relativeMatch = trimmed.match(RELATIVE_DATE_PATTERN);
|
|
21
|
+
if (relativeMatch && relativeMatch[2]) {
|
|
22
|
+
const count = relativeMatch[1] ? parseInt(relativeMatch[1], 10) : 1;
|
|
23
|
+
if (count < 1) return undefined;
|
|
24
|
+
const unit = relativeMatch[2].toLowerCase() as "day" | "week" | "month";
|
|
25
|
+
return { type: "relative", unit, count };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (const op of DATE_COMPARISON_OPS) {
|
|
29
|
+
if (trimmed.startsWith(op)) {
|
|
30
|
+
const date = trimmed.slice(op.length).trim();
|
|
31
|
+
if (date) {
|
|
32
|
+
return { type: "comparison", op, date };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (/^\d{4}$/.test(trimmed)) {
|
|
38
|
+
return { type: "year", year: parseInt(trimmed, 10) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const monthMatch = trimmed.match(/^(\d{4})\.(\d{1,2})$/);
|
|
42
|
+
if (monthMatch && monthMatch[1] && monthMatch[2]) {
|
|
43
|
+
const month = parseInt(monthMatch[2], 10);
|
|
44
|
+
if (month < 1 || month > 12) return undefined;
|
|
45
|
+
return {
|
|
46
|
+
type: "month",
|
|
47
|
+
year: parseInt(monthMatch[1], 10),
|
|
48
|
+
month,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { NormalizedNumericSelector, NumericComparisonOp } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Numeric comparison operators, ordered longest-first.
|
|
5
|
+
*/
|
|
6
|
+
const NUMERIC_COMPARISON_OPS: NumericComparisonOp[] = ["<=", ">=", "<", ">", "="];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Parse numeric selector string into structured format.
|
|
10
|
+
*/
|
|
11
|
+
export function parseNumericSelector(value: string): NormalizedNumericSelector | undefined {
|
|
12
|
+
const trimmed = value.trim();
|
|
13
|
+
if (!trimmed) return undefined;
|
|
14
|
+
|
|
15
|
+
for (const op of NUMERIC_COMPARISON_OPS) {
|
|
16
|
+
if (trimmed.startsWith(op)) {
|
|
17
|
+
const numStr = trimmed.slice(op.length).trim();
|
|
18
|
+
const num = parseFloat(numStr);
|
|
19
|
+
if (Number.isFinite(num) && /^-?\d+(\.\d+)?$/.test(numStr)) {
|
|
20
|
+
return { op, value: num };
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const num = parseFloat(trimmed);
|
|
27
|
+
if (Number.isFinite(num) && /^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
28
|
+
return { op: "=", value: num };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { NormalizedOrder, NormalizedParent, OrderDirection, OrderField } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mapping from Wikidot's order field names to normalized OrderField values.
|
|
5
|
+
*/
|
|
6
|
+
const ORDER_FIELD_MAP: Record<string, OrderField> = {
|
|
7
|
+
datecreated: "created_at",
|
|
8
|
+
dateedited: "updated_at",
|
|
9
|
+
title: "title",
|
|
10
|
+
fullname: "fullname",
|
|
11
|
+
rating: "rating",
|
|
12
|
+
votes: "votes",
|
|
13
|
+
revisions: "revisions",
|
|
14
|
+
comments: "comments",
|
|
15
|
+
pagelength: "size",
|
|
16
|
+
size: "size",
|
|
17
|
+
random: "random",
|
|
18
|
+
created_at: "created_at",
|
|
19
|
+
updated_at: "updated_at",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Parse order string into structured format.
|
|
24
|
+
*/
|
|
25
|
+
export function parseOrder(value: string): NormalizedOrder {
|
|
26
|
+
const defaultOrder: NormalizedOrder = { field: "created_at", direction: "desc" };
|
|
27
|
+
const trimmed = value.trim().toLowerCase();
|
|
28
|
+
if (!trimmed) return defaultOrder;
|
|
29
|
+
|
|
30
|
+
const spaceParts = trimmed.split(/\s+/);
|
|
31
|
+
if (spaceParts.length >= 2 && spaceParts[0] && spaceParts[1]) {
|
|
32
|
+
const field = ORDER_FIELD_MAP[spaceParts[0]];
|
|
33
|
+
const direction = spaceParts[1] === "asc" ? "asc" : "desc";
|
|
34
|
+
if (field) {
|
|
35
|
+
return { field, direction };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let direction: OrderDirection = "desc";
|
|
40
|
+
let fieldPart = trimmed;
|
|
41
|
+
|
|
42
|
+
if (trimmed.endsWith("desc")) {
|
|
43
|
+
direction = "desc";
|
|
44
|
+
fieldPart = trimmed.slice(0, -4);
|
|
45
|
+
} else if (trimmed.endsWith("asc")) {
|
|
46
|
+
direction = "asc";
|
|
47
|
+
fieldPart = trimmed.slice(0, -3);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const field = ORDER_FIELD_MAP[fieldPart];
|
|
51
|
+
if (field) {
|
|
52
|
+
return { field, direction };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const singleField = ORDER_FIELD_MAP[trimmed];
|
|
56
|
+
if (singleField) {
|
|
57
|
+
return { field: singleField, direction: "desc" };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return defaultOrder;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Parse parent string into structured format.
|
|
65
|
+
*/
|
|
66
|
+
export function parseParent(value: string): NormalizedParent | undefined {
|
|
67
|
+
const trimmed = value.trim();
|
|
68
|
+
if (!trimmed) return undefined;
|
|
69
|
+
|
|
70
|
+
switch (trimmed) {
|
|
71
|
+
case "-":
|
|
72
|
+
return { type: "none" };
|
|
73
|
+
case "=":
|
|
74
|
+
return { type: "same" };
|
|
75
|
+
case "-=":
|
|
76
|
+
return { type: "different" };
|
|
77
|
+
case ".":
|
|
78
|
+
return { type: "children" };
|
|
79
|
+
default:
|
|
80
|
+
return { type: "page", name: trimmed };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { NormalizedCategory, NormalizedTags } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pattern for splitting multi-value attribute strings.
|
|
5
|
+
* Wikidot allows commas, semicolons, and whitespace as separators between values.
|
|
6
|
+
*/
|
|
7
|
+
const TOKEN_SEPARATOR = /[,;\s]+/;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parse tags string into structured format.
|
|
11
|
+
*/
|
|
12
|
+
export function parseTags(value: string): NormalizedTags {
|
|
13
|
+
const result: NormalizedTags = {
|
|
14
|
+
all: [],
|
|
15
|
+
any: [],
|
|
16
|
+
none: [],
|
|
17
|
+
special: null,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const trimmed = value.trim();
|
|
21
|
+
if (!trimmed) return result;
|
|
22
|
+
|
|
23
|
+
if (trimmed === "-") {
|
|
24
|
+
result.special = "none";
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
if (trimmed === "==") {
|
|
28
|
+
result.special = "same-all";
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const tokens = trimmed.split(TOKEN_SEPARATOR).filter(Boolean);
|
|
33
|
+
|
|
34
|
+
for (const token of tokens) {
|
|
35
|
+
if (token === "=") {
|
|
36
|
+
result.special = "same-visible";
|
|
37
|
+
} else if (token.startsWith("+")) {
|
|
38
|
+
const tag = token.slice(1);
|
|
39
|
+
if (tag) result.all.push(tag);
|
|
40
|
+
} else if (token.startsWith("-")) {
|
|
41
|
+
const tag = token.slice(1);
|
|
42
|
+
if (tag) result.none.push(tag);
|
|
43
|
+
} else {
|
|
44
|
+
result.any.push(token);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Parse category string into structured format.
|
|
53
|
+
*/
|
|
54
|
+
export function parseCategory(value: string): NormalizedCategory {
|
|
55
|
+
const result: NormalizedCategory = {
|
|
56
|
+
include: [],
|
|
57
|
+
exclude: [],
|
|
58
|
+
all: false,
|
|
59
|
+
current: false,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const trimmed = value.trim().toLowerCase();
|
|
63
|
+
if (!trimmed) return result;
|
|
64
|
+
|
|
65
|
+
if (trimmed === "*") {
|
|
66
|
+
result.all = true;
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const tokens = trimmed.split(TOKEN_SEPARATOR).filter(Boolean);
|
|
71
|
+
|
|
72
|
+
for (const token of tokens) {
|
|
73
|
+
if (token === "*") {
|
|
74
|
+
result.all = true;
|
|
75
|
+
} else if (token === ".") {
|
|
76
|
+
result.current = true;
|
|
77
|
+
} else if (token.startsWith("-")) {
|
|
78
|
+
const cat = token.slice(1);
|
|
79
|
+
if (cat) result.exclude.push(cat);
|
|
80
|
+
} else {
|
|
81
|
+
result.include.push(token);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Query normalization for the ListPages module.
|
|
4
|
+
*
|
|
5
|
+
* Converts the raw string-based `ListPagesQuery` (where fields like `tags`,
|
|
6
|
+
* `category`, and `order` are plain strings) into a `NormalizedListPagesQuery`
|
|
7
|
+
* with type-safe structured objects. This makes it straightforward for external
|
|
8
|
+
* applications to build database queries from the normalized representation
|
|
9
|
+
* without having to re-parse Wikidot's query syntax.
|
|
10
|
+
*
|
|
11
|
+
* Based on Wikidot official documentation:
|
|
12
|
+
* https://www.wikidot.com/doc-modules:listpages-module
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { ListPagesQuery, NormalizedListPagesQuery } from "./types";
|
|
18
|
+
import { parseCategory, parseTags } from "./normalization/tags-category";
|
|
19
|
+
import { parseOrder, parseParent } from "./normalization/order-parent";
|
|
20
|
+
import { parseDateSelector, parseNumericSelector } from "./normalization/selectors";
|
|
21
|
+
|
|
22
|
+
export { parseCategory, parseTags } from "./normalization/tags-category";
|
|
23
|
+
export { parseOrder, parseParent } from "./normalization/order-parent";
|
|
24
|
+
export { parseDateSelector, parseNumericSelector } from "./normalization/selectors";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Normalize a ListPagesQuery into structured types
|
|
28
|
+
*
|
|
29
|
+
* @param query - Raw query with string fields
|
|
30
|
+
* @returns Normalized query with structured types
|
|
31
|
+
*/
|
|
32
|
+
export function normalizeQuery(query: ListPagesQuery): NormalizedListPagesQuery {
|
|
33
|
+
const result: NormalizedListPagesQuery = {};
|
|
34
|
+
|
|
35
|
+
// Pass through simple fields
|
|
36
|
+
if (query.pagetype) result.pagetype = query.pagetype;
|
|
37
|
+
if (query.linkTo) result.linkTo = query.linkTo;
|
|
38
|
+
if (query.createdBy) result.createdBy = query.createdBy;
|
|
39
|
+
if (query.name) result.name = query.name;
|
|
40
|
+
if (query.fullname) result.fullname = query.fullname;
|
|
41
|
+
if (query.range) result.range = query.range;
|
|
42
|
+
if (query.dataFormFields) result.dataFormFields = query.dataFormFields;
|
|
43
|
+
if (query.offset !== undefined) result.offset = query.offset;
|
|
44
|
+
if (query.limit !== undefined) result.limit = query.limit;
|
|
45
|
+
if (query.perPage !== undefined) result.perPage = query.perPage;
|
|
46
|
+
if (query.reverse !== undefined) result.reverse = query.reverse;
|
|
47
|
+
|
|
48
|
+
// Parse complex fields
|
|
49
|
+
if (query.tags) result.tags = parseTags(query.tags);
|
|
50
|
+
if (query.category) result.category = parseCategory(query.category);
|
|
51
|
+
if (query.order) result.order = parseOrder(query.order);
|
|
52
|
+
if (query.parent) {
|
|
53
|
+
const parent = parseParent(query.parent);
|
|
54
|
+
if (parent) result.parent = parent;
|
|
55
|
+
}
|
|
56
|
+
if (query.createdAt) {
|
|
57
|
+
const createdAt = parseDateSelector(query.createdAt);
|
|
58
|
+
if (createdAt) result.createdAt = createdAt;
|
|
59
|
+
}
|
|
60
|
+
if (query.updatedAt) {
|
|
61
|
+
const updatedAt = parseDateSelector(query.updatedAt);
|
|
62
|
+
if (updatedAt) result.updatedAt = updatedAt;
|
|
63
|
+
}
|
|
64
|
+
if (query.rating) {
|
|
65
|
+
const rating = parseNumericSelector(query.rating);
|
|
66
|
+
if (rating) result.rating = rating;
|
|
67
|
+
}
|
|
68
|
+
if (query.votes) {
|
|
69
|
+
const votes = parseNumericSelector(query.votes);
|
|
70
|
+
if (votes) result.votes = votes;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Parser rule for the Wikidot `[[module ListPages ...]]` block.
|
|
4
|
+
*
|
|
5
|
+
* Parses the module's attributes into a structured `list-pages` Module AST node.
|
|
6
|
+
* Handles both hyphenated (`link-to`) and concatenated (`linkto`) attribute name
|
|
7
|
+
* formats, as Wikidot normalizes both to lowercase. The raw attribute values are
|
|
8
|
+
* preserved in the `attributes` field for `@URL` resolution by external applications.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { Module } from "@wdprlib/ast";
|
|
14
|
+
import type { ModuleRule } from "../types";
|
|
15
|
+
import { parseBool, parseInt32 } from "../utils";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Module rule for `[[module ListPages ...]]`.
|
|
19
|
+
*
|
|
20
|
+
* ListPages is the most complex Wikidot module. It queries pages by various
|
|
21
|
+
* criteria (tags, category, parent, date, rating, etc.) and renders each matching
|
|
22
|
+
* page using a template specified in the module body. The template uses
|
|
23
|
+
* `%%variable%%` syntax to reference page data.
|
|
24
|
+
*
|
|
25
|
+
* This rule only handles parsing; data fetching and template rendering are handled
|
|
26
|
+
* by the extract/resolve pipeline.
|
|
27
|
+
*/
|
|
28
|
+
export const listPagesModuleRule: ModuleRule = {
|
|
29
|
+
name: "module-listpages",
|
|
30
|
+
acceptsNames: ["listpages"],
|
|
31
|
+
hasBody: true,
|
|
32
|
+
|
|
33
|
+
parse(_ctx, _pos, args, body): Module {
|
|
34
|
+
// Extract known attributes, pass rest as additional attributes
|
|
35
|
+
// Note: attribute names are normalized to lowercase by parseAttributesRaw
|
|
36
|
+
const {
|
|
37
|
+
category,
|
|
38
|
+
tags,
|
|
39
|
+
parent,
|
|
40
|
+
rating,
|
|
41
|
+
votes,
|
|
42
|
+
name,
|
|
43
|
+
fullname,
|
|
44
|
+
range,
|
|
45
|
+
pagetype,
|
|
46
|
+
offset,
|
|
47
|
+
limit,
|
|
48
|
+
order,
|
|
49
|
+
reverse,
|
|
50
|
+
separate,
|
|
51
|
+
wrapper,
|
|
52
|
+
rss,
|
|
53
|
+
} = args;
|
|
54
|
+
// Hyphenated attributes (stored with hyphens in lowercase)
|
|
55
|
+
const linkTo = args["link-to"] ?? args.linkto;
|
|
56
|
+
const createdBy = args["created-by"] ?? args.createdby;
|
|
57
|
+
const createdAt = args["created-at"] ?? args.createdat;
|
|
58
|
+
const updatedAt = args["updated-at"] ?? args.updatedat;
|
|
59
|
+
const perPage = args["per-page"] ?? args.perpage;
|
|
60
|
+
const prependLine = args["prepend-line"] ?? args.prependline;
|
|
61
|
+
const appendLine = args["append-line"] ?? args.appendline;
|
|
62
|
+
const rssDescription = args["rss-description"] ?? args.rssdescription;
|
|
63
|
+
const rssHome = args["rss-home"] ?? args.rsshome;
|
|
64
|
+
const rssLimit = args["rss-limit"] ?? args.rsslimit;
|
|
65
|
+
const rssOnly = args["rss-only"] ?? args.rssonly;
|
|
66
|
+
const urlAttrPrefix = args["url-attr-prefix"] ?? args.urlattrprefix;
|
|
67
|
+
|
|
68
|
+
// Store all raw arguments for @URL resolution by external apps
|
|
69
|
+
const rawArgs: Record<string, string> = { ...args };
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
module: "list-pages",
|
|
73
|
+
category,
|
|
74
|
+
tags,
|
|
75
|
+
parent,
|
|
76
|
+
"link-to": linkTo,
|
|
77
|
+
"created-by": createdBy,
|
|
78
|
+
"created-at": createdAt,
|
|
79
|
+
"updated-at": updatedAt,
|
|
80
|
+
rating,
|
|
81
|
+
votes,
|
|
82
|
+
name,
|
|
83
|
+
fullname,
|
|
84
|
+
range,
|
|
85
|
+
pagetype,
|
|
86
|
+
offset: parseInt32(offset),
|
|
87
|
+
limit: parseInt32(limit),
|
|
88
|
+
"per-page": parseInt32(perPage),
|
|
89
|
+
order,
|
|
90
|
+
reverse: parseBool(reverse, false),
|
|
91
|
+
separate: parseBool(separate, true),
|
|
92
|
+
wrapper: parseBool(wrapper, true),
|
|
93
|
+
"prepend-line": prependLine,
|
|
94
|
+
"append-line": appendLine,
|
|
95
|
+
rss,
|
|
96
|
+
"rss-description": rssDescription,
|
|
97
|
+
"rss-home": rssHome,
|
|
98
|
+
"rss-limit": parseInt32(rssLimit),
|
|
99
|
+
"rss-only": parseBool(rssOnly, false),
|
|
100
|
+
"url-attr-prefix": urlAttrPrefix,
|
|
101
|
+
body,
|
|
102
|
+
// All raw arguments for @URL resolution
|
|
103
|
+
attributes: rawArgs,
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
};
|