13

I'm a bit confused. I think remark is a markdown processor, rehype is an html processor. So remark takes some markdown, transforms it, and gives me back some markdown. Rehype takes some html, transforms it, and gives me back some html - is this correct?

For example: I came across the packages remark-slug and rehype-slug, and they appear to do basically the same thing—what is the difference between the two?

Jacob Ford
  • 4,553
  • 5
  • 27
  • 42
antonwilhelm
  • 5,768
  • 4
  • 19
  • 45
  • 1
    for reference, I found these articles helpful: 1. [An Introduction to Unified and Remark](https://braincoke.fr/blog/2020/03/an-introduction-to-unified-and-remark), 2. [Transforming Markdown with Remark & Rehype](https://www.ryanfiller.com/blog/remark-and-rehype-plugins), 3. [How to debug unified, rehype, or remark and fix bugs in markdown processing](https://swizec.com/blog/how-to-debug-unified-rehype-or-remark-and-fix-bugs-in-markdown-processing-2) – Gangula Jan 19 '22 at 17:49

1 Answers1

10

Not quite right. remark and rehype are Node.js-based processors in the unified collective. They support parsing markdown and HTML respectively to/from syntax trees. All such processors in the unified collective support 'plugins' that enable you to inspect and manipulate the intermediary syntax trees. Powerful stuff.

remark-slug and rehype-slug are third-party plugins for their respective unified collective processors, remark and rehype. From the slugs' descriptions I gather these plugins are used to turn "headings" into navigable items (Anchors/Bookmarks).

You decide what to use based on your input and output formats and what, if any, inspection or transformation you want to accomplish. You may use some or all of them.

ScottWelker
  • 1,701
  • 17
  • 30
  • 1
    "You may use some or all of them..." or, create your own plug-in(s). – ScottWelker Dec 27 '21 at 19:09
  • 2
    Here's another's take [Transforming Markdown with Remark & Rehype, When to use Each](https://www.ryanfiller.com/blog/remark-and-rehype-plugins#when-to-use-each) - Ryan Filler. – ScottWelker Jun 03 '22 at 23:04