remark-parse vs remark-gfm vs remark-mdx vs remark-frontmatter vs remark-html
Markdown Processing in JavaScript
remark-parseremark-gfmremark-mdxremark-frontmatterremark-htmlSimilar Packages:
Markdown Processing in JavaScript

Markdown Processing in JavaScript refers to the manipulation and transformation of Markdown content (a lightweight markup language) within JavaScript applications. This can include parsing Markdown text into a structured format (like an Abstract Syntax Tree or AST), converting it into HTML or other formats, and handling various Markdown features such as frontmatter, tables, and custom components. JavaScript libraries like remark and its plugins provide powerful tools for these tasks, enabling developers to integrate Markdown processing seamlessly into their web applications, content management systems, or static site generators.

Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
remark-parse16,379,8878,63619.5 kB42 years agoMIT
remark-gfm9,066,4431,09622 kB210 months agoMIT
remark-mdx4,158,11019,07114.7 kB203 months agoMIT
remark-frontmatter1,911,11930921.2 kB02 years agoMIT
remark-html488,81933617 kB02 years agoMIT
Feature Comparison: remark-parse vs remark-gfm vs remark-mdx vs remark-frontmatter vs remark-html

Frontmatter Support

  • remark-parse:

    remark-parse is a general-purpose Markdown parser that does not specifically handle frontmatter. However, it can be extended with plugins to parse frontmatter if needed.

  • remark-gfm:

    remark-gfm does not provide frontmatter support, as it focuses on enhancing Markdown parsing with GitHub Flavored features like tables and strikethroughs.

  • remark-mdx:

    remark-mdx does not handle frontmatter directly, but it allows for the integration of frontmatter in MDX files. You can use other tools or plugins alongside MDX to manage frontmatter data.

  • remark-frontmatter:

    remark-frontmatter provides dedicated support for parsing frontmatter sections in Markdown files. It extracts metadata from YAML or TOML blocks, making it easy to access and use this information in your application.

  • remark-html:

    remark-html does not handle frontmatter. It is primarily concerned with converting Markdown content to HTML, leaving frontmatter processing to other tools or plugins.

GFM Compatibility

  • remark-parse:

    remark-parse is a basic Markdown parser that does not include GFM support by default. However, it can be extended with plugins like remark-gfm to add GFM features during the parsing process.

  • remark-gfm:

    remark-gfm is specifically designed to add GitHub Flavored Markdown (GFM) compatibility to your Markdown processing. It includes support for GFM features like tables, strikethroughs, and task lists, making it the go-to choice for GFM rendering.

  • remark-mdx:

    remark-mdx does not focus on GFM compatibility, but it allows for the use of GFM features within MDX files. You can integrate GFM support by using remark-gfm alongside remark-mdx in your processing pipeline.

  • remark-frontmatter:

    remark-frontmatter does not handle GFM features, as its primary focus is on parsing frontmatter sections in Markdown. It does not interfere with GFM compatibility, so you can use it alongside GFM-supporting plugins.

  • remark-html:

    remark-html does not provide GFM support by itself, but it can be used in conjunction with remark-gfm to render GFM features in HTML. You would need to include remark-gfm as a plugin to enable GFM features during the parsing process.

HTML Conversion

  • remark-parse:

    remark-parse does not convert Markdown to HTML. It parses the Markdown text and generates an Abstract Syntax Tree (AST), which can then be processed by other tools or plugins for HTML conversion.

  • remark-gfm:

    remark-gfm does not perform HTML conversion. It is a plugin that enhances Markdown parsing with GFM features, but you will need to use remark-html or another HTML conversion tool to render the output.

  • remark-mdx:

    remark-mdx allows for HTML conversion of MDX content, including any embedded React components. However, it does not handle the conversion itself; you will need to use a compatible renderer that supports both Markdown and JSX.

  • remark-frontmatter:

    remark-frontmatter does not handle HTML conversion. It focuses on parsing frontmatter in Markdown, leaving the rendering of the content to other tools.

  • remark-html:

    remark-html is the standard package for converting Markdown content into HTML. It ensures that the Markdown is rendered correctly and safely for use in web applications.

MDX Support

  • remark-parse:

    remark-parse is a general-purpose Markdown parser that does not support MDX. However, it can parse the Markdown portion of MDX files; you will need additional tools to handle the JSX elements.

  • remark-gfm:

    remark-gfm does not provide MDX support, as it focuses on enhancing Markdown with GitHub Flavored features. It can be used alongside MDX, but it does not interact with the JSX elements in any way.

  • remark-mdx:

    remark-mdx is specifically designed to support MDX (Markdown + JSX), allowing you to write Markdown content alongside React components. It enables a seamless integration of JSX within Markdown files, making it ideal for projects that require interactive or component-based content.

  • remark-frontmatter:

    remark-frontmatter does not handle MDX content. It is focused on parsing frontmatter in Markdown files and does not interact with JSX or component-based content.

  • remark-html:

    remark-html does not support MDX natively. However, it can be used in conjunction with remark-mdx to render MDX content after it has been processed. You will need to handle the JSX conversion separately, typically using a React renderer.

Ease of Use: Code Examples

  • remark-parse:

    Markdown Parsing Example with remark-parse

    import { unified } from 'unified';
    import remarkParse from 'remark-parse';
    
    const markdown = `# Hello World
    This is a sample Markdown.`;
    
    unified()
      .use(remarkParse)
      .process(markdown)
      .then((file) => {
        console.log(file.contents);
      });
    
  • remark-gfm:

    GFM Example with remark-gfm

    import { unified } from 'unified';
    import remarkParse from 'remark-parse';
    import remarkGfm from 'remark-gfm';
    import remarkHtml from 'remark-html';
    
    const markdown = `# Task List
    - [ ] Item 1
    - [x] Item 2
    
    | Header 1 | Header 2 |
    | -------- | -------- |
    | Row 1    | Data 1   |
    | Row 2    | Data 2   |
    `;
    
    unified()
      .use(remarkParse)
      .use(remarkGfm)
      .use(remarkHtml)
      .process(markdown)
      .then((file) => {
        console.log(String(file));
      });
    
  • remark-mdx:

    MDX Example with remark-mdx

    import { unified } from 'unified';
    import remarkParse from 'remark-parse';
    import remarkMdx from 'remark-mdx';
    
    const mdx = `# Hello MDX
    
    <MyComponent />
    `;
    
    unified()
      .use(remarkParse)
      .use(remarkMdx)
      .process(mdx)
      .then((file) => {
        console.log(String(file));
      });
    
  • remark-frontmatter:

    Frontmatter Example with remark-frontmatter

    import { unified } from 'unified';
    import remarkParse from 'remark-parse';
    import remarkFrontmatter from 'remark-frontmatter';
    
    const markdown = `---
    title: My Post
    ---
    
    # Hello World
    `;
    
    unified()
      .use(remarkParse)
      .use(remarkFrontmatter)
      .process(markdown)
      .then((file) => {
        console.log(String(file));
      });
    
  • remark-html:

    HTML Conversion Example with remark-html

    import { unified } from 'unified';
    import remarkParse from 'remark-parse';
    import remarkHtml from 'remark-html';
    
    const markdown = `# Hello World
    This is a sample Markdown.`;
    
    unified()
      .use(remarkParse)
      .use(remarkHtml)
      .process(markdown)
      .then((file) => {
        console.log(String(file));
      });
    
How to Choose: remark-parse vs remark-gfm vs remark-mdx vs remark-frontmatter vs remark-html
  • remark-parse:

    Choose remark-parse if you need a fast and extensible Markdown parser that converts Markdown text into an Abstract Syntax Tree (AST). This is the foundational package for building custom Markdown processing workflows.

  • remark-gfm:

    Select remark-gfm if you want to add support for GitHub Flavored Markdown (GFM) features, including tables, strikethroughs, and task lists. This is ideal for applications that need to render Markdown content with GFM compatibility.

  • remark-mdx:

    Opt for remark-mdx if you want to work with MDX (Markdown + JSX), allowing you to embed React components directly within your Markdown files. This is perfect for projects that require a mix of Markdown content and interactive components.

  • remark-frontmatter:

    Choose remark-frontmatter if you need to parse and handle frontmatter (YAML or TOML) sections in your Markdown files. This is useful for static site generators or applications that require metadata from Markdown content.

  • remark-html:

    Use remark-html when you need to convert Markdown content into HTML. This package is essential for rendering Markdown in web applications, ensuring that the output is properly formatted and safe for use in the DOM.

README for remark-parse

remark-parse

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to add support for parsing from markdown.

Contents

What is this?

This package is a unified (remark) plugin that defines how to take markdown as input and turn it into a syntax tree.

See the monorepo readme for info on what the remark ecosystem is.

When should I use this?

