1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Introduction to the remark CLI

    John OtanderJohn Otander
    javascriptJavaScript

    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
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    John Otander: 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.

    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.

    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.

    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.

    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.