textlint-plugin-typst-prose
v1.0.0
Published
A prose-oriented wrapper for textlint-plugin-typst
Maintainers
Readme
textlint-plugin-typst-prose
A prose-oriented wrapper for textlint-plugin-typst.
textlint-plugin-typst-prose is a textlint plugin that post-processes the AST produced by textlint-plugin-typst and turns non-prose Typst commands into Comment nodes.
Customization
Issues and pull requests are welcome, but project-specific commands and templates may be easier to maintain in a fork.
Purpose
Typst documents often mix prose with #set, #show, #import, labels, footnotes, bibliographies, and custom functions for figures or tables.
These are valid parts of a Typst document, but prose-oriented textlint rules such as sentence-length may treat non-prose commands as prose and report unwanted errors.
This plugin is not a Typst parser. It is a small wrapper that makes Typst documents easier to proofread with textlint.
Installation
npm install --save-dev textlint textlint-plugin-typst-prose textlint-rule-sentence-lengthUsage
Add it to .textlintrc.
{
"plugins": {
"typst-prose": true
},
"rules": {
"sentence-length": true
}
}Suppressed Nodes
The plugin currently converts the following Typst elements into Comment nodes.
- Labels
#footnote(...)#bibliography(...)#show#set#let#import
Example
For example, suppose you have the following Typst document.
#import "@preview/tablex:0.0.8": tablex
#set text(lang: "ja")
This is prose. #footnote[This is a footnote.]
@fig:overviewThis plugin does not rewrite the Typst source code. It only replaces non-prose nodes with Comment nodes in the AST that textlint reads.
When textlint rules read the original textlint-plugin-typst AST directly, they may treat Typst commands and footnotes as prose and report errors like this.
error Line 1: Sentence is too long.
#import "@preview/tablex:0.0.8": tablex
error Line 4: Sentence is too long.
#footnote[This is a footnote.]With this plugin, the AST read by textlint is transformed as follows.
[
{ type: "Comment", raw: "#" },
{ type: "Comment", raw: '#import "@preview/tablex:0.0.8": tablex' },
{ type: "Comment", raw: "#" },
{ type: "Comment", raw: '#set text(lang: "ja")' },
{ type: "Str", value: "This is prose." },
{ type: "Comment", raw: "#" },
{ type: "Comment", raw: "#footnote[This is a footnote.]" },
{ type: "Comment", raw: "@fig:overview" }
]As a result, prose-oriented rules such as sentence-length can focus on prose such as This is prose..
Why Comment Nodes?
Many prose-oriented textlint rules do not treat Comment nodes as prose.
This plugin does not rewrite Typst source code. It only post-processes the AST generated by textlint-plugin-typst.
Notes
This plugin is not a Typst parser. Typst AST generation is delegated to textlint-plugin-typst.
It also does not automatically detect every user-defined Typst function.
