Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

remark-loader

webpack-contrib52.3kMIT6.0.0

Load markdown through remark with some react-specific features.

react, markdown, webpack, webpack-loader, loader

readme

npm node tests cover discussion size

Remark Loader

Load markdown through remark.

Usage

Simply add the loader to your configuration, and pass options.

import md from "markdown-file.md";

console.log(md);

webpack.config.js

import RemarkHTML from "remark-html";

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "html-loader",
          },
          {
            loader: "remark-loader",
            options: {
              remarkOptions: {
                plugins: [RemarkHTML],
              },
            },
          },
        ],
      },
    ],
  },
};

Here's the full list of remark plugins.

We no longer support any react specific features. Please see the wonderful MDX project if you're interested in mixing JSX with Markdown.

Options

remarkOptions

Remark options

Type:

type remarkOptions = {
  plugins: Array<string | Array>;
  settings: Object;
  data: Object;
};

plugins

Allows to connect remark plugins Type:

type plugins = Array<string | Array>;

Default: []

Allows to connect remark plugins

string

webpack.config.js

import RemarkFrontmatter from "remark-frontmatter";

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "remark-loader",
            options: {
              remarkOptions: {
                plugins: [RemarkFrontmatter],
              },
            },
          },
        ],
      },
    ],
  },
};
array

If need to specify options for the plugin, can pass the plugin using an array, where the second argument will be options.

webpack.config.js

import RemarkFrontmatter from "remark-frontmatter";
import RemarkBookmarks from "remark-bookmarks";

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "remark-loader",
            options: {
              remarkOptions: {
                plugins: [
                  RemarkFrontmatter,
                  [
                    RemarkBookmarks,
                    {
                      bookmarks: {
                        npm: "https://npmjs.com/package/remark-bookmarks",
                      },
                    },
                  ],
                ],
              },
            },
          },
        ],
      },
    ],
  },
};

settings

Remark settings
Type:

type settings = Object;

Default: undefined

Pass remark-stringify options and remark-parse options options to the remark.

webpack.config.js

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "remark-loader",
            options: {
              remarkOptions: {
                settings: {
                  bullet: "+",
                  listItemIndent: "1",
                },
              },
            },
          },
        ],
      },
    ],
  },
};

data

Information available to all plugins
Type:

type data = Object;

Default: undefined

Configure the remark with information available to all plugins. Information is stored in an in-memory key-value store.

webpack.config.js

function examplePluginUsingData() {
  console.log(this.data);
  // { alpha: 'bravo', charlie: 'delta' }
}

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "remark-loader",
            options: {
              remarkOptions: {
                plugins: [examplePluginUsingData],
                data: {
                  alpha: "bravo",
                  charlie: "delta",
                },
              },
            },
          },
        ],
      },
    ],
  },
};

removeFrontMatter

Remove removeFrontMatter

Type:

type removeFrontMatter = boolean;

Default: true

By default, the frontMatter is removed. To override this behavior, set removeFrontMatter to false and add remark-frontmatter to plugins.

webpack.config.js

import RemarkFrontmatter from "remark-frontmatter";

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "remark-loader",
            options: {
              removeFrontMatter: false,
              remarkOptions: {
                plugins: [RemarkFrontmatter],
              },
            },
          },
        ],
      },
    ],
  },
};

Inspiration

This project was inspired the following open source work:

Examples

Markdown to HTML

To get html, need to add remark-html to the remark plugins and add html-loader to the webpack.config

import md from "markdown-file.md";
console.log(md);

webpack.config.js

import RemarkHTML from "remark-html";

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "html-loader",
          },
          {
            loader: "remark-loader",
            options: {
              remarkOptions: {
                plugins: [RemarkHTML],
              },
            },
          },
        ],
      },
    ],
  },
};

Markdown to Markdown

index.js

import md from "markdown-file.md";
console.log(md);

webpack.config.js

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "remark-loader",
          },
        ],
      },
    ],
  },
};

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

6.0.0 (2024-01-18)

⚠ BREAKING CHANGES

  • minimum supported Node.js version is 18.12.0 (#114) (1d613db)

5.0.0 (2022-06-02)

⚠ BREAKING CHANGES

  • minimum supported Node.js version is 14.15.0 (#65)
  • minimum supported remark version is 14.0.0

Features

  • output links and descriptions on errors (#44) (482647b)

4.0.0 (2021-05-18)

⚠ BREAKING CHANGES

  • minimum supported Node.js version is 12.13.0

3.0.0 (2021-02-01)

⚠ BREAKING CHANGES

  • minimum supported webpack version is 5

2.0.0 (2020-11-24)

⚠ BREAKING CHANGES

  • remark is now in peer dependencies , so you need to install remark itself, please read remark changelog before updating remark, there are a lot of breaking changes

Features

  • allow to use remark@12 and remark@13 (other versions is not tested, but it may work too)

1.0.1 (2020-10-09)

Chore

  • update schema-utils

1.0.0 (2020-08-06)

⚠ BREAKING CHANGES

  • minimum required Node.js version is 10.13.0
  • minimum required webpack version is 4
  • loader doesn't return HTML, you need to use html-loader, please look at this example
  • update remark to 12.0.0 version, some plugins can be incompatible, please update them

Features

  • added remarkOptions option, you can specify plugins, settings and data
  • added removeFrontMatter option (#19) (3550105)
  • validate options by default (c6b6ed2)

Bug Fixes

  • improved performance

1.0.0-rc.0 (2019-06-10)

Chores

  • remove react specific code (f4e64c4), closes #1

BREAKING CHANGES

  • The react option has been removed. Our implementation was extremely hacky and led to a bunch of pitfalls. Please use MDX as an alternative.

0.3.2 (2018-02-06)

Bug Fixes

  • react: make <br> tags self-closing (8c1f754)

0.3.1 (2018-01-24)

Bug Fixes

  • allow specified template to receive any higher-level props (b365efa)
  • use ES6 module syntax for the output modules (d550fa4)

0.3.0 (2017-08-10)

Features

  • allow users to pass plugins (0f125c0)
  • react: provide YAML attributes to templates (8072585)

0.2.3 (2017-08-08)

Bug Fixes

  • react: fix syntax error in build script (cb951f6)

0.2.2 (2017-08-08)

Bug Fixes

  • react: fix missing newline and bracket usage in code blocks (4f05570)

0.2.1 (2017-08-04)

Bug Fixes

  • deps: update dependencies in package.json (c42c645)

0.2.0 (2017-08-04)

Features

  • resolve local resources using the html-loader (77ac7b2)
  • switch to remark parser allowing plugins and output options to be passed (d8fbcef)
  • react: re-integrate the react build script (35cd6f7)

0.1.0 (2017-08-01)

Port and refactor the repository from react-markdown-loader. Still working on the switching over to remark over remarkable.