Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
rehype-prism
Advanced tools
The unified plugin used to highlight code block in html with Prism.
This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.
import unified from 'unified'
import rehyper from 'rehyper'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypePrism from 'rehype-prism'
import rehypeStringify from 'rehype-stringify'
// you have to load css manual
import 'prismjs/themes/prism-coy.css'
import 'prismjs/plugins/line-numbers/prism-line-numbers.css'
// parse markdown to html
unified()
.use(markdown)
.use(remark2rehype)
// it should be after rehype
.use(rehypePrism, { plugins: ['line-numbers'] })
.use(html)
.parse(/* markstring string */)
// parse code block in html string
rehyper()
.use(rehypePrism)
.use(html)
.parse(/* html string */)
PrismJS
will auto highlight all code at pre code
after browser document
loaded.
Disabled prism autoHighlight before import 'rehype-prism'
. there are two way to do this:
set the window.Prism = { manual: true }
use the attribute data-manual
on the <script>
element you used for prism.
<script src="prism.js" data-manual></script>
Some plugins will not work(e.g.
line-number
). Because it's only work in browser.
The names to use can be found here.
loadLanguages()
provided by prismjs
.(don't use loadLanguages()
with Webpack or another bundler)import 'prismjs'
will auto load the theme setted in babel-plugin-prismjs config.import 'prismjs/themes/prism-coy.css'
If there is any doubt, it is very welcome to discuss the issue together. Please read Contributor Covenant Code of Conduct and CONTRIBUTING.
FAQs
The unified plugin used to highlight code block in html with Prism
The npm package rehype-prism receives a total of 3,339 weekly downloads. As such, rehype-prism popularity was classified as popular.
We found that rehype-prism demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.