annotatedtext-remark
Version:
A lightweight JavaScript library based on annotatedtext and remark-parse for converting markdown documents into an annotated text format consumable by LanguageTool as AnnotatedText.
26 lines • 914 B
JavaScript
import * as annotatedtext from "annotatedtext";
import frontmatter from "remark-frontmatter";
import remarkparse from "remark-parse";
import { unified } from "unified";
const defaults = {
children(node) {
return annotatedtext.defaults.children(node);
},
annotatetextnode(node, text) {
return annotatedtext.defaults.annotatetextnode(node, text);
},
interpretmarkup(text = "") {
return "\n".repeat((text.match(/\n/g) || []).length);
},
// See: https://github.com/syntax-tree/mdast-util-from-markdown#frommarkdowndoc-encoding-options
remarkoptions: {},
};
function build(text, options = defaults) {
const nodes = unified()
.use(remarkparse, options.remarkoptions)
.use(frontmatter, ["yaml", "toml"])
.parse(text);
return annotatedtext.compose(text, nodes, options);
}
export { build, defaults };
//# sourceMappingURL=index.js.map