Introduction to the remark CLI

John Otander
InstructorJohn Otander
Share this video with your friends

Social Share Links

Send Tweet

You can use the remark CLI to inspect the AST, run plugins, or lint your markdown documents. It can be used in your build scripts to generate HTML or ensure your markdown style guide is adhered to.

  • Inspect the AST: remark document.md --inspect
  • Use a plugin: remark document.md --use toc
  • Overwrite your document after the plugin runs: remark document.md --use toc -o
  • Lint a document: remark document.md --frail --use preset-lint-markdown-style-guide

John Otander: [00:00] Remark comes with the command line interface, or CLI, that can be used to automate tasks. First, just go ahead and inspect the document. Inspect option logs out the entire AST, which can be used for debugging plugins.

[00:15] As we also see here, we have the "Table of contents" heading and no children beneath it. We can automatically populate this by using the remark toc plugin as part of the CLI command. Now the table of contents has been populated.

[00:29] However, if you run the inspect command one more time, we'll see that the table of contents has not been persisted. That's because we didn't specify the output.

[00:37] With the output options specified, we can now inspect one more time and see that it has been populated. In addition to plugins that manipulate your markdown, you can also use plugins for linting.

[00:48] Here, we'll lint against our markdown style guide. When we run the command, we'll see a list of errors that have been generated based off our preferences. We can additionally run commands based off whether the linting passed or failed. Though for this to work we'll have to specify the frail option, which means it will error out. This results in us seeing fail rather than pass.