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

Passing raw HTML tags through the markdown processor #43

Open
seancdavis opened this issue Apr 22, 2022 · 3 comments
Open

Passing raw HTML tags through the markdown processor #43

seancdavis opened this issue Apr 22, 2022 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@seancdavis
Copy link
Contributor

seancdavis commented Apr 22, 2022

Comments from Discord:

[Graf] I have several raw HTML tags in my Markdown (.md) files. How do I return them as-is to be shown when I call post.html? They are currently removed from it

[schickling] I think there's some rehype/remark plugin that can do this.

[Graf] I attempted to use rehype-raw but no dice.. ended up just using the mdx format instead to preserve the tags

Let's solve this and then add the solution to the docs.

@seancdavis seancdavis added the documentation Improvements or additions to documentation label Apr 22, 2022
@causztic
Copy link

causztic commented Apr 22, 2022

👋

https://github.com/remarkjs/remark-rehype#when-should-i-use-this

From this readme, it looks like I'll have to include { allowDangerousHtml: true } as options to remark-rehype, so that rehype-raw can re-parse it and include it into the HAST. Alternatively, I can also pass { allowDangerousHtml: true } to rehype-stringify, but that is limited

I tested this locally by overriding the default remark-rehype in contentlayer's markdown.ts, with

builder.use(remark2rehype, { allowDangerousHtml: true })

Afterwards, I was able to have my raw HTML in Markdown pass through after adding rehypeRaw to rehypePlugins

From this little adventure, I have two questions:

  • Can we have custom options passed in to the default processors used? I can help with this
  • How do we pass in custom options to the plugins? It would be nice for the documentation to be filled with this information too!
  • I managed to figure out how to pass in custom options to plugins with this format:
rehypePlugins: [rehypePrism, [rehypeExternalLinks, {target: "_blank", rel: ['nofollow']}]]

It would be nice to have this in the documentation as well :)

@seancdavis
Copy link
Contributor Author

@causztic Thanks for all this info! I'll look into the documentation piece next week.

Regarding this:

Can we have custom options passed in to the default processors used?

Likely not possible right now with Contentlayer, but could be a useful feature. Would you mind creating an issue in that project?

@causztic
Copy link

causztic commented May 11, 2022

Just an update for posterity - this feature should be made available in 0.2.5 once ContentLayer allows passing in of a custom builder pipeline 🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants