-
-
Notifications
You must be signed in to change notification settings - Fork 848
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
Better documentation and support for code syntax hightlighting #191
Comments
It's actually pretty easy to enable code highlighting, you just need to pass a custom renderer for code blocks to ReactMarkdown. I found the easiest way to figure out how to do that was to look at the source for how the existing renderers were written: https://github.com/rexxars/react-markdown/blob/master/src/renderers.js . I am not sure if those examples in the other issues are fully up to date (since they predate version 3.0), but I'll throw mine into the pile because I'm actually using https://gist.github.com/ibrahima/d21950a95aee3212e991a8404e238093 (I've extracted this snippet from a bigger codebase with more customization so apologies if it doesn't work right away.) |
Build-In support is not that necessary. The solution @ibrahima provided is awesome. |
@ibrahima I'm confused - does your code work with triple-backtick syntax? How do you tell react-markdown what language's syntax to use? Does anyone know of a solution that uses GitHub's custom syntax for specifying languages? e.g.: const x: string = "asdf"; |
Yes it does. The markdown parser already handles that. My snippet just gives a way to render code blocks with syntax highlighting. |
Did that example ever get added to the docs? |
This should be significantly easier when #428 lands, by adding either https://github.com/mapbox/rehype-prism, https://github.com/rsclarke/rehype-shiki, or https://github.com/rehypejs/rehype-highlight. I’ll rename this issue to ensure we add an example somewhere in the readme edit: title is perfect 😅 |
* Lowercase filenames to scream less * Add `remark-cli`, `remark-preset-wooorm` to format prose * Use imports and fancy new JS features * Add link to a markdown cheatsheet, as many questions are about that * Add details tags showing equivalent JSX for examples, to clarify how markdown works * Refactor options list, clean signatures * Add examples on plugins, plugins w/ options, renderers (syntax highlighting), and combining plugins w/ renderers (math) * Add sections on why to use this, security, contributing, related projects * Add test for `react-katex` integration Closes GH-70. Closes GH-191. Related to GH-474. Closes GH-479. Closes GH-480. Related to GH-483.
* Lowercase filenames to scream less * Add `remark-cli`, `remark-preset-wooorm` to format prose * Use imports and fancy new JS features * Add link to a markdown cheatsheet, as many questions are about that * Add details tags showing equivalent JSX for examples, to clarify how markdown works * Refactor options list, clean signatures * Add examples on plugins, plugins w/ options, renderers (syntax highlighting), and combining plugins w/ renderers (math) * Add sections on why to use this, security, contributing, related projects * Add test for `react-katex` integration Closes GH-70. Closes GH-191. Related to GH-474. Closes GH-479. Closes GH-480. Related to GH-483.
This is now documented in the readme |
I think these code hightlighting issues keep popping up because it's not at all obvious how we're supposed to turn code highlighting on without digging into the code examples.
Take a look at how react-syntax-hightlighter deals with this issue:
In my opinion, something like this would be really cool:
If we can already do something like this, it would be really cool to make it easy to find in the documentation.
The text was updated successfully, but these errors were encountered: