gatsby-transformer-remark vs react-markdown vs react-remark vs remarkable
Markdown Processing Libraries
gatsby-transformer-remarkreact-markdownreact-remarkremarkableSimilar Packages:

Markdown Processing Libraries

Markdown processing libraries are essential tools in web development that enable developers to convert Markdown text into HTML. These libraries facilitate the integration of Markdown content into web applications, allowing for easy formatting of text without the need for complex HTML structures. They often come with various features such as syntax highlighting, custom rendering options, and extensibility through plugins, making them versatile for different use cases in content management and presentation.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
gatsby-transformer-remark055,951118 kB3466 months agoMIT
react-markdown015,51152.6 kB3a year agoMIT
react-remark024437.3 kB14-MIT
remarkable05,826-1326 years agoMIT

Feature Comparison: gatsby-transformer-remark vs react-markdown vs react-remark vs remarkable

Integration

  • gatsby-transformer-remark:

    Gatsby-transformer-remark integrates seamlessly with Gatsby's ecosystem, allowing for efficient data sourcing and transformation of Markdown files into HTML. It leverages Gatsby's GraphQL API to provide a structured way to query your Markdown content, making it ideal for static site generation.

  • react-markdown:

    React-markdown is designed to work directly within React components, allowing developers to easily render Markdown content without additional setup. It provides a simple interface for including Markdown in your React application, making it highly accessible for developers familiar with React.

  • react-remark:

    React-remark provides a bridge to the Remark ecosystem, allowing developers to utilize Remark's extensive plugin architecture within React applications. This integration enables advanced Markdown processing capabilities, making it suitable for projects requiring custom transformations and syntax highlighting.

  • remarkable:

    Remarkable is a standalone Markdown parser that can be integrated into various JavaScript environments. It is lightweight and fast, making it a good choice for applications where performance is a priority, and it can be easily used in both client-side and server-side contexts.

Customization

  • gatsby-transformer-remark:

    Gatsby-transformer-remark supports customization through plugins and options, allowing developers to tailor the Markdown processing to their specific needs. This includes features like syntax highlighting, custom block rendering, and more, providing flexibility in how Markdown content is displayed.

  • react-markdown:

    React-markdown allows for significant customization through its renderers, enabling developers to define how each Markdown element should be rendered in React. This flexibility makes it easy to integrate Markdown content into existing UI components and apply custom styles or behaviors.

  • react-remark:

    React-remark offers extensive customization options by leveraging Remark's plugin system. Developers can create custom plugins to modify the Markdown processing pipeline, allowing for tailored transformations and enhancements to the Markdown content.

  • remarkable:

    Remarkable provides a limited but effective customization interface, allowing developers to configure parsing options and enable or disable specific features. While not as extensive as some other libraries, it provides enough flexibility for most standard use cases.

Performance

  • gatsby-transformer-remark:

    Gatsby-transformer-remark is optimized for performance within the Gatsby framework, leveraging static site generation to ensure that Markdown content is pre-rendered at build time. This results in fast load times and improved SEO, making it suitable for high-performance websites.

  • react-markdown:

    React-markdown is lightweight and efficient, designed to render Markdown content quickly in React applications. Its performance is generally good, but developers should be mindful of how they structure their components to avoid unnecessary re-renders.

  • react-remark:

    React-remark benefits from Remark's performance optimizations, allowing for efficient parsing and rendering of Markdown content. The use of plugins can enhance performance further, depending on the complexity of the Markdown being processed.

  • remarkable:

    Remarkable is known for its speed and efficiency, making it one of the fastest Markdown parsers available. Its lightweight design ensures quick parsing and rendering, which is beneficial for applications that require high performance.

Learning Curve

  • gatsby-transformer-remark:

    Gatsby-transformer-remark has a moderate learning curve, especially for developers new to Gatsby. Understanding how to configure and use the GraphQL data layer effectively is essential, but once learned, it provides powerful capabilities for Markdown processing.

  • react-markdown:

    React-markdown is easy to learn for developers familiar with React. Its straightforward API and component-based approach make it accessible, allowing for quick integration into existing projects without a steep learning curve.

  • react-remark:

    React-remark may have a steeper learning curve due to its reliance on the Remark ecosystem and the need to understand how to use plugins effectively. However, it offers powerful capabilities for those willing to invest the time to learn.

  • remarkable:

    Remarkable has a low learning curve, as it is designed to be simple and straightforward. Developers can quickly get started with basic Markdown parsing without needing extensive documentation.

Community and Support

  • gatsby-transformer-remark:

    Gatsby-transformer-remark benefits from the strong Gatsby community, which provides extensive documentation, tutorials, and support resources. This makes it easier for developers to find help and share knowledge.

  • react-markdown:

    React-markdown has a growing community and is well-documented, making it easy for developers to find examples and support. Its popularity in the React ecosystem ensures that there are plenty of resources available.

  • react-remark:

    React-remark, while less popular than some alternatives, has a dedicated user base and access to the broader Remark community. Documentation is available, but resources may be more limited compared to more widely used libraries.

  • remarkable:

    Remarkable has a smaller community compared to others, but it is well-documented and provides essential support for developers. Its simplicity and performance have garnered a loyal user base.

How to Choose: gatsby-transformer-remark vs react-markdown vs react-remark vs remarkable

  • gatsby-transformer-remark:

    Choose gatsby-transformer-remark if you are using Gatsby.js for your static site generation and need a seamless way to transform Markdown files into HTML while leveraging Gatsby's GraphQL data layer. This package is specifically designed for Gatsby projects and provides powerful features like syntax highlighting and custom plugins for enhanced functionality.

  • react-markdown:

    Select react-markdown if you are building a React application and want a straightforward way to render Markdown directly in your components. It offers a simple API and supports custom renderers, allowing you to easily customize how different Markdown elements are displayed without much overhead.

  • react-remark:

    Opt for react-remark if you need a React wrapper around the Remark library, which is a powerful Markdown processor. This package is suitable for developers looking for extensive customization options and the ability to use Remark plugins for advanced Markdown processing, making it ideal for complex use cases.

  • remarkable:

    Use remarkable if you are looking for a fast and lightweight Markdown parser that can be integrated into various JavaScript environments. It is particularly useful for projects where performance is critical, and you want a simple, no-frills solution for converting Markdown to HTML.

README for gatsby-transformer-remark

gatsby-transformer-remark

Parses Markdown files using remark.

Install

Install the plugin to your site:

npm install gatsby-transformer-remark

Add it to your gatsby-config:

module.exports = {
  plugins: [
    {
      resolve: `gatsby-transformer-remark`,
      options: {},
    },
  ],
}

Options

module.exports = {
  plugins: [
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        // Footnotes mode (default: true)
        footnotes: true,
        // GitHub Flavored Markdown mode (default: true)
        gfm: true,
        // Add your gatsby-remark-* plugins here
        plugins: [],
        // Enable JS for https://github.com/jonschlinkert/gray-matter#optionsengines (default: false)
        // It's not advised to set this to "true" and this option will likely be removed in the future
        jsFrontmatterEngine: false,
      },
    },
  ],
}

The following parts of options enable the remark-footnotes and remark-gfm plugins:

  • options.footnotes
  • options.gfm

A full explanation of how to use markdown in Gatsby can be found here: Adding Markdown Pages

There are many gatsby-remark-* plugins which you can install to customize how Markdown is processed. Check out the source code for using-remark as an example.

gray-matter options

gatsby-transformer-remark uses gray-matter to parse Markdown frontmatter, so you can specify any of the options mentioned in its README in the options key of the plugin.

Example: Excerpts

If you don't want to use pruneLength for excerpts but a custom separator, you can specify an excerpt_separator:

module.exports = {
  plugins: [
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        excerpt_separator: `<!-- end -->`
      }
    },
  ],
}

Parsing algorithm

It recognizes files with the following extensions as Markdown:

  • md
  • markdown

Each Markdown file is parsed into a node of type MarkdownRemark.

All frontmatter fields are converted into GraphQL fields through inference.

This plugin adds additional fields to the MarkdownRemark GraphQL type including html, excerpt, headings, etc. Other Gatsby plugins can also add additional fields.

How to query

A sample GraphQL query to get MarkdownRemark nodes:

{
  allMarkdownRemark {
    edges {
      node {
        html
        headings {
          depth
          value
        }
        frontmatter {
          # Assumes you're using title in your frontmatter.
          title
        }
      }
    }
  }
}

Getting table of contents

Using the following GraphQL query you'll be able to get the table of contents

{
  allMarkdownRemark {
    edges {
      node {
        html
        tableOfContents
      }
    }
  }
}

Configuring the tableOfContents

By default, absolute is set to false, generating a relative path. If you'd like to generate an absolute path, pass absolute: true. In that case, be sure to pass the pathToSlugField parameter, often fields.slug, to create absolute URLs. Note that providing a non-existent field will cause the result to be null. To alter the default values for tableOfContents generation, include values for heading (string) and/or maxDepth (number 1 to 6) in GraphQL query. If a value for heading is given, the first heading that matches will be omitted and the ToC is generated from the next heading of the same depth onwards. Value for maxDepth sets the maximum depth of the toc (i.e. if a maxDepth of 3 is set, only h1 to h3 headings will appear in the toc).

{
  allMarkdownRemark {
    edges {
      node {
        html
        tableOfContents(
          absolute: true
          pathToSlugField: "frontmatter.path"
          heading: "only show toc from this heading onwards"
          maxDepth: 2
        )
        frontmatter {
          # Assumes you're using path in your frontmatter.
          path
        }
      }
    }
  }
}

To pass default options to the plugin generating the tableOfContents, configure it in gatsby-config.js as shown below. The options shown below are the defaults used by the plugin.

module.exports = {
  plugins: [
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        tableOfContents: {
          heading: null,
          maxDepth: 6,
        },
      },
    },
  ],
}

Excerpts

Length

By default, excerpts have a maximum length of 140 characters. You can change the default using the pruneLength argument. For example, if you need 500 characters, you can specify:

{
  allMarkdownRemark {
    edges {
      node {
        html
        excerpt(pruneLength: 500)
      }
    }
  }
}

Format

By default, Gatsby will return excerpts as plain text. This might be useful for populating opengraph HTML tags for SEO reasons. You can also explicitly specify a PLAIN format like so:

{
  allMarkdownRemark {
    edges {
      node {
        excerpt(format: PLAIN)
      }
    }
  }
}

It's also possible to ask Gatsby to return excerpts formatted as HTML. You might use this if you have a blog post whose excerpt contains markdown content -- e.g. header, link, etc. -- and you want these links to render as HTML.

{
  allMarkdownRemark {
    edges {
      node {
        excerpt(format: HTML)
      }
    }
  }
}

You can also get excerpts in Markdown format.

{
  allMarkdownRemark {
    edges {
      node {
        excerpt(format: MARKDOWN)
      }
    }
  }
}

Any file that does not have the given excerpt_separator will fall back to the default pruning method.

Troubleshooting

Excerpts for non-latin languages

By default, excerpt uses underscore.string/prune which doesn't handle non-latin characters (https://github.com/epeli/underscore.string/issues/418).

If that is the case, you can set truncate option on excerpt field, like:

{
  markdownRemark {
    excerpt(truncate: true)
  }
}

Excerpts for HTML embedded in Markdown files

If your Markdown file contains HTML, excerpt will not return a value.

In that case, you can set an excerpt_separator in the gatsby-config:

module.exports = {
  plugins: [
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        excerpt_separator: `<!-- endexcerpt -->`
      },
    },
  ],
}

Edit your Markdown files to include that HTML tag after the text you'd like to appear in the excerpt:

---
title: "my little pony"
date: "2017-09-18T23:19:51.246Z"
---

<p>Where oh where is that pony?</p>
<!-- endexcerpt -->
<p>Is he in the stable or down by the stream?</p>

Then specify MARKDOWN as the format in your GraphQL query:

{
  markdownRemark {
    excerpt(format: MARKDOWN)
  }
}