chaffjs 0.17.0 → 0.18.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/announced-count.d.ts +26 -0
- package/dist/announced-count.d.ts.map +1 -0
- package/dist/announced-count.js +104 -0
- package/dist/announced-count.js.map +1 -0
- package/dist/bare-url.d.ts +14 -0
- package/dist/bare-url.d.ts.map +1 -0
- package/dist/bare-url.js +28 -0
- package/dist/bare-url.js.map +1 -0
- package/dist/baseline.d.ts +5 -0
- package/dist/baseline.d.ts.map +1 -1
- package/dist/baseline.js +16 -1
- package/dist/baseline.js.map +1 -1
- package/dist/body-section.d.ts +7 -0
- package/dist/body-section.d.ts.map +1 -0
- package/dist/body-section.js +6 -0
- package/dist/body-section.js.map +1 -0
- package/dist/calendar-number.d.ts +2 -0
- package/dist/calendar-number.d.ts.map +1 -1
- package/dist/calendar-number.js +9 -2
- package/dist/calendar-number.js.map +1 -1
- package/dist/cli-args.d.ts +4 -0
- package/dist/cli-args.d.ts.map +1 -1
- package/dist/cli-args.js +5 -0
- package/dist/cli-args.js.map +1 -1
- package/dist/cli-text.d.ts.map +1 -1
- package/dist/cli-text.js +8 -4
- package/dist/cli-text.js.map +1 -1
- package/dist/cli.js +33 -30
- package/dist/cli.js.map +1 -1
- package/dist/commands/compare.d.ts +8 -0
- package/dist/commands/compare.d.ts.map +1 -0
- package/dist/commands/compare.js +72 -0
- package/dist/commands/compare.js.map +1 -0
- package/dist/commands/eval.d.ts.map +1 -1
- package/dist/commands/eval.js +17 -9
- package/dist/commands/eval.js.map +1 -1
- package/dist/commands/feedback.d.ts +5 -2
- package/dist/commands/feedback.d.ts.map +1 -1
- package/dist/commands/feedback.js +11 -5
- package/dist/commands/feedback.js.map +1 -1
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +2 -4
- package/dist/commands/test.js.map +1 -1
- package/dist/commands/tree.d.ts +13 -0
- package/dist/commands/tree.d.ts.map +1 -1
- package/dist/commands/tree.js +35 -5
- package/dist/commands/tree.js.map +1 -1
- package/dist/compare/atom.d.ts +31 -0
- package/dist/compare/atom.d.ts.map +1 -0
- package/dist/compare/atom.js +4 -0
- package/dist/compare/atom.js.map +1 -0
- package/dist/compare/clock-time.d.ts +8 -0
- package/dist/compare/clock-time.d.ts.map +1 -0
- package/dist/compare/clock-time.js +65 -0
- package/dist/compare/clock-time.js.map +1 -0
- package/dist/compare/extract.d.ts +15 -0
- package/dist/compare/extract.d.ts.map +1 -0
- package/dist/compare/extract.js +58 -0
- package/dist/compare/extract.js.map +1 -0
- package/dist/compare/fact-text.d.ts +23 -0
- package/dist/compare/fact-text.d.ts.map +1 -0
- package/dist/compare/fact-text.js +47 -0
- package/dist/compare/fact-text.js.map +1 -0
- package/dist/compare/markup-atoms.d.ts +11 -0
- package/dist/compare/markup-atoms.d.ts.map +1 -0
- package/dist/compare/markup-atoms.js +23 -0
- package/dist/compare/markup-atoms.js.map +1 -0
- package/dist/compare/match.d.ts +19 -0
- package/dist/compare/match.d.ts.map +1 -0
- package/dist/compare/match.js +84 -0
- package/dist/compare/match.js.map +1 -0
- package/dist/compare/outcome.d.ts +33 -0
- package/dist/compare/outcome.d.ts.map +1 -0
- package/dist/compare/outcome.js +40 -0
- package/dist/compare/outcome.js.map +1 -0
- package/dist/compare/proper-nouns.d.ts +19 -0
- package/dist/compare/proper-nouns.d.ts.map +1 -0
- package/dist/compare/proper-nouns.js +44 -0
- package/dist/compare/proper-nouns.js.map +1 -0
- package/dist/compare/render.d.ts +9 -0
- package/dist/compare/render.d.ts.map +1 -0
- package/dist/compare/render.js +64 -0
- package/dist/compare/render.js.map +1 -0
- package/dist/compare/spans.d.ts +9 -0
- package/dist/compare/spans.d.ts.map +1 -0
- package/dist/compare/spans.js +11 -0
- package/dist/compare/spans.js.map +1 -0
- package/dist/compare/text-atoms.d.ts +24 -0
- package/dist/compare/text-atoms.d.ts.map +1 -0
- package/dist/compare/text-atoms.js +67 -0
- package/dist/compare/text-atoms.js.map +1 -0
- package/dist/compare/text.d.ts +24 -0
- package/dist/compare/text.d.ts.map +1 -0
- package/dist/compare/text.js +90 -0
- package/dist/compare/text.js.map +1 -0
- package/dist/compare/tree-atoms.d.ts +20 -0
- package/dist/compare/tree-atoms.d.ts.map +1 -0
- package/dist/compare/tree-atoms.js +58 -0
- package/dist/compare/tree-atoms.js.map +1 -0
- package/dist/compare/written-names.d.ts +8 -0
- package/dist/compare/written-names.d.ts.map +1 -0
- package/dist/compare/written-names.js +24 -0
- package/dist/compare/written-names.js.map +1 -0
- package/dist/config/load.d.ts +15 -0
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +5 -0
- package/dist/config/load.js.map +1 -1
- package/dist/config/option-problems.d.ts +16 -0
- package/dist/config/option-problems.d.ts.map +1 -0
- package/dist/config/option-problems.js +58 -0
- package/dist/config/option-problems.js.map +1 -0
- package/dist/config/read.d.ts +4 -0
- package/dist/config/read.d.ts.map +1 -0
- package/dist/config/read.js +8 -0
- package/dist/config/read.js.map +1 -0
- package/dist/config/rule-problems.d.ts +2 -4
- package/dist/config/rule-problems.d.ts.map +1 -1
- package/dist/config/rule-problems.js +7 -1
- package/dist/config/rule-problems.js.map +1 -1
- package/dist/config/style.d.ts +16 -0
- package/dist/config/style.d.ts.map +1 -0
- package/dist/config/style.js +36 -0
- package/dist/config/style.js.map +1 -0
- package/dist/config/warnings.d.ts +6 -0
- package/dist/config/warnings.d.ts.map +1 -0
- package/dist/config/warnings.js +10 -0
- package/dist/config/warnings.js.map +1 -0
- package/dist/config/write.d.ts.map +1 -1
- package/dist/config/write.js +17 -4
- package/dist/config/write.js.map +1 -1
- package/dist/custom/bounded-match.d.ts +15 -0
- package/dist/custom/bounded-match.d.ts.map +1 -0
- package/dist/custom/bounded-match.js +43 -0
- package/dist/custom/bounded-match.js.map +1 -0
- package/dist/custom/load.d.ts +8 -0
- package/dist/custom/load.d.ts.map +1 -0
- package/dist/custom/load.js +11 -0
- package/dist/custom/load.js.map +1 -0
- package/dist/custom/parse.d.ts +70 -0
- package/dist/custom/parse.d.ts.map +1 -0
- package/dist/custom/parse.js +215 -0
- package/dist/custom/parse.js.map +1 -0
- package/dist/custom/problems.d.ts +5 -0
- package/dist/custom/problems.d.ts.map +1 -0
- package/dist/custom/problems.js +78 -0
- package/dist/custom/problems.js.map +1 -0
- package/dist/custom/regex-safety.d.ts +11 -0
- package/dist/custom/regex-safety.d.ts.map +1 -0
- package/dist/custom/regex-safety.js +110 -0
- package/dist/custom/regex-safety.js.map +1 -0
- package/dist/custom/token-pattern.d.ts +8 -0
- package/dist/custom/token-pattern.d.ts.map +1 -0
- package/dist/custom/token-pattern.js +75 -0
- package/dist/custom/token-pattern.js.map +1 -0
- package/dist/detect.d.ts.map +1 -1
- package/dist/detect.js +24 -2
- package/dist/detect.js.map +1 -1
- package/dist/detectors/acronym-context.d.ts +2 -0
- package/dist/detectors/acronym-context.d.ts.map +1 -1
- package/dist/detectors/acronym-context.js +12 -4
- package/dist/detectors/acronym-context.js.map +1 -1
- package/dist/detectors/ai-phrasing.d.ts +20 -0
- package/dist/detectors/ai-phrasing.d.ts.map +1 -0
- package/dist/detectors/ai-phrasing.js +112 -0
- package/dist/detectors/ai-phrasing.js.map +1 -0
- package/dist/detectors/announced-count.d.ts +4 -0
- package/dist/detectors/announced-count.d.ts.map +1 -0
- package/dist/detectors/announced-count.js +20 -0
- package/dist/detectors/announced-count.js.map +1 -0
- package/dist/detectors/broken-link.d.ts +17 -0
- package/dist/detectors/broken-link.d.ts.map +1 -0
- package/dist/detectors/broken-link.js +66 -0
- package/dist/detectors/broken-link.js.map +1 -0
- package/dist/detectors/cited-name.d.ts.map +1 -1
- package/dist/detectors/cited-name.js +4 -4
- package/dist/detectors/cited-name.js.map +1 -1
- package/dist/detectors/cited-title.d.ts +11 -0
- package/dist/detectors/cited-title.d.ts.map +1 -0
- package/dist/detectors/cited-title.js +75 -0
- package/dist/detectors/cited-title.js.map +1 -0
- package/dist/detectors/concrete-evidence.d.ts +1 -1
- package/dist/detectors/concrete-evidence.d.ts.map +1 -1
- package/dist/detectors/concrete-evidence.js +2 -1
- package/dist/detectors/concrete-evidence.js.map +1 -1
- package/dist/detectors/contrast-frame.d.ts +17 -0
- package/dist/detectors/contrast-frame.d.ts.map +1 -0
- package/dist/detectors/contrast-frame.js +32 -0
- package/dist/detectors/contrast-frame.js.map +1 -0
- package/dist/detectors/custom.d.ts +8 -0
- package/dist/detectors/custom.d.ts.map +1 -0
- package/dist/detectors/custom.js +71 -0
- package/dist/detectors/custom.js.map +1 -0
- package/dist/detectors/dangling-figure.d.ts +4 -0
- package/dist/detectors/dangling-figure.d.ts.map +1 -0
- package/dist/detectors/dangling-figure.js +18 -0
- package/dist/detectors/dangling-figure.js.map +1 -0
- package/dist/detectors/doubled-punctuation.d.ts +9 -0
- package/dist/detectors/doubled-punctuation.d.ts.map +1 -0
- package/dist/detectors/doubled-punctuation.js +33 -0
- package/dist/detectors/doubled-punctuation.js.map +1 -0
- package/dist/detectors/doubled-word.d.ts +5 -0
- package/dist/detectors/doubled-word.d.ts.map +1 -1
- package/dist/detectors/doubled-word.js +24 -11
- package/dist/detectors/doubled-word.js.map +1 -1
- package/dist/detectors/enumerated-runs.d.ts +1 -1
- package/dist/detectors/enumerated-runs.d.ts.map +1 -1
- package/dist/detectors/enumerated-runs.js +15 -4
- package/dist/detectors/enumerated-runs.js.map +1 -1
- package/dist/detectors/gram-furniture.d.ts +6 -0
- package/dist/detectors/gram-furniture.d.ts.map +1 -0
- package/dist/detectors/gram-furniture.js +21 -0
- package/dist/detectors/gram-furniture.js.map +1 -0
- package/dist/detectors/gram-place.d.ts +2 -0
- package/dist/detectors/gram-place.d.ts.map +1 -1
- package/dist/detectors/gram-place.js +9 -7
- package/dist/detectors/gram-place.js.map +1 -1
- package/dist/detectors/gram-windows.d.ts +9 -0
- package/dist/detectors/gram-windows.d.ts.map +1 -0
- package/dist/detectors/gram-windows.js +27 -0
- package/dist/detectors/gram-windows.js.map +1 -0
- package/dist/detectors/heading-case.d.ts +2 -0
- package/dist/detectors/heading-case.d.ts.map +1 -1
- package/dist/detectors/heading-case.js +29 -2
- package/dist/detectors/heading-case.js.map +1 -1
- package/dist/detectors/heading-code-words.d.ts +6 -0
- package/dist/detectors/heading-code-words.d.ts.map +1 -0
- package/dist/detectors/heading-code-words.js +29 -0
- package/dist/detectors/heading-code-words.js.map +1 -0
- package/dist/detectors/heading-echo.d.ts.map +1 -1
- package/dist/detectors/heading-echo.js +7 -4
- package/dist/detectors/heading-echo.js.map +1 -1
- package/dist/detectors/heading-level-skip.d.ts +12 -0
- package/dist/detectors/heading-level-skip.d.ts.map +1 -0
- package/dist/detectors/heading-level-skip.js +11 -0
- package/dist/detectors/heading-level-skip.js.map +1 -0
- package/dist/detectors/image-alt-text.d.ts +3 -0
- package/dist/detectors/image-alt-text.d.ts.map +1 -0
- package/dist/detectors/image-alt-text.js +9 -0
- package/dist/detectors/image-alt-text.js.map +1 -0
- package/dist/detectors/index.d.ts.map +1 -1
- package/dist/detectors/index.js +34 -1
- package/dist/detectors/index.js.map +1 -1
- package/dist/detectors/kutoten-consistency.d.ts +24 -0
- package/dist/detectors/kutoten-consistency.d.ts.map +1 -0
- package/dist/detectors/kutoten-consistency.js +77 -0
- package/dist/detectors/kutoten-consistency.js.map +1 -0
- package/dist/detectors/lead-in.d.ts +1 -0
- package/dist/detectors/lead-in.d.ts.map +1 -1
- package/dist/detectors/lead-in.js +2 -1
- package/dist/detectors/lead-in.js.map +1 -1
- package/dist/detectors/lexicon-match.d.ts +4 -0
- package/dist/detectors/lexicon-match.d.ts.map +1 -1
- package/dist/detectors/lexicon-match.js +7 -2
- package/dist/detectors/lexicon-match.js.map +1 -1
- package/dist/detectors/list-item.d.ts +45 -0
- package/dist/detectors/list-item.d.ts.map +1 -0
- package/dist/detectors/list-item.js +88 -0
- package/dist/detectors/list-item.js.map +1 -0
- package/dist/detectors/list-items.d.ts +31 -0
- package/dist/detectors/list-items.d.ts.map +1 -0
- package/dist/detectors/list-items.js +113 -0
- package/dist/detectors/list-items.js.map +1 -0
- package/dist/detectors/list-lead-in.d.ts +7 -0
- package/dist/detectors/list-lead-in.d.ts.map +1 -0
- package/dist/detectors/list-lead-in.js +28 -0
- package/dist/detectors/list-lead-in.js.map +1 -0
- package/dist/detectors/list-sentence.d.ts +65 -0
- package/dist/detectors/list-sentence.d.ts.map +1 -0
- package/dist/detectors/list-sentence.js +105 -0
- package/dist/detectors/list-sentence.js.map +1 -0
- package/dist/detectors/list-view.d.ts +34 -0
- package/dist/detectors/list-view.d.ts.map +1 -0
- package/dist/detectors/list-view.js +137 -0
- package/dist/detectors/list-view.js.map +1 -0
- package/dist/detectors/long-vowel.d.ts +7 -0
- package/dist/detectors/long-vowel.d.ts.map +1 -0
- package/dist/detectors/long-vowel.js +57 -0
- package/dist/detectors/long-vowel.js.map +1 -0
- package/dist/detectors/markup-finding.d.ts +6 -0
- package/dist/detectors/markup-finding.d.ts.map +1 -0
- package/dist/detectors/markup-finding.js +19 -0
- package/dist/detectors/markup-finding.js.map +1 -0
- package/dist/detectors/name-numeral.d.ts +1 -1
- package/dist/detectors/name-numeral.d.ts.map +1 -1
- package/dist/detectors/name-numeral.js +2 -7
- package/dist/detectors/name-numeral.js.map +1 -1
- package/dist/detectors/orthography.d.ts.map +1 -1
- package/dist/detectors/orthography.js +14 -10
- package/dist/detectors/orthography.js.map +1 -1
- package/dist/detectors/oxford-comma.d.ts +7 -1
- package/dist/detectors/oxford-comma.d.ts.map +1 -1
- package/dist/detectors/oxford-comma.js +135 -229
- package/dist/detectors/oxford-comma.js.map +1 -1
- package/dist/detectors/place-run.d.ts.map +1 -1
- package/dist/detectors/place-run.js +10 -6
- package/dist/detectors/place-run.js.map +1 -1
- package/dist/detectors/placeholder-text.d.ts +9 -0
- package/dist/detectors/placeholder-text.d.ts.map +1 -0
- package/dist/detectors/placeholder-text.js +18 -0
- package/dist/detectors/placeholder-text.js.map +1 -0
- package/dist/detectors/quote-around.d.ts +3 -0
- package/dist/detectors/quote-around.d.ts.map +1 -0
- package/dist/detectors/quote-around.js +8 -0
- package/dist/detectors/quote-around.js.map +1 -0
- package/dist/detectors/register.d.ts +11 -3
- package/dist/detectors/register.d.ts.map +1 -1
- package/dist/detectors/register.js +28 -9
- package/dist/detectors/register.js.map +1 -1
- package/dist/detectors/roman-numeral.d.ts +2 -0
- package/dist/detectors/roman-numeral.d.ts.map +1 -1
- package/dist/detectors/roman-numeral.js +2 -0
- package/dist/detectors/roman-numeral.js.map +1 -1
- package/dist/detectors/sentence-ending.d.ts +17 -1
- package/dist/detectors/sentence-ending.d.ts.map +1 -1
- package/dist/detectors/sentence-ending.js +13 -7
- package/dist/detectors/sentence-ending.js.map +1 -1
- package/dist/detectors/sentence-length.d.ts.map +1 -1
- package/dist/detectors/sentence-length.js +13 -4
- package/dist/detectors/sentence-length.js.map +1 -1
- package/dist/detectors/signals.d.ts +8 -0
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +67 -46
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/structure-tree.d.ts +6 -0
- package/dist/detectors/structure-tree.d.ts.map +1 -1
- package/dist/detectors/structure-tree.js +37 -1
- package/dist/detectors/structure-tree.js.map +1 -1
- package/dist/detectors/structure.d.ts +1 -3
- package/dist/detectors/structure.d.ts.map +1 -1
- package/dist/detectors/structure.js +3 -4
- package/dist/detectors/structure.js.map +1 -1
- package/dist/detectors/superlative-name.d.ts.map +1 -1
- package/dist/detectors/superlative-name.js +8 -5
- package/dist/detectors/superlative-name.js.map +1 -1
- package/dist/detectors/superlative-scope.d.ts.map +1 -1
- package/dist/detectors/superlative-scope.js +9 -4
- package/dist/detectors/superlative-scope.js.map +1 -1
- package/dist/detectors/token-column.d.ts +46 -0
- package/dist/detectors/token-column.d.ts.map +1 -0
- package/dist/detectors/token-column.js +95 -0
- package/dist/detectors/token-column.js.map +1 -0
- package/dist/detectors/unbalanced-bracket.d.ts +22 -0
- package/dist/detectors/unbalanced-bracket.d.ts.map +1 -0
- package/dist/detectors/unbalanced-bracket.js +119 -0
- package/dist/detectors/unbalanced-bracket.js.map +1 -0
- package/dist/detectors/url-run-on.d.ts +9 -0
- package/dist/detectors/url-run-on.d.ts.map +1 -0
- package/dist/detectors/url-run-on.js +19 -0
- package/dist/detectors/url-run-on.js.map +1 -0
- package/dist/document-sections.d.ts +13 -0
- package/dist/document-sections.d.ts.map +1 -0
- package/dist/document-sections.js +32 -0
- package/dist/document-sections.js.map +1 -0
- package/dist/document.d.ts +11 -4
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +90 -98
- package/dist/document.js.map +1 -1
- package/dist/email-parts.d.ts +28 -0
- package/dist/email-parts.d.ts.map +1 -0
- package/dist/email-parts.js +230 -0
- package/dist/email-parts.js.map +1 -0
- package/dist/eval.d.ts +2 -1
- package/dist/eval.d.ts.map +1 -1
- package/dist/eval.js +16 -4
- package/dist/eval.js.map +1 -1
- package/dist/figure-references.d.ts +30 -0
- package/dist/figure-references.d.ts.map +1 -0
- package/dist/figure-references.js +76 -0
- package/dist/figure-references.js.map +1 -0
- package/dist/files.d.ts +2 -0
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +4 -0
- package/dist/files.js.map +1 -1
- package/dist/heading-label.d.ts +22 -0
- package/dist/heading-label.d.ts.map +1 -0
- package/dist/heading-label.js +50 -0
- package/dist/heading-label.js.map +1 -0
- package/dist/in-page-nav.d.ts +4 -1
- package/dist/in-page-nav.d.ts.map +1 -1
- package/dist/in-page-nav.js +53 -18
- package/dist/in-page-nav.js.map +1 -1
- package/dist/joined-view.d.ts.map +1 -1
- package/dist/joined-view.js +1 -0
- package/dist/joined-view.js.map +1 -1
- package/dist/levels.d.ts +5 -1
- package/dist/levels.d.ts.map +1 -1
- package/dist/levels.js +9 -0
- package/dist/levels.js.map +1 -1
- package/dist/line-paragraphs.d.ts +8 -0
- package/dist/line-paragraphs.d.ts.map +1 -1
- package/dist/line-paragraphs.js +33 -10
- package/dist/line-paragraphs.js.map +1 -1
- package/dist/long-vowel.d.ts +35 -0
- package/dist/long-vowel.d.ts.map +1 -0
- package/dist/long-vowel.js +71 -0
- package/dist/long-vowel.js.map +1 -0
- package/dist/markdown-node.d.ts +19 -0
- package/dist/markdown-node.d.ts.map +1 -0
- package/dist/markdown-node.js +6 -0
- package/dist/markdown-node.js.map +1 -0
- package/dist/markdown-read.d.ts +17 -0
- package/dist/markdown-read.d.ts.map +1 -0
- package/dist/markdown-read.js +37 -0
- package/dist/markdown-read.js.map +1 -0
- package/dist/markup.d.ts +22 -0
- package/dist/markup.d.ts.map +1 -0
- package/dist/markup.js +180 -0
- package/dist/markup.js.map +1 -0
- package/dist/mask.js +8 -5
- package/dist/mask.js.map +1 -1
- package/dist/number-name.d.ts +21 -5
- package/dist/number-name.d.ts.map +1 -1
- package/dist/number-name.js +119 -17
- package/dist/number-name.js.map +1 -1
- package/dist/orthography.d.ts +2 -0
- package/dist/orthography.d.ts.map +1 -1
- package/dist/orthography.js +9 -4
- package/dist/orthography.js.map +1 -1
- package/dist/page-furniture.d.ts +5 -2
- package/dist/page-furniture.d.ts.map +1 -1
- package/dist/page-furniture.js +8 -2
- package/dist/page-furniture.js.map +1 -1
- package/dist/plain-source.d.ts +1 -0
- package/dist/plain-source.d.ts.map +1 -1
- package/dist/plain-source.js +2 -1
- package/dist/plain-source.js.map +1 -1
- package/dist/plugin.d.ts +115 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/profile/for-file.d.ts.map +1 -1
- package/dist/profile/for-file.js +3 -1
- package/dist/profile/for-file.js.map +1 -1
- package/dist/quoted-span.d.ts.map +1 -1
- package/dist/quoted-span.js +8 -3
- package/dist/quoted-span.js.map +1 -1
- package/dist/reasons.d.ts +3 -0
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +6 -0
- package/dist/reasons.js.map +1 -1
- package/dist/reference-lists.d.ts +3 -0
- package/dist/reference-lists.d.ts.map +1 -0
- package/dist/reference-lists.js +75 -0
- package/dist/reference-lists.js.map +1 -0
- package/dist/render/explain.d.ts +7 -1
- package/dist/render/explain.d.ts.map +1 -1
- package/dist/render/explain.js +36 -12
- package/dist/render/explain.js.map +1 -1
- package/dist/render/friendly.d.ts.map +1 -1
- package/dist/render/friendly.js +19 -9
- package/dist/render/friendly.js.map +1 -1
- package/dist/render/options.d.ts +7 -0
- package/dist/render/options.d.ts.map +1 -0
- package/dist/render/options.js +50 -0
- package/dist/render/options.js.map +1 -0
- package/dist/render/rules-json.d.ts +4 -1
- package/dist/render/rules-json.d.ts.map +1 -1
- package/dist/render/rules-json.js +102 -12
- package/dist/render/rules-json.js.map +1 -1
- package/dist/render/rules-table.d.ts +4 -0
- package/dist/render/rules-table.d.ts.map +1 -0
- package/dist/render/rules-table.js +70 -0
- package/dist/render/rules-table.js.map +1 -0
- package/dist/render/sarif.js +4 -4
- package/dist/render/sarif.js.map +1 -1
- package/dist/render/semantic.js +3 -3
- package/dist/render/semantic.js.map +1 -1
- package/dist/render/severity-name.d.ts +6 -0
- package/dist/render/severity-name.d.ts.map +1 -0
- package/dist/render/severity-name.js +7 -0
- package/dist/render/severity-name.js.map +1 -0
- package/dist/render/text.d.ts +7 -2
- package/dist/render/text.d.ts.map +1 -1
- package/dist/render/text.js +15 -4
- package/dist/render/text.js.map +1 -1
- package/dist/resolve-genre.d.ts +1 -1
- package/dist/resolve-genre.d.ts.map +1 -1
- package/dist/resolve-genre.js +4 -1
- package/dist/resolve-genre.js.map +1 -1
- package/dist/rule-genres.d.ts +24 -0
- package/dist/rule-genres.d.ts.map +1 -0
- package/dist/rule-genres.js +11 -0
- package/dist/rule-genres.js.map +1 -0
- package/dist/rule-guide.d.ts +54 -0
- package/dist/rule-guide.d.ts.map +1 -0
- package/dist/rule-guide.js +81 -0
- package/dist/rule-guide.js.map +1 -0
- package/dist/rule-load.d.ts.map +1 -1
- package/dist/rule-load.js +87 -33
- package/dist/rule-load.js.map +1 -1
- package/dist/rule-options.d.ts +50 -0
- package/dist/rule-options.d.ts.map +1 -0
- package/dist/rule-options.js +106 -0
- package/dist/rule-options.js.map +1 -0
- package/dist/run.d.ts +13 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +54 -10
- package/dist/run.js.map +1 -1
- package/dist/sentence-shape.d.ts.map +1 -1
- package/dist/sentence-shape.js +4 -4
- package/dist/sentence-shape.js.map +1 -1
- package/dist/setting-problems.d.ts +2 -1
- package/dist/setting-problems.d.ts.map +1 -1
- package/dist/setting-problems.js +6 -1
- package/dist/setting-problems.js.map +1 -1
- package/dist/span-cut.d.ts +6 -0
- package/dist/span-cut.d.ts.map +1 -0
- package/dist/span-cut.js +22 -0
- package/dist/span-cut.js.map +1 -0
- package/dist/structure/aside-depth.d.ts +21 -0
- package/dist/structure/aside-depth.d.ts.map +1 -0
- package/dist/structure/aside-depth.js +65 -0
- package/dist/structure/aside-depth.js.map +1 -0
- package/dist/structure/build.d.ts +5 -1
- package/dist/structure/build.d.ts.map +1 -1
- package/dist/structure/build.js +29 -17
- package/dist/structure/build.js.map +1 -1
- package/dist/structure/closed-pairs.d.ts +8 -0
- package/dist/structure/closed-pairs.d.ts.map +1 -0
- package/dist/structure/closed-pairs.js +22 -0
- package/dist/structure/closed-pairs.js.map +1 -0
- package/dist/structure/date-range.d.ts +21 -0
- package/dist/structure/date-range.d.ts.map +1 -0
- package/dist/structure/date-range.js +45 -0
- package/dist/structure/date-range.js.map +1 -0
- package/dist/structure/known-mentions.d.ts +18 -0
- package/dist/structure/known-mentions.d.ts.map +1 -0
- package/dist/structure/known-mentions.js +78 -0
- package/dist/structure/known-mentions.js.map +1 -0
- package/dist/structure/numbering.d.ts +1 -0
- package/dist/structure/numbering.d.ts.map +1 -1
- package/dist/structure/numbering.js +11 -6
- package/dist/structure/numbering.js.map +1 -1
- package/dist/structure/of.d.ts +3 -1
- package/dist/structure/of.d.ts.map +1 -1
- package/dist/structure/of.js +5 -1
- package/dist/structure/of.js.map +1 -1
- package/dist/structure/percent-sum.d.ts +16 -0
- package/dist/structure/percent-sum.d.ts.map +1 -0
- package/dist/structure/percent-sum.js +104 -0
- package/dist/structure/percent-sum.js.map +1 -0
- package/dist/structure/quoted-number.d.ts +8 -0
- package/dist/structure/quoted-number.d.ts.map +1 -0
- package/dist/structure/quoted-number.js +34 -0
- package/dist/structure/quoted-number.js.map +1 -0
- package/dist/structure/relative-find.d.ts.map +1 -1
- package/dist/structure/relative-find.js +34 -46
- package/dist/structure/relative-find.js.map +1 -1
- package/dist/structure/relative-resolve.d.ts.map +1 -1
- package/dist/structure/relative-resolve.js +76 -30
- package/dist/structure/relative-resolve.js.map +1 -1
- package/dist/structure/runs.d.ts +2 -0
- package/dist/structure/runs.d.ts.map +1 -1
- package/dist/structure/runs.js +2 -2
- package/dist/structure/runs.js.map +1 -1
- package/dist/structure/sexp.d.ts +1 -1
- package/dist/structure/sexp.d.ts.map +1 -1
- package/dist/structure/sexp.js +18 -6
- package/dist/structure/sexp.js.map +1 -1
- package/dist/structure/total.d.ts +3 -0
- package/dist/structure/total.d.ts.map +1 -1
- package/dist/structure/total.js +2 -2
- package/dist/structure/total.js.map +1 -1
- package/dist/structure/universal.d.ts +14 -2
- package/dist/structure/universal.d.ts.map +1 -1
- package/dist/structure/universal.js +17 -2
- package/dist/structure/universal.js.map +1 -1
- package/dist/structure/wrapped-tail.d.ts +14 -7
- package/dist/structure/wrapped-tail.d.ts.map +1 -1
- package/dist/structure/wrapped-tail.js +33 -8
- package/dist/structure/wrapped-tail.js.map +1 -1
- package/dist/style-load.d.ts +4 -0
- package/dist/style-load.d.ts.map +1 -0
- package/dist/style-load.js +28 -0
- package/dist/style-load.js.map +1 -0
- package/dist/style-parse.d.ts +19 -0
- package/dist/style-parse.d.ts.map +1 -0
- package/dist/style-parse.js +60 -0
- package/dist/style-parse.js.map +1 -0
- package/dist/subheading-line.d.ts +6 -0
- package/dist/subheading-line.d.ts.map +1 -0
- package/dist/subheading-line.js +57 -0
- package/dist/subheading-line.js.map +1 -0
- package/dist/template-syntax.d.ts +17 -0
- package/dist/template-syntax.d.ts.map +1 -0
- package/dist/template-syntax.js +140 -0
- package/dist/template-syntax.js.map +1 -0
- package/dist/text-above.d.ts +19 -0
- package/dist/text-above.d.ts.map +1 -0
- package/dist/text-above.js +43 -0
- package/dist/text-above.js.map +1 -0
- package/dist/text-figures.d.ts +10 -0
- package/dist/text-figures.d.ts.map +1 -0
- package/dist/text-figures.js +131 -0
- package/dist/text-figures.js.map +1 -0
- package/dist/trailing-aside.d.ts +2 -0
- package/dist/trailing-aside.d.ts.map +1 -0
- package/dist/trailing-aside.js +53 -0
- package/dist/trailing-aside.js.map +1 -0
- package/dist/tree-walk.d.ts +18 -0
- package/dist/tree-walk.d.ts.map +1 -0
- package/dist/tree-walk.js +45 -0
- package/dist/tree-walk.js.map +1 -0
- package/genres.yaml +26 -0
- package/package.json +5 -3
- package/reference-headings.yaml +17 -0
- package/rules/adverb-overuse.yaml +19 -0
- package/rules/agentless-passive.yaml +19 -0
- package/rules/agreement-slip.yaml +14 -1
- package/rules/ai-generated-composite.yaml +102 -0
- package/rules/ai-tell.yaml +23 -0
- package/rules/announced-count-mismatch.yaml +57 -0
- package/rules/announcing-opener.yaml +51 -0
- package/rules/assistant-residue.yaml +52 -0
- package/rules/bold-density.yaml +31 -0
- package/rules/broken-link.yaml +65 -0
- package/rules/closing-cliche.yaml +33 -0
- package/rules/colon-lead-in.yaml +59 -0
- package/rules/concrete-evidence-density.yaml +41 -0
- package/rules/contraction-consistency.yaml +18 -0
- package/rules/contrast-framing.yaml +57 -0
- package/rules/cushion-phrase-density.yaml +25 -0
- package/rules/dangling-figure-reference.yaml +61 -0
- package/rules/dangling-reference.yaml +53 -1
- package/rules/date-order.yaml +33 -1
- package/rules/date-range-reversed.yaml +46 -0
- package/rules/date-weekday-mismatch.yaml +17 -1
- package/rules/double-keigo.yaml +16 -0
- package/rules/doubled-punctuation.yaml +45 -0
- package/rules/doubled-word.yaml +17 -1
- package/rules/duplicate-definition.yaml +59 -1
- package/rules/emoji-density.yaml +25 -0
- package/rules/empty-conclusion.yaml +28 -0
- package/rules/empty-intensifier.yaml +19 -0
- package/rules/excessive-hedging.yaml +19 -0
- package/rules/expletive-construction.yaml +19 -0
- package/rules/heading-echo.yaml +31 -0
- package/rules/heading-level-skip.yaml +78 -0
- package/rules/hiragana-fukushi.yaml +16 -0
- package/rules/image-alt-text.yaml +54 -0
- package/rules/internal-jargon.yaml +21 -0
- package/rules/katakana-long-vowel.yaml +98 -0
- package/rules/kutoten-consistency.yaml +53 -0
- package/rules/latin-spacing.yaml +23 -4
- package/rules/max-kanji-continuous.yaml +16 -0
- package/rules/max-paragraph-length.yaml +33 -0
- package/rules/max-sentence-length.yaml +32 -0
- package/rules/ngram-repetition.yaml +29 -2
- package/rules/no-doubled-joshi.yaml +16 -0
- package/rules/no-em-dash.yaml +25 -0
- package/rules/no-mixed-desumasu.yaml +27 -2
- package/rules/no-nakaguro-parallel.yaml +20 -0
- package/rules/numbering-gap.yaml +53 -1
- package/rules/oxford-comma-consistency.yaml +18 -0
- package/rules/padded-intro.yaml +19 -0
- package/rules/paragraph-length-variance.yaml +49 -0
- package/rules/percent-sum-mismatch.yaml +58 -0
- package/rules/preamble-length.yaml +56 -0
- package/rules/preferred-term.yaml +27 -0
- package/rules/proper-noun-density.yaml +26 -0
- package/rules/repeated-conjunction.yaml +47 -0
- package/rules/repeated-sentence-head.yaml +23 -0
- package/rules/required-sections.yaml +49 -0
- package/rules/risk-disclosure.yaml +22 -0
- package/rules/rule-of-three.yaml +97 -0
- package/rules/sasete-itadaku.yaml +18 -0
- package/rules/section-length-uniformity.yaml +89 -0
- package/rules/sentence-initial-conjunction-run.yaml +18 -0
- package/rules/sentence-rhythm.yaml +25 -0
- package/rules/stock-transition.yaml +55 -0
- package/rules/stray-space.yaml +18 -0
- package/rules/taigen-dome-in-prose.yaml +19 -0
- package/rules/title-case-consistency.yaml +42 -0
- package/rules/total-mismatch.yaml +37 -1
- package/rules/unbalanced-bracket.yaml +56 -0
- package/rules/undefined-acronym.yaml +22 -0
- package/rules/unfilled-placeholder.yaml +50 -0
- package/rules/unqualified-superlative.yaml +19 -0
- package/rules/unsourced-number.yaml +16 -0
- package/rules/url-run-on.yaml +45 -0
- package/skills/chaff/SKILL.md +70 -0
- package/src/announced-count.ts +148 -0
- package/src/bare-url.ts +35 -0
- package/src/baseline.ts +17 -1
- package/src/body-section.ts +7 -0
- package/src/calendar-number.ts +18 -4
- package/src/cli-args.ts +6 -0
- package/src/cli-text.ts +8 -4
- package/src/cli.ts +37 -37
- package/src/commands/compare.ts +80 -0
- package/src/commands/eval.ts +19 -8
- package/src/commands/feedback.ts +12 -6
- package/src/commands/test.ts +2 -4
- package/src/commands/tree.ts +41 -5
- package/src/compare/atom.ts +33 -0
- package/src/compare/clock-time.ts +86 -0
- package/src/compare/extract.ts +78 -0
- package/src/compare/fact-text.ts +68 -0
- package/src/compare/markup-atoms.ts +29 -0
- package/src/compare/match.ts +105 -0
- package/src/compare/outcome.ts +70 -0
- package/src/compare/proper-nouns.ts +65 -0
- package/src/compare/render.ts +102 -0
- package/src/compare/spans.ts +17 -0
- package/src/compare/text-atoms.ts +95 -0
- package/src/compare/text.ts +120 -0
- package/src/compare/tree-atoms.ts +80 -0
- package/src/compare/written-names.ts +26 -0
- package/src/config/load.ts +21 -0
- package/src/config/option-problems.ts +70 -0
- package/src/config/read.ts +8 -0
- package/src/config/rule-problems.ts +12 -2
- package/src/config/style.ts +42 -0
- package/src/config/warnings.ts +13 -0
- package/src/config/write.ts +18 -4
- package/src/custom/bounded-match.ts +58 -0
- package/src/custom/load.ts +15 -0
- package/src/custom/parse.ts +274 -0
- package/src/custom/problems.ts +89 -0
- package/src/custom/regex-safety.ts +118 -0
- package/src/custom/token-pattern.ts +84 -0
- package/src/detect.ts +28 -2
- package/src/detectors/acronym-context.ts +16 -4
- package/src/detectors/ai-phrasing.ts +137 -0
- package/src/detectors/announced-count.ts +25 -0
- package/src/detectors/broken-link.ts +90 -0
- package/src/detectors/cited-name.ts +6 -5
- package/src/detectors/cited-title.ts +96 -0
- package/src/detectors/concrete-evidence.ts +3 -2
- package/src/detectors/contrast-frame.ts +54 -0
- package/src/detectors/custom.ts +89 -0
- package/src/detectors/dangling-figure.ts +22 -0
- package/src/detectors/doubled-punctuation.ts +49 -0
- package/src/detectors/doubled-word.ts +19 -4
- package/src/detectors/enumerated-runs.ts +13 -4
- package/src/detectors/gram-furniture.ts +30 -0
- package/src/detectors/gram-place.ts +9 -5
- package/src/detectors/gram-windows.ts +31 -0
- package/src/detectors/heading-case.ts +30 -2
- package/src/detectors/heading-code-words.ts +35 -0
- package/src/detectors/heading-echo.ts +8 -4
- package/src/detectors/heading-level-skip.ts +19 -0
- package/src/detectors/image-alt-text.ts +11 -0
- package/src/detectors/index.ts +43 -1
- package/src/detectors/kutoten-consistency.ts +96 -0
- package/src/detectors/lead-in.ts +3 -1
- package/src/detectors/lexicon-match.ts +9 -2
- package/src/detectors/list-item.ts +122 -0
- package/src/detectors/list-items.ts +163 -0
- package/src/detectors/list-lead-in.ts +33 -0
- package/src/detectors/list-sentence.ts +157 -0
- package/src/detectors/list-view.ts +157 -0
- package/src/detectors/long-vowel.ts +66 -0
- package/src/detectors/markup-finding.ts +24 -0
- package/src/detectors/name-numeral.ts +4 -2
- package/src/detectors/orthography.ts +23 -17
- package/src/detectors/oxford-comma.ts +178 -283
- package/src/detectors/place-run.ts +7 -4
- package/src/detectors/placeholder-text.ts +27 -0
- package/src/detectors/quote-around.ts +9 -0
- package/src/detectors/register.ts +37 -10
- package/src/detectors/roman-numeral.ts +3 -0
- package/src/detectors/sentence-ending.ts +14 -7
- package/src/detectors/sentence-length.ts +16 -5
- package/src/detectors/signals.ts +80 -46
- package/src/detectors/structure-tree.ts +45 -1
- package/src/detectors/structure.ts +3 -4
- package/src/detectors/superlative-name.ts +7 -4
- package/src/detectors/superlative-scope.ts +8 -3
- package/src/detectors/token-column.ts +149 -0
- package/src/detectors/unbalanced-bracket.ts +153 -0
- package/src/detectors/url-run-on.ts +27 -0
- package/src/document-sections.ts +46 -0
- package/src/document.ts +106 -138
- package/src/email-parts.ts +269 -0
- package/src/eval.ts +14 -4
- package/src/figure-references.ts +112 -0
- package/src/files.ts +5 -0
- package/src/heading-label.ts +55 -0
- package/src/in-page-nav.ts +48 -19
- package/src/joined-view.ts +1 -0
- package/src/levels.ts +14 -1
- package/src/line-paragraphs.ts +52 -9
- package/src/long-vowel.ts +99 -0
- package/src/markdown-node.ts +19 -0
- package/src/markdown-read.ts +44 -0
- package/src/markup.ts +210 -0
- package/src/mask.ts +8 -8
- package/src/number-name.ts +151 -24
- package/src/orthography.ts +10 -3
- package/src/page-furniture.ts +11 -2
- package/src/plain-source.ts +2 -1
- package/src/plugin.ts +101 -1
- package/src/profile/for-file.ts +3 -1
- package/src/quoted-span.ts +9 -3
- package/src/reasons.ts +9 -0
- package/src/reference-lists.ts +91 -0
- package/src/render/explain.ts +47 -13
- package/src/render/friendly.ts +20 -9
- package/src/render/options.ts +58 -0
- package/src/render/rules-json.ts +130 -14
- package/src/render/rules-table.ts +91 -0
- package/src/render/sarif.ts +4 -4
- package/src/render/semantic.ts +3 -3
- package/src/render/severity-name.ts +10 -0
- package/src/render/text.ts +21 -7
- package/src/resolve-genre.ts +4 -1
- package/src/rule-genres.ts +25 -0
- package/src/rule-guide.ts +135 -0
- package/src/rule-load.ts +91 -34
- package/src/rule-options.ts +131 -0
- package/src/run.ts +74 -11
- package/src/sentence-shape.ts +4 -5
- package/src/setting-problems.ts +7 -1
- package/src/span-cut.ts +28 -0
- package/src/structure/aside-depth.ts +67 -0
- package/src/structure/build.ts +38 -19
- package/src/structure/closed-pairs.ts +20 -0
- package/src/structure/date-range.ts +69 -0
- package/src/structure/known-mentions.ts +96 -0
- package/src/structure/numbering.ts +9 -5
- package/src/structure/of.ts +11 -3
- package/src/structure/percent-sum.ts +135 -0
- package/src/structure/quoted-number.ts +36 -0
- package/src/structure/relative-find.ts +34 -47
- package/src/structure/relative-resolve.ts +77 -30
- package/src/structure/runs.ts +2 -2
- package/src/structure/sexp.ts +17 -5
- package/src/structure/total.ts +2 -2
- package/src/structure/universal.ts +24 -4
- package/src/structure/wrapped-tail.ts +38 -13
- package/src/style-load.ts +28 -0
- package/src/style-parse.ts +77 -0
- package/src/subheading-line.ts +68 -0
- package/src/template-syntax.ts +164 -0
- package/src/text-above.ts +49 -0
- package/src/text-figures.ts +147 -0
- package/src/trailing-aside.ts +50 -0
- package/src/tree-walk.ts +48 -0
- package/styles/bunkacho.yaml +25 -0
- package/styles/ieice.yaml +29 -0
- package/styles/jis-z8301-2011.yaml +25 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { spanOf, type MarkdownNode } from "./markdown-node.ts";
|
|
2
|
+
import type { Span } from "./plugin.ts";
|
|
3
|
+
|
|
4
|
+
/** `closer` finds where each `close` starts. */
|
|
5
|
+
type Delimiters = { readonly open: string; readonly close: string; readonly closer: RegExp };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Template and MDX syntax written into the text: Liquid and Jinja tags (`{% ifversion %}`,
|
|
9
|
+
* `{% data variables.product.github %}`), outputs (`{{ page.title }}`, which also covers Hugo's shortcodes
|
|
10
|
+
* `{{< note >}}` and `{{% alert %}}`) and comments (`{# … #}`), and MDX comments (a block comment in braces).
|
|
11
|
+
*/
|
|
12
|
+
const DELIMITERS: readonly Delimiters[] = [
|
|
13
|
+
{ open: "{%", close: "%}", closer: /%\}/gu },
|
|
14
|
+
{ open: "{{", close: "}}", closer: /\}\}/gu },
|
|
15
|
+
{ open: "{#", close: "#}", closer: /#\}/gu },
|
|
16
|
+
{ open: "{/*", close: "*/}", closer: /\*\/\}/gu },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const OPENER = /\{(?=[{%#]|\/\*)/gu;
|
|
20
|
+
|
|
21
|
+
// A tag never runs past a blank line: an unclosed `{{` is a character in the text, not a tag that swallows the page.
|
|
22
|
+
const BLANK_LINE = /\n[ \t]*\n/gu;
|
|
23
|
+
|
|
24
|
+
const stretchesOf = (text: string): Span[] => {
|
|
25
|
+
const breaks = [...text.matchAll(BLANK_LINE)];
|
|
26
|
+
const starts = [0, ...breaks.map((blank) => blank.index + blank[0].length)];
|
|
27
|
+
return starts.map((start, index) => ({ start, end: breaks[index]?.index ?? text.length }));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** The first of the sorted `positions` at or after `from`. */
|
|
31
|
+
const firstAtOrAfter = (positions: readonly number[], from: number, low = 0, high = positions.length): number | undefined => {
|
|
32
|
+
if (low >= high) return positions[low];
|
|
33
|
+
const middle = (low + high) >> 1;
|
|
34
|
+
return (positions[middle] ?? from) >= from ? firstAtOrAfter(positions, from, low, middle) : firstAtOrAfter(positions, from, middle + 1, high);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The tags in one stretch, left to right: each opener closes at the first closer after it, and an opener inside a tag
|
|
39
|
+
* opens nothing. Each opener looks its closer up instead of scanning for it, so a line of unclosed openers is linear.
|
|
40
|
+
*/
|
|
41
|
+
const tagsIn = (stretch: string): Span[] => {
|
|
42
|
+
const closers = DELIMITERS.map(({ closer }) => [...stretch.matchAll(closer)].map((match) => match.index));
|
|
43
|
+
return [...stretch.matchAll(OPENER)].reduce<Span[]>((tags, { index }) => {
|
|
44
|
+
if (index < (tags.at(-1)?.end ?? 0)) return tags;
|
|
45
|
+
const kind = DELIMITERS.findIndex(({ open }) => stretch.startsWith(open, index));
|
|
46
|
+
const delimiters = DELIMITERS[kind];
|
|
47
|
+
const close = delimiters === undefined ? undefined : firstAtOrAfter(closers[kind] ?? [], index + delimiters.open.length);
|
|
48
|
+
if (delimiters !== undefined && close !== undefined) tags.push({ start: index, end: close + delimiters.close.length });
|
|
49
|
+
return tags;
|
|
50
|
+
}, []);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Where the template syntax stands. Read `code` with code already blanked, so a `{{` inside backticks opens nothing. */
|
|
54
|
+
export const templateSpans = (code: string): Span[] =>
|
|
55
|
+
stretchesOf(code).flatMap((stretch) =>
|
|
56
|
+
tagsIn(code.slice(stretch.start, stretch.end)).map((tag) => ({ start: stretch.start + tag.start, end: stretch.start + tag.end })),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
/** A line that starts with a JSX element's tag (`<Tabs>`, `</Tabs>`). HTML's tags are lower case and stay HTML. */
|
|
60
|
+
const COMPONENT_START = /^[ \t]*<\/?[A-Z][^\n]*$/gmu;
|
|
61
|
+
|
|
62
|
+
const QUOTED = /"[^"\n]*"|'[^'\n]*'/gu;
|
|
63
|
+
|
|
64
|
+
/** Tags and nothing else, once quoted values are emptied and expressions taken out: `<TabItem value= label=>`. */
|
|
65
|
+
const TAGS_ONLY = /^[ \t]*(?:<\/?[A-Za-z][\w.:-]*(?:[ \t][^<>{}]*)?>[ \t]*)+$/u;
|
|
66
|
+
|
|
67
|
+
/** The line without its brace expressions, however deeply they nest; undefined when its braces do not balance. */
|
|
68
|
+
const withoutExpressions = (line: string): string | undefined => {
|
|
69
|
+
const kept: string[] = [];
|
|
70
|
+
const depth = [...line.replace(QUOTED, '""')].reduce((level, char) => {
|
|
71
|
+
if (level < 0) return level;
|
|
72
|
+
if (char === "{") return level + 1;
|
|
73
|
+
if (char === "}") return level - 1;
|
|
74
|
+
if (level === 0) kept.push(char);
|
|
75
|
+
return level;
|
|
76
|
+
}, 0);
|
|
77
|
+
return depth === 0 ? kept.join("") : undefined;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const isComponentLine = (line: string): boolean => {
|
|
81
|
+
const bare = withoutExpressions(line);
|
|
82
|
+
return bare !== undefined && TAGS_ONLY.test(bare);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Lines of nothing but JSX tags. MDX reads such a line as a block of its own, so the text on the next line is a
|
|
87
|
+
* paragraph; CommonMark reads it as the start of an HTML block that runs to the next blank line and hides that text.
|
|
88
|
+
*/
|
|
89
|
+
export const componentLines = (source: string): Span[] =>
|
|
90
|
+
[...source.matchAll(COMPONENT_START)]
|
|
91
|
+
.filter((match) => isComponentLine(match[0]))
|
|
92
|
+
.map((match) => ({ start: match.index, end: match.index + match[0].length }));
|
|
93
|
+
|
|
94
|
+
const IMPORT_START = /^import(?:\s|\{)/u;
|
|
95
|
+
// The module's name in quotes ends the statement: "import data from 'CSV' before review." goes on, so it is prose.
|
|
96
|
+
const IMPORT_FROM = /(?:[\s}*]from\s*|^import\s*)["'][^"'\n]*["'];?[ \t]*(?:\n|$)/u;
|
|
97
|
+
|
|
98
|
+
/** JavaScript's shapes of `export`, read on the first line, so that "export default reports from…" stays a sentence. */
|
|
99
|
+
const EXPORT_SHAPES: readonly RegExp[] = [
|
|
100
|
+
/^export\s+(?:async\s+)?function\b/u,
|
|
101
|
+
/^export\s+class\s+[\w$]/u,
|
|
102
|
+
/^export\s+(?:const|let|var)\s+[\w${[][^=]*=/u,
|
|
103
|
+
/^export\s+default\s+(?:async\s+)?(?:function|class)\b/u,
|
|
104
|
+
/^export\s+default\s*[{(["'`<]/u,
|
|
105
|
+
/^export\s+default\s+[\w$.]+\s*\(/u,
|
|
106
|
+
/^export\s+default\s+[\w$]+(?:\.[\w$]+)*;?\s*$/u,
|
|
107
|
+
/^export\s*[{*]/u,
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
const isExport = (paragraph: string): boolean => {
|
|
111
|
+
const firstLine = paragraph.split("\n", 1)[0] ?? "";
|
|
112
|
+
return EXPORT_SHAPES.some((shape) => shape.test(firstLine));
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** A paragraph that is MDX's `import`/`export` block: JavaScript, which MDX runs to the next blank line. */
|
|
116
|
+
const isModuleBlock = (paragraph: string): boolean => (IMPORT_START.test(paragraph) && IMPORT_FROM.test(paragraph)) || isExport(paragraph);
|
|
117
|
+
|
|
118
|
+
/** MDX's `import`/`export` lines: JavaScript, and only at the top level of the page. */
|
|
119
|
+
export const moduleBlocks = (root: MarkdownNode, source: string): Span[] =>
|
|
120
|
+
(root.children ?? []).flatMap((node) => {
|
|
121
|
+
const span = node.type === "paragraph" ? spanOf(node) : undefined;
|
|
122
|
+
return span !== undefined && isModuleBlock(source.slice(span.start, span.end)) ? [span] : [];
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
/** `[!NOTE]` and the like opening a quote: a GitHub alert (Obsidian's callouts write the same). */
|
|
126
|
+
const alertMarkerAt = (source: string, start: number): Span | undefined => {
|
|
127
|
+
const marker = /\[![A-Za-z]+\][^\n]*/uy;
|
|
128
|
+
marker.lastIndex = start;
|
|
129
|
+
return marker.test(source) ? { start, end: marker.lastIndex } : undefined;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const QUOTE_MARK = /^[ \t]*>[ \t]?/gmu;
|
|
133
|
+
|
|
134
|
+
/** The `>` that opens each line of a quote spanning `quote`: the quote's own mark, not its text. */
|
|
135
|
+
const quoteMarks = (source: string, quote: Span): Span[] =>
|
|
136
|
+
[...source.slice(quote.start, quote.end).matchAll(QUOTE_MARK)].map((match) => ({
|
|
137
|
+
start: quote.start + match.index,
|
|
138
|
+
end: quote.start + match.index + match[0].length,
|
|
139
|
+
}));
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A GitHub alert (`> [!NOTE]`) is the writer's own text set in a box, not a quote: only its marker line and the `>` of
|
|
143
|
+
* each line are not prose. Undefined when the quote is not an alert.
|
|
144
|
+
*/
|
|
145
|
+
const alertMarks = (quote: MarkdownNode, whole: Span, source: string): Span[] | undefined => {
|
|
146
|
+
const first = quote.children?.[0];
|
|
147
|
+
const start = first?.type === "paragraph" ? spanOf(first)?.start : undefined;
|
|
148
|
+
const marker = start === undefined ? undefined : alertMarkerAt(source, start);
|
|
149
|
+
return marker === undefined ? undefined : [marker, ...quoteMarks(source, whole)];
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Reads the alerts of one walk over the tree in pre-order: the marks of each alert, undefined for any other node. A
|
|
154
|
+
* quote inside a quote is quoted, even one that opens like an alert; pre-order meets the outer quote first.
|
|
155
|
+
*/
|
|
156
|
+
export const alertReader = (source: string): ((node: MarkdownNode) => Span[] | undefined) => {
|
|
157
|
+
const outer = { end: -1 };
|
|
158
|
+
return (node) => {
|
|
159
|
+
const quote = node.type === "blockquote" ? spanOf(node) : undefined;
|
|
160
|
+
if (quote === undefined || quote.start < outer.end) return undefined;
|
|
161
|
+
outer.end = quote.end;
|
|
162
|
+
return alertMarks(node, quote, source);
|
|
163
|
+
};
|
|
164
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 箇条書きや表のすぐ上に書いた文の塊。予告の文(以下の3点)や、割合の表の説明(売上の構成比)を読む rule が使う。
|
|
3
|
+
* 文書の頭まで読み返さないので、箇条書きや表の多い長い文書でも行数に比例する。
|
|
4
|
+
*/
|
|
5
|
+
export type TextBlock = { readonly start: number; readonly text: string };
|
|
6
|
+
|
|
7
|
+
const BLANK = /^[ \t]*$/u;
|
|
8
|
+
const LIST_MARKER = /^[ \t]*(?:[-*+]|\d{1,3}[.)])[ \t]/u;
|
|
9
|
+
|
|
10
|
+
export const isBlank = (text: string): boolean => BLANK.test(text);
|
|
11
|
+
|
|
12
|
+
/** 位置 end の改行で終わる行。 */
|
|
13
|
+
const lineEndingAt = (source: string, end: number): TextBlock => {
|
|
14
|
+
const start = end === 0 ? 0 : source.lastIndexOf("\n", end - 1) + 1;
|
|
15
|
+
return { start, text: source.slice(start, end) };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** start の行の一つ上の行。文書の最初の行なら undefined。 */
|
|
19
|
+
export const lineAbove = (source: string, start: number): TextBlock | undefined => {
|
|
20
|
+
if (start === 0) return undefined;
|
|
21
|
+
const end = source.lastIndexOf("\n", start - 1);
|
|
22
|
+
return end < 0 ? undefined : lineEndingAt(source, end);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* start の行より上の塊を、下の行から上へ。passed に当たる行(表の見出しの行など)と空行は、塊に着くまで飛ばす。
|
|
27
|
+
* 塊は次の空行まで。箇条書きの印で始まる行(親の項目)はそこで止める。下の行から順に返す。
|
|
28
|
+
*/
|
|
29
|
+
export const linesAbove = (source: string, start: number, passed: (text: string) => boolean = () => false): TextBlock[] => {
|
|
30
|
+
const block: TextBlock[] = [];
|
|
31
|
+
let line = lineAbove(source, start);
|
|
32
|
+
while (line !== undefined) {
|
|
33
|
+
if (isBlank(line.text) || (block.length === 0 && passed(line.text))) {
|
|
34
|
+
if (block.length > 0) break;
|
|
35
|
+
} else {
|
|
36
|
+
block.push(line);
|
|
37
|
+
if (LIST_MARKER.test(line.text)) break;
|
|
38
|
+
}
|
|
39
|
+
line = lineAbove(source, line.start);
|
|
40
|
+
}
|
|
41
|
+
return block;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** 下の行から並べた塊を、一続きの文字列にする。 */
|
|
45
|
+
export const joined = (source: string, lines: readonly TextBlock[]): TextBlock | undefined => {
|
|
46
|
+
const top = lines.at(-1);
|
|
47
|
+
const bottom = lines[0];
|
|
48
|
+
return top === undefined || bottom === undefined ? undefined : { start: top.start, text: source.slice(top.start, bottom.start + bottom.text.length) };
|
|
49
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { Span } from "./plugin.ts";
|
|
2
|
+
import { mergeSpans } from "./span-merge.ts";
|
|
3
|
+
import { spansOfType } from "./markdown-read.ts";
|
|
4
|
+
import type { MarkdownNode } from "./markdown-node.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 線と矢印で描いた図(RFC の状態遷移図、やり取りの図、枠の表)。文ではないので、コードブロックと同じく本文から外す。
|
|
8
|
+
*
|
|
9
|
+
* 見分けるのは形だけ。線の文字が多いか、語のあいだを 3 字以上空けて桁をそろえた行で、文の句読点が無いもの。
|
|
10
|
+
* そういう行が続く塊(行のあいだの空行は 1 行まで)のうち、2 行以上あり、線の行を 1 行でも含むものを図とする。
|
|
11
|
+
* 句読点の無い短い行(図の中の「(Close)」)は、図の行に挟まれていれば図に入る。塊の端にあれば入らない。
|
|
12
|
+
* 語の多い行は、句読点が無くても文の行(折り返した文の途中)として塊を切る。
|
|
13
|
+
* 桁をそろえただけの語の表は、線が無ければ本文のまま読む。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** 線を引く文字。ASCII の + - | / \ < > ^ = と、U+2500 台の罫線・U+25A0 台の図形(▶ ▼)。 */
|
|
17
|
+
const LINE_CHAR = /[+\-|/\\<>^=\u2500-\u25FF]/gu;
|
|
18
|
+
/** 下向きの矢印として一文字で立つ v。語の中の v は数えない。 */
|
|
19
|
+
const ARROW_V = /(?<=^|\s)[vV](?=\s|$)/gu;
|
|
20
|
+
/** 線の文字が 3 つ続けば線(-->、+---+、<==)。 */
|
|
21
|
+
const LINE_RUN = /[+\-|/\\<>^=\u2500-\u25FF]{3,}/gu;
|
|
22
|
+
/** ただし「---」ちょうどは、語のあいだのダッシュ(47.041 --- Engineering)。 */
|
|
23
|
+
const DASH = /^-{3}$/u;
|
|
24
|
+
/** 行の空白以外の文字のうち、この割合以上が線の文字なら線の行。「== Community ==」のような見出しの印は半分に届かない。 */
|
|
25
|
+
const LINE_SHARE = 0.5;
|
|
26
|
+
/** 割合で線の行と読むのに要る、線の文字の数。箇条書きの「- EU」は印が 1 つだけ。 */
|
|
27
|
+
const MIN_LINE_CHARS = 2;
|
|
28
|
+
/** 語のあいだの 3 字以上の空白は、桁をそろえた印。文の区切りの空白は 2 字まで(RFC は文のあいだを 2 字空ける)。 */
|
|
29
|
+
const COLUMN_GAP = /\S {3,}\S/u;
|
|
30
|
+
/** 文の印: 語の直後の句読点に、次の語が続く("reply. It"、"link, then")。日本語は句点か読点があれば文。 */
|
|
31
|
+
const SENTENCE = /\p{L}\p{L}[.,;:?!]["')\]]?\s+\p{L}|[。、]/u;
|
|
32
|
+
/**
|
|
33
|
+
* 行末で終わる文("alpha Sends requests."、"beta Uses TCP.")。見るのは最後の桁で、小文字の語があり . ? ! で終わるもの。
|
|
34
|
+
* 括弧で閉じた注記("(return to LISTEN!)")と省略の点("...")は図の中の書き方で、文の終わりではない。
|
|
35
|
+
*/
|
|
36
|
+
const SENTENCE_END = /[^.][.?!]["'”’]?$/u;
|
|
37
|
+
const LOWER_WORD = /\p{Ll}\p{Ll}/u;
|
|
38
|
+
const LAST_CELL = / {3,}/u;
|
|
39
|
+
|
|
40
|
+
const endsSentence = (text: string): boolean => {
|
|
41
|
+
const cell = text.trim().split(LAST_CELL).at(-1) ?? "";
|
|
42
|
+
return SENTENCE_END.test(cell) && LOWER_WORD.test(cell);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 同じ線の文字だけの行(-----、==== ====)。見出しの下線や段の区切りで、図の中にあってもよいが図の印にはならない。
|
|
46
|
+
* 印にすると、区切りの線 2 本に挟まれた題(===== / Title / =====)や、下線を引いた見出しの前の箇条書きまで図になる。
|
|
47
|
+
*/
|
|
48
|
+
const RULE_LINE = /^\s*([-=_~*])\1*(?:\s+\1+)*\s*$/u;
|
|
49
|
+
/** 行頭の箇条書きの印(-、*、+、1.、a))。印の後ろの空白は桁そろえではない。 */
|
|
50
|
+
const LIST_MARK = /^\s*(?:[-*+]|\p{N}{1,3}[.)]|\p{L}[.)])(?=\s)/u;
|
|
51
|
+
/** 語。句読点の無い行でも、語が多ければ文の一部(折り返した文の行)で、図の中の注記ではない。 */
|
|
52
|
+
const WORD = /\p{L}[\p{L}\p{N}'-]*/gu;
|
|
53
|
+
/** 図の中の注記(「(Close)」「(2 MSL)」「CLOSED」)の語の数の上限。 */
|
|
54
|
+
const MAX_PLAIN_WORDS = 4;
|
|
55
|
+
/** 図の中で、行と行のあいだに置ける空行の数。 */
|
|
56
|
+
const MAX_BLANK_RUN = 1;
|
|
57
|
+
/** 図と読むのに要る行の数。区切りの線 1 行は図ではない。 */
|
|
58
|
+
const MIN_FIGURE_LINES = 2;
|
|
59
|
+
|
|
60
|
+
/** line は線の行、column は桁そろえの行、plain は句読点の無い行と区切りの線(図の中にあってよい)、text は文の行。 */
|
|
61
|
+
type Kind = "line" | "column" | "plain" | "blank" | "text";
|
|
62
|
+
|
|
63
|
+
type Row = { readonly start: number; readonly end: number; readonly kind: Kind };
|
|
64
|
+
|
|
65
|
+
const matchesOf = (text: string, pattern: RegExp): string[] => [...text.matchAll(pattern)].map((match) => match[0]);
|
|
66
|
+
|
|
67
|
+
const count = (text: string, pattern: RegExp): number => matchesOf(text, pattern).length;
|
|
68
|
+
|
|
69
|
+
/** 箇条書きの印は線に数えない(「- /」はパンくずの区切り)。 */
|
|
70
|
+
const isLineArt = (text: string): boolean => {
|
|
71
|
+
const body = text.replace(LIST_MARK, "");
|
|
72
|
+
const visible = body.replace(/\s/gu, "").length;
|
|
73
|
+
const drawn = count(body, LINE_CHAR) + count(body, ARROW_V);
|
|
74
|
+
return matchesOf(body, LINE_RUN).some((run) => !DASH.test(run)) || (drawn >= MIN_LINE_CHARS && drawn >= visible * LINE_SHARE);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const kindOf = (text: string): Kind => {
|
|
78
|
+
if (text.trim() === "") return "blank";
|
|
79
|
+
if (SENTENCE.test(text) || endsSentence(text)) return "text";
|
|
80
|
+
if (RULE_LINE.test(text)) return "plain";
|
|
81
|
+
if (isLineArt(text)) return "line";
|
|
82
|
+
if (COLUMN_GAP.test(text.replace(LIST_MARK, "").trimStart())) return "column";
|
|
83
|
+
return count(text, WORD) > MAX_PLAIN_WORDS ? "text" : "plain";
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** skip の中で始まる行は、文の行と同じく塊を切る。行も範囲も先頭から順に進むので、行ごとに範囲を全部なめない。 */
|
|
87
|
+
const rowsOf = (source: string, skip: readonly Span[]): Row[] => {
|
|
88
|
+
const regions = mergeSpans(skip, false);
|
|
89
|
+
const scan = { start: 0, region: 0 };
|
|
90
|
+
return source.split("\n").map((text) => {
|
|
91
|
+
while ((regions[scan.region]?.end ?? Number.POSITIVE_INFINITY) <= scan.start) scan.region += 1;
|
|
92
|
+
const region = regions[scan.region];
|
|
93
|
+
const skipped = region !== undefined && region.start <= scan.start;
|
|
94
|
+
const row: Row = { start: scan.start, end: scan.start + text.length, kind: skipped ? "text" : kindOf(text) };
|
|
95
|
+
scan.start = row.end + 1;
|
|
96
|
+
return row;
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** 図の行の塊。空行が MAX_BLANK_RUN を超えて続くか、文の行が来たら切れる。塊の端の空行と句読点の無い行は入れない。 */
|
|
101
|
+
const runsOf = (rows: readonly Row[]): Row[][] => {
|
|
102
|
+
// 行ごとに配列を作り直すと、何万行の文書で行数の二乗になる。塊は押し足していく。
|
|
103
|
+
const runs: Row[][] = [[]];
|
|
104
|
+
const scan = { blanks: 0 };
|
|
105
|
+
const cut = (): void => {
|
|
106
|
+
if ((runs.at(-1) ?? []).length > 0) runs.push([]);
|
|
107
|
+
};
|
|
108
|
+
rows.forEach((row) => {
|
|
109
|
+
if (row.kind === "blank") {
|
|
110
|
+
scan.blanks += 1;
|
|
111
|
+
if (scan.blanks > MAX_BLANK_RUN) cut();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
scan.blanks = 0;
|
|
115
|
+
if (row.kind === "text") cut();
|
|
116
|
+
else runs.at(-1)?.push(row);
|
|
117
|
+
});
|
|
118
|
+
return runs.map(trimPlain).filter((run) => run.length > 0);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const isDrawn = (row: Row): boolean => row.kind === "line" || row.kind === "column";
|
|
122
|
+
|
|
123
|
+
const trimPlain = (run: readonly Row[]): Row[] => {
|
|
124
|
+
const first = run.findIndex(isDrawn);
|
|
125
|
+
return first === -1 ? [] : run.slice(first, run.findLastIndex(isDrawn) + 1);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const isFigure = (run: readonly Row[]): boolean => run.filter(isDrawn).length >= MIN_FIGURE_LINES && run.some((row) => row.kind === "line");
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* テキストの図の範囲。最初の行の頭から最後の行の終わりまで(あいだの空行も入る)。source は LF でそろえたもの。
|
|
132
|
+
* skip は図と別に読む範囲(Markdown のコード・表・HTML・見出し)。その中の行は図の行に数えない。
|
|
133
|
+
*/
|
|
134
|
+
export const textFigures = (source: string, skip: readonly Span[] = []): Span[] =>
|
|
135
|
+
runsOf(rowsOf(source, skip))
|
|
136
|
+
.filter(isFigure)
|
|
137
|
+
.map((run) => ({ start: run[0]?.start ?? 0, end: run.at(-1)?.end ?? 0 }));
|
|
138
|
+
|
|
139
|
+
/** Markdown が図と別に読む塊。この中の線は図として探さない(コードはもともと本文でなく、表の区切りの行は表、見出しは見出し)。 */
|
|
140
|
+
const NOT_FIGURE = ["code", "table", "html", "heading"];
|
|
141
|
+
|
|
142
|
+
/** Markdown の図。コード・表・HTML・見出しの外に描かれたものだけ。 */
|
|
143
|
+
export const markdownFigures = (root: MarkdownNode, source: string): Span[] =>
|
|
144
|
+
textFigures(
|
|
145
|
+
source,
|
|
146
|
+
NOT_FIGURE.flatMap((type) => spansOfType(root, type)),
|
|
147
|
+
);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文末に添えた括弧(「最優先制約とする(§17)。」の(§17))を除いた、文そのものの終わり。
|
|
3
|
+
* 括弧が注記そのもの(文全体が括弧か、終わった文の後ろで「。)」と閉じる)なら、文末はその中にある。
|
|
4
|
+
* 述語に続く括弧は、中で文が終わっていても添え物(「費用(…を除く。)」)。続けて添えた括弧は全部除く。
|
|
5
|
+
*
|
|
6
|
+
* 後ろから一度だけ読む。法令の文は数千字あり、添えた括弧が何百も続くことがある。
|
|
7
|
+
*/
|
|
8
|
+
const OPEN = new Set(["(", "("]);
|
|
9
|
+
const CLOSE = new Set([")", ")"]);
|
|
10
|
+
const STOPS = new Set(["。", ".", "!", "?", "!", "?"]);
|
|
11
|
+
const LINE_BREAKS = new Set(["\n", "\r"]);
|
|
12
|
+
const isSpace = (unit: string): boolean => /\s/u.test(unit);
|
|
13
|
+
const isInlineSpace = (unit: string): boolean => unit === " " || unit === "\t" || unit === " ";
|
|
14
|
+
|
|
15
|
+
/** before より前で、skip に当たらない最後の位置。無ければ -1。 */
|
|
16
|
+
const lastBefore = (text: string, before: number, skip: (unit: string) => boolean): number => {
|
|
17
|
+
let index = before - 1;
|
|
18
|
+
while (index >= 0 && skip(text.charAt(index))) index -= 1;
|
|
19
|
+
return index;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** closeAt の閉じ括弧と対になる開き括弧の位置。対が無ければ undefined。 */
|
|
23
|
+
const openingOf = (text: string, closeAt: number): number | undefined => {
|
|
24
|
+
let depth = 0;
|
|
25
|
+
for (let index = closeAt - 1; index >= 0; index -= 1) {
|
|
26
|
+
const unit = text.charAt(index);
|
|
27
|
+
if (CLOSE.has(unit)) depth += 1;
|
|
28
|
+
else if (OPEN.has(unit) && depth === 0) return index;
|
|
29
|
+
else if (OPEN.has(unit)) depth -= 1;
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** open から closeAt までの括弧が注記そのもの: 文の頭にあるか、終わった文の後ろで、中の文が終わっている。 */
|
|
35
|
+
const isNote = (text: string, open: number, closeAt: number): boolean => {
|
|
36
|
+
if (lastBefore(text, open, isSpace) === -1) return true;
|
|
37
|
+
const previous = text.charAt(lastBefore(text, open, isInlineSpace));
|
|
38
|
+
const inner = lastBefore(text, closeAt, isSpace);
|
|
39
|
+
return (STOPS.has(previous) || LINE_BREAKS.has(previous)) && inner > open && STOPS.has(text.charAt(inner));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const ownEnd = (text: string): number => {
|
|
43
|
+
let limit = text.length;
|
|
44
|
+
for (;;) {
|
|
45
|
+
const closeAt = lastBefore(text, limit, (unit) => isSpace(unit) || STOPS.has(unit));
|
|
46
|
+
const open = CLOSE.has(text.charAt(closeAt)) ? openingOf(text, closeAt) : undefined;
|
|
47
|
+
if (open === undefined) return limit;
|
|
48
|
+
limit = isNote(text, open, closeAt) ? closeAt : open;
|
|
49
|
+
}
|
|
50
|
+
};
|
package/src/tree-walk.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walks over the Markdown tree and the structure tree. Both keep their own stack instead of recursing:
|
|
3
|
+
* a blockquote nested ten thousand levels deep is valid Markdown, and one call per level overflows the call stack.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
type Branching<T> = { readonly children?: readonly T[] | undefined };
|
|
7
|
+
|
|
8
|
+
/** Each node before its children, children from the left: the order a recursive walk visits them. */
|
|
9
|
+
export const eachPreOrder = <T extends Branching<T>>(root: T, visit: (node: T) => void): void => {
|
|
10
|
+
const pending: T[] = [root];
|
|
11
|
+
while (pending.length > 0) {
|
|
12
|
+
const node = pending.pop();
|
|
13
|
+
if (node === undefined) return;
|
|
14
|
+
visit(node);
|
|
15
|
+
(node.children ?? []).toReversed().forEach((child) => pending.push(child));
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** The nodes in pre-order. */
|
|
20
|
+
export const preOrder = <T extends Branching<T>>(root: T): T[] => {
|
|
21
|
+
const nodes: T[] = [];
|
|
22
|
+
eachPreOrder(root, (node) => nodes.push(node));
|
|
23
|
+
return nodes;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type Frame<T, R> = { readonly node: T; readonly children: readonly T[]; readonly results: R[] };
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Each node's value from its children's values: children first, from the left, then the node. depth is 0 at the root.
|
|
30
|
+
* The same calls in the same order as `combine(node, childrenOf(node).map(recurse), depth)`.
|
|
31
|
+
*/
|
|
32
|
+
export const foldPostOrder = <T, R>(root: T, childrenOf: (node: T) => readonly T[], combine: (node: T, children: readonly R[], depth: number) => R): R => {
|
|
33
|
+
const frames: Frame<T, R>[] = [{ node: root, children: childrenOf(root), results: [] }];
|
|
34
|
+
for (;;) {
|
|
35
|
+
const frame = frames.at(-1);
|
|
36
|
+
if (frame === undefined) throw new Error("foldPostOrder lost its root");
|
|
37
|
+
const next = frame.children[frame.results.length];
|
|
38
|
+
if (next !== undefined) {
|
|
39
|
+
frames.push({ node: next, children: childrenOf(next), results: [] });
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
frames.pop();
|
|
43
|
+
const value = combine(frame.node, frame.results, frames.length);
|
|
44
|
+
const parent = frames.at(-1);
|
|
45
|
+
if (parent === undefined) return value;
|
|
46
|
+
parent.results.push(value);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# 文化庁「外来語の表記」(平成 3 年内閣告示第 2 号)の長音の書き方。chaff.yaml に style: bunkacho と書くと使える。
|
|
2
|
+
# JIS Z 8301:2019 も外来語の表記をこれによるとした。告示は「慣用に応じて「ー」を省くことができる」とも書くので、
|
|
3
|
+
# 省いた語は、辞書が「ー」付きで知る語と、文書がほかで「ー」付きで書く語だけを見る(katakana-long-vowel の keep)。
|
|
4
|
+
id: bunkacho
|
|
5
|
+
|
|
6
|
+
name:
|
|
7
|
+
ja: 文化庁「外来語の表記」
|
|
8
|
+
en: The Agency for Cultural Affairs' 外来語の表記 (Cabinet notice, 1991)
|
|
9
|
+
|
|
10
|
+
summary:
|
|
11
|
+
ja: 英語の語末の -er、-or、-ar などは、長音として「ー」を付けます(コンピューター、エレベーター)。
|
|
12
|
+
en: Writes the English endings -er, -or, -ar and the like as a long vowel with ー (コンピューター, エレベーター).
|
|
13
|
+
|
|
14
|
+
source:
|
|
15
|
+
title:
|
|
16
|
+
ja: 外来語の表記(平成 3 年 6 月 28 日 内閣告示第 2 号)留意事項その 2(細則的な事項)Ⅲ 3 注 3
|
|
17
|
+
en: 外来語の表記 (Cabinet notice No. 2 of 28 June 1991), detailed notes (留意事項その2), III 3, note 3
|
|
18
|
+
url: https://www.bunka.go.jp/kokugo_nihongo/sisaku/joho/joho/kijun/naikaku/gairai/honbun06.html
|
|
19
|
+
|
|
20
|
+
rules:
|
|
21
|
+
katakana-long-vowel: normal
|
|
22
|
+
|
|
23
|
+
options:
|
|
24
|
+
katakana-long-vowel:
|
|
25
|
+
ending: keep
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# 電子情報通信学会(IEICE)の和文論文誌の書き方。chaff.yaml に style: ieice と書くと使える。
|
|
2
|
+
# ここに置くのは、案内が言っていることだけ。案内に無いことは足さない。
|
|
3
|
+
#
|
|
4
|
+
# 投稿のしおり 2.4 (b) は、用語を文部省「学術用語集 電気工学編」などによるとする。学術用語集のカタカナ語は、
|
|
5
|
+
# 3 音以上の語の語末の「ー」を省く(コンピュータ、レーザ、プリンタ)。2 音以下の語(カー)は付ける。
|
|
6
|
+
# 2.4 (d) は、句読点を全角の「.」「,」とする。句読点を見る rule が chaff にまだ無いので、ここでは決めない。
|
|
7
|
+
id: ieice
|
|
8
|
+
|
|
9
|
+
name:
|
|
10
|
+
ja: 電子情報通信学会 和文論文誌
|
|
11
|
+
en: IEICE Transactions (papers in Japanese)
|
|
12
|
+
|
|
13
|
+
summary:
|
|
14
|
+
ja: 3 音以上のカタカナ語は語末の「ー」を省きます(コンピュータ、プリンタ)。2 音以下の語(カー)は付けます。
|
|
15
|
+
en: Drops the final ー of katakana words of three morae or more (コンピュータ, プリンタ) and keeps it on shorter words (カー).
|
|
16
|
+
|
|
17
|
+
source:
|
|
18
|
+
title:
|
|
19
|
+
ja: 電子情報通信学会「和文論文誌 投稿のしおり」2.4 用字と用語について (b)。用語は文部省「学術用語集 電気工学編」による
|
|
20
|
+
en: IEICE, 和文論文誌 投稿のしおり (submission guide for papers in Japanese), 2.4 (b); terms follow 学術用語集 電気工学編
|
|
21
|
+
url: https://www.ieice.org/jpn/shiori/cs_2.html
|
|
22
|
+
|
|
23
|
+
rules:
|
|
24
|
+
katakana-long-vowel: normal
|
|
25
|
+
|
|
26
|
+
options:
|
|
27
|
+
katakana-long-vowel:
|
|
28
|
+
ending: drop
|
|
29
|
+
min_morae: 3
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# JIS Z 8301:2011「規格票の様式及び作成方法」の外来語の書き方。chaff.yaml に style: jis-z8301-2011 と書くと使える。
|
|
2
|
+
# 2019 年版はこの原則を外し、「外来語の表記」(平成 3 年内閣告示第 2 号)によるとした。2019 年版に合わせるなら style: bunkacho。
|
|
3
|
+
id: jis-z8301-2011
|
|
4
|
+
|
|
5
|
+
name:
|
|
6
|
+
ja: JIS Z 8301:2011 規格票の様式及び作成方法
|
|
7
|
+
en: JIS Z 8301:2011, rules for the structure and drafting of standards
|
|
8
|
+
|
|
9
|
+
summary:
|
|
10
|
+
ja: 3 音以上の外来語は語末の「ー」を省き(コンピュータ)、2 音以下は付けます(カー)。2019 年版はこの原則を外しました。
|
|
11
|
+
en: Drops the final ー of loanwords of three morae or more (コンピュータ) and keeps it on shorter ones (カー). The 2019 edition dropped this principle.
|
|
12
|
+
|
|
13
|
+
source:
|
|
14
|
+
title:
|
|
15
|
+
ja: JIS Z 8301:2011 附属書 G 表 G.3「外来語の表記に語尾の長音符号を省く場合の原則」
|
|
16
|
+
en: JIS Z 8301:2011 Annex G, Table G.3 (the principle for omitting the final long-vowel mark of loanwords)
|
|
17
|
+
url: https://www.jisc.go.jp/
|
|
18
|
+
|
|
19
|
+
rules:
|
|
20
|
+
katakana-long-vowel: normal
|
|
21
|
+
|
|
22
|
+
options:
|
|
23
|
+
katakana-long-vowel:
|
|
24
|
+
ending: drop
|
|
25
|
+
min_morae: 3
|