Installations
npm install mdx-prism
Releases
Unable to fetch releases
Contributors
Developer
mapbox
Developer Guide
Module System
CommonJS
Min. Node Version
>=6
Typescript Support
No
Node Version
14.16.0
NPM Version
7.20.0
Statistics
179 Stars
41 Commits
24 Forks
101 Watching
1 Branches
538 Contributors
Updated on 09 Nov 2024
Languages
JavaScript (98.25%)
Shell (1.75%)
Total Downloads
Cumulative downloads
Total Downloads
364,734
Last day
-36.1%
147
Compared to previous day
Last week
-1.7%
1,164
Compared to previous week
Last month
13.3%
4,442
Compared to previous month
Last year
-9.7%
69,928
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Note: This repository is no longer maintained
As of April 2024, this repo is no longer being used by the Mapbox docs team.
@mapbox/rehype-prism
rehype plugin to highlight code blocks in HTML with Prism (via refractor).
(If you would like to highlight code blocks with highlight.js, instead, check out rehype-highlight.)
Best suited for usage in Node. If you would like to perform syntax highlighting in the browser, you should look into less heavy ways to use refractor.
Installation
npm install @mapbox/rehype-prism
API
rehype().use(rehypePrism, [options])
Syntax highlights pre > code
.
Under the hood, it uses refractor, which is a virtual version of Prism.
The code language is configured by setting a language-{name}
class on the <code>
element.
You can use any language supported by refractor.
If no language-{name}
class is found on a <code>
element, it will be skipped.
options
options.ignoreMissing
Type: boolean
.
Default: false
.
By default, if {name}
does not correspond to a language supported by refractor an error will be thrown.
If you would like to silently skip <code>
elements with invalid languages, set this option to true
.
options.alias
Type: Record<string, string | string[]>
.
Default: undefined
.
Provide aliases to refractor to register as alternative names for a language.
Usage
Use this package as a rehype plugin.
Some examples of how you might do that:
1const rehype = require('rehype'); 2const rehypePrism = require('@mapbox/rehype-prism'); 3 4rehype() 5 .use(rehypePrism) 6 .process(/* some html */);
1const unified = require('unified'); 2const rehypeParse = require('rehype-parse'); 3const rehypePrism = require('@mapbox/rehype-prism'); 4 5unified() 6 .use(rehypeParse) 7 .use(rehypePrism) 8 .processSync(/* some html */);
If you'd like to get syntax highlighting in Markdown, parse the Markdown (with remark-parse), convert it to rehype, then use this plugin.
1const unified = require('unified'); 2const remarkParse = require('remark-parse'); 3const remarkRehype = require('remark-rehype'); 4const rehypePrism = require('@mapbox/rehype-prism'); 5 6unified() 7 .use(remarkParse) 8 .use(remarkRehype) 9 .use(rehypePrism) 10 .process(/* some markdown */);
FAQ
Why does rehype-prism copy the language-
class to the <pre>
tag?
Prism recommends adding the language-
class to the <code>
tag like this:
1<pre><code class="language-css">p { color: red }</code></pre>
It bases this recommendation on the HTML5 spec. However, an undocumented behavior of their JavaScript is that, in the process of highlighting the code, they also copy the language-
class to the <pre>
tag:
1<pre class="language-css"><code class="language-css"><span class="token selector">p</span> <span class="token punctuation">{</span> <span class="token property">color</span><span class="token punctuation">:</span> red <span class="token punctuation">}</span></code></pre>
This resulted in many Prism themes relying on this behavior by using CSS selectors like pre[class*="language-"]
. So in order for people using rehype-prism to get the most out of these themes, we decided to do the same.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/mapbox/.github/SECURITY.md:1
- Info: Found linked content: github.com/mapbox/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/mapbox/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/mapbox/.github/SECURITY.md:1
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
Reason
Found 3/19 approved changesets -- score normalized to 1
Reason
SAST tool is not run on all commits -- score normalized to 1
Details
- Warn: 2 commits out of 17 are checked with a SAST tool
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
3.7
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to mdx-prism
mdx-prism-2
A fork from mdx-prism plugin to highlight code blocks in HTML with Prism and more
rehype-prism-plus
rehype plugin to highlight code blocks in HTML with Prism (via refractor) with line highlighting and line numbers
rehype-prism-enhanced
A fork of the rehype-prism & mdx-prism plugins to highlight code blocks in HTML with Prism and more
prismjs
Lightweight, robust, elegant syntax highlighting. A spin-off project from Dabblet.