Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
causztic opened this issue Apr 30, 2022 · 2 comments
Closed

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

causztic opened this issue Apr 30, 2022 · 2 comments

Comments

@causztic
Copy link

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.

@schickling
Copy link
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)
  }
})

@schickling
Copy link
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
Projects
None yet
Development

No branches or pull requests

2 participants