readmeio / markdown

ReadMe's flavored Markdown parser and React-based rendering engine.
https://rdmd.readme.io
ISC License
33 stars 9 forks source link

feat: remark plugins #939

Closed kellyjosephprice closed 1 month ago

kellyjosephprice commented 1 month ago
PR App RM-9815

🧰 Changes

Adds an option for remark plugins.

By adding the remarkPlugins option, I can write a small plugin to support indexing in the main app. We recently decided we're going to refocus this repo to only deal with converting MDX to React. Recently, we've been adding a lot of code that is specific only to our editor, and we'd like to move that someplace.

The problem I'm trying to solve is for indexing. When converting mdast to hast, in MDX, we lose some information. remark-rehype doesn't know what to do with mdxJsxFlowElements and replaces them with div's.

mdx

<h2>Hello, world!</h2>

mdast

{
  "type": "root",
  "children": [
    {
      "type": "mdxJsxFlowElement",
      "name": "h2",
      "children": [
        {
          "type": "text",
          "value": "Hello, world!"
        }
      ]
    }
  ]
}

hast

{
  "type": "root",
  "children": [
    {
      "type": "element",
      "tagName": "div",
      "children": [
        {
          "type": "element",
          "tagName": "p",
          "children": [
            {
              "type": "text",
              "value": "Hello, world!"
            }
          ]
        }
      ]
    }
  ]
}



🧬 QA & Testing

rafegoldberg commented 1 month ago

This PR was released!

🚀 Changes included in v6.75.0-beta.72