Skip to content

Allow custom options to be passed to default Markdown processors #202

Closed

Description

@causztic

From here: contentlayerdev/website#43

Context

Some platforms like Github allows raw HTML tags to be used in Markdown. This can be useful if creators want to include raw HTML from trusted sources, or want to introduce extra layout and semantic flexibilities that would be hard to implement with only Markdown tags / require extra post-processing.

Current Situation

ContentLayer's Markdown processing middleware currently does not provide this possibility.

For this to work in ContentLayer, remark-rehype requires an additional option of { allowDangerousHtml: true } , which allows the processor to pass the nodes as-is, so that it can be parsed again either by rehype-raw or rehype-stringify.

Proposal

To allow for this to happen, we can allow options specified in contentlayer.config.js (maybe something like
remarkRehypeOptions for remark-rehype, as an example) to be passed into the respective default processors. Since this is optional, users will have to be aware of its security implications (if any) and enable them consciously.

Activity

  1. added this to the 0.2.5 milestone on May 10, 2022
  2. schickling commented on May 10, 2022

    @schickling
    Collaborator

    Thanks a lot for opening this issue. This case will be addressed by the upcoming 0.2.5 release which will support the following pattern:

    import rehypeStringify from 'rehype-stringify'
    import remarkFrontmatter from 'remark-frontmatter'
    import remarkParse from 'remark-parse'
    import remark2rehype from 'remark-rehype'
     
    makeSource({
      // your other options ...
      markdown: (builder) => {
        builder
          .use(remarkFrontmatter)
          .use(remarkParse)
          .use(remark2rehype, { allowDangerousHtml: true })
          .use(rehypeStringify)
      }
    })
  3. schickling commented on May 11, 2022

    @schickling
    Collaborator

    This should be addressed with the 0.2.5 release. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions