What is remark?
The remark npm package is a powerful, extensible Markdown processor built on the unified collective ecosystem. It allows for parsing, transforming, and compiling Markdown content with a focus on syntax trees. Remark can be used for a variety of tasks such as linting Markdown, transforming the syntax for different purposes, or extracting metadata from documents.
What are remark's main functionalities?
Parsing Markdown to Syntax Trees
This feature allows users to parse Markdown content into an abstract syntax tree (AST), enabling programmatic analysis and manipulation of the content.
const remark = require('remark');
const markdown = 'Some **Markdown** text.';
remark().parse(markdown);
Transforming Syntax Trees
With this feature, users can transform the syntax tree generated from Markdown content. For example, converting the tree to HTML by using the remark-html plugin.
const remark = require('remark');
const html = require('remark-html');
const markdown = 'Some **Markdown** text.';
remark().use(html).processSync(markdown).toString();
Linting Markdown
This feature enables users to lint their Markdown content for style and syntax issues, ensuring consistency and quality in their Markdown files.
const remark = require('remark');
const recommended = require('remark-preset-lint-recommended');
const report = require('vfile-reporter');
remark().use(recommended).process('_Emphasis_ and **importance**', (err, file) => {
console.error(report(err || file));
});
Other packages similar to remark
markdown-it
markdown-it is a fast and extensible Markdown parser that can render HTML. It is similar to remark in its extensibility but focuses more on speed and adherence to the CommonMark specification without an emphasis on abstract syntax trees.
showdown
showdown is another Markdown to HTML converter that can run both in the browser and on the server. Unlike remark, which is built around a plugin ecosystem and AST manipulation, showdown focuses on configurability and extension through a different type of extension mechanism.
marked
marked is a low-level Markdown compiler for parsing Markdown without caching or blocking for files. It is designed for speed and is simpler in scope compared to remark, which offers a broader range of processing capabilities through its plugins and unified ecosystem.
The remark processor is a markdown processor powered by
plug-ins.
Don’t need the parser? Or the compiler? That’s OK.
Installation
npm:
npm install remark
Usage
var remark = require('remark');
var lint = require('remark-lint');
var html = require('remark-html');
var report = require('vfile-reporter');
remark().use(lint).use(html).process('## Hello world!', function (err, file) {
console.error(report(file));
console.log(file.toString());
});
Yields:
<stdin>
1:1 warning Missing newline character at end of file final-newline
1:1-1:16 warning First heading level should be `1` first-heading-level
1:1-1:16 warning Don’t add a trailing `!` to headings no-heading-punctuation
⚠ 3 warnings
<h2>Hello world!</h2>
License
MIT © Titus Wormer