This plugin adds support to unified for parsing markdown. If you also need to serialize markdown, you can alternatively use remark, which combines unified, this plugin, and remark-stringify.

If you just want to turn markdown into HTML (with maybe a few extensions), we recommend micromark instead. If you don’t use plugins and want to access the syntax tree, you can directly use mdast-util-from-markdown. remark focusses on making it easier to transform content by abstracting these internals away.

You can combine this plugin with other plugins to add syntax extensions. Notable examples that deeply integrate with it are remark-gfm, remark-mdx, remark-frontmatter, remark-math, and remark-directive. You can also use any other remark plugin after remark-parse.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install remark-parse

In Deno with esm.sh:

import remarkParse from 'https://esm.sh/remark-parse@11'

In browsers with esm.sh:

<script type="module">
  import remarkParse from 'https://esm.sh/remark-parse@11?bundle'
</script>

Use

Say we have the following module example.js:

import rehypeStringify from 'rehype-stringify'
import remarkGfm from 'remark-gfm'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'

const doc = `
# Mercury

**Mercury** is the first planet from the [Sun](https://en.wikipedia.org/wiki/Sun)
and the smallest planet in the Solar System.
`

const file = await unified()
  .use(remarkParse)
  .use(remarkGfm)
  .use(remarkRehype)
  .use(rehypeStringify)
  .process(doc)

console.log(String(file))

…then running node example.js yields:

<h1>Mercury</h1>
<p><strong>Mercury</strong> is the first planet from the <a href="https://en.wikipedia.org/wiki/Sun">Sun</a>
and the smallest planet in the Solar System.</p>

API

This package exports no identifiers. The default export is remarkParse.

unified().use(remarkParse)

Add support for parsing from markdown.

Parameters

There are no parameters.

Returns

Nothing (undefined).

Examples

Example: support GFM and frontmatter

We support CommonMark by default. Non-standard markdown extensions can be enabled with plugins.

This example shows how to support GFM features (autolink literals, footnotes, strikethrough, tables, tasklists) and frontmatter (YAML):

import rehypeStringify from 'rehype-stringify'
import remarkFrontmatter from 'remark-frontmatter'
import remarkGfm from 'remark-gfm'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'

const doc = `---
layout: solar-system
---

# Hi ~~Mars~~Venus!
`

const file = await unified()
  .use(remarkParse)
  .use(remarkFrontmatter)
  .use(remarkGfm)
  .use(remarkRehype)
  .use(rehypeStringify)
  .process(doc)

console.log(String(file))

Yields:

<h1>Hi <del>Mars</del>Venus!</h1>

Example: turning markdown into a man page

Man pages (short for manual pages) are a way to document CLIs (example: type man git-log in your terminal). They use an old markup format called roff. There’s a remark plugin, remark-man, that can serialize as roff.

This example shows how to turn markdown into man pages by using unified with remark-parse and remark-man:

import remarkMan from 'remark-man'
import remarkParse from 'remark-parse'
import {unified} from 'unified'

const doc = `
# titan(7) -- largest moon of saturn

Titan is the largest moon…
`

const file = await unified().use(remarkParse).use(remarkMan).process(doc)

console.log(String(file))

Yields:

.TH "TITAN" "7" "September 2023" "" ""
.SH "NAME"
\fBtitan\fR - largest moon of saturn
.P
Titan is the largest moon…

Syntax

Markdown is parsed according to CommonMark. Other plugins can add support for syntax extensions. If you’re interested in extending markdown, more information is available in micromark’s readme.

Syntax tree

The syntax tree used in remark is mdast.

Types

This package is fully typed with TypeScript. It exports the additional type Options (which is currently empty).

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, remark-parse@^11, compatible with Node.js 16.

Security

As markdown can be turned into HTML and improper use of HTML can open you up to cross-site scripting (XSS) attacks, use of remark can be unsafe. When going to HTML, you will combine remark with rehype, in which case you should use rehype-sanitize.

Use of remark plugins could also open you up to other attacks. Carefully assess each plugin and the risks involved in using them.

For info on how to submit a report, see our security policy.

Contribute

See contributing.md in remarkjs/.github for ways to get started. See support.md for ways to get help. Join us in Discussions to chat with the community and contributors.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

Sponsor

Support this effort and give back by sponsoring on OpenCollective!

Vercel

Motif

HashiCorp

GitBook

Gatsby

Netlify

Coinbase

ThemeIsle

Expo

Boost Note

Markdown Space

Holloway


You?

License

MIT © Titus Wormer