What is remark-parse?
The remark-parse package is a plugin for the Remark processor that parses Markdown content into a syntax tree. It is part of the unified ecosystem, which provides a way to parse, transform, and stringify content using abstract syntax trees (ASTs).
What are remark-parse's main functionalities?
Parsing Markdown
This feature allows you to parse Markdown content and transform it into an abstract syntax tree (AST). The code sample demonstrates how to use remark-parse with the remark library to parse a simple Markdown string.
const remark = require('remark');
const parse = require('remark-parse');
remark().use(parse).process('# Hello world!', function(err, file) {
if (err) throw err;
console.log(file);
});
Extensible Markdown Parsing
remark-parse can be extended with plugins to handle custom Markdown syntax. In this example, the 'remark-math' plugin is used to parse mathematical expressions within the Markdown content.
const remark = require('remark');
const parse = require('remark-parse');
const math = require('remark-math');
remark().use(parse).use(math).process('Euler's identity: $e^{i\pi} + 1 = 0$', function(err, file) {
if (err) throw err;
console.log(file);
});
Other packages similar to remark-parse
markdown-it
markdown-it is a Markdown parser with a similar goal to remark-parse, but it is implemented differently. It is often used for its speed and extensibility with plugins, and it can output HTML directly instead of an AST.
marked
marked is another Markdown parser that is known for being fast and lightweight. It is less extensible than remark-parse but can be a good choice for simpler use cases where a full AST is not required.
Parser for unified.
Parses Markdown to mdast syntax trees.
Built on micromark
and
mdast-util-from-markdown
.
Used in the remark processor but can be used on its own as well.
Can be extended to change how Markdown is parsed.
Install
npm:
npm install remark-parse
Use
var unified = require('unified')
var createStream = require('unified-stream')
var markdown = require('remark-parse')
var remark2rehype = require('remark-rehype')
var html = require('rehype-stringify')
var processor = unified().use(markdown).use(remark2rehype).use(html)
process.stdin.pipe(createStream(processor)).pipe(process.stdout)
See unified for more examples »
API
See unified for API docs »
processor().use(parse)
Configure the processor
to read Markdown as input and process
mdast syntax trees.
Extending the parser
See micromark
and mdast-util-from-markdown
.
Then create a wrapper plugin such as remark-gfm
.
Security
As Markdown is sometimes used for HTML, and improper use of HTML can open you up
to a cross-site scripting (XSS) attack, use of remark can also be unsafe.
When going to HTML, use remark in combination with the rehype
ecosystem, and use rehype-sanitize
to make the tree safe.
Use of remark plugins could also open you up to other attacks.
Carefully assess each plugin and the risks involved in using them.
Contribute
See contributing.md
in remarkjs/.github
for ways
to get started.
See support.md
for ways to get help.
Ideas for new plugins and tools can be posted in remarkjs/ideas
.
A curated list of awesome remark resources can be found in awesome
remark.
This project has a code of conduct.
By interacting with this repository, organization, or community you agree to
abide by its terms.
Support this effort and give back by sponsoring on OpenCollective!
License
MIT © Titus Wormer