Gathering detailed insights and metrics for mdx-prism-2
Gathering detailed insights and metrics for mdx-prism-2
Gathering detailed insights and metrics for mdx-prism-2
Gathering detailed insights and metrics for mdx-prism-2
npm install mdx-prism-2
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1 Stars
50 Commits
2 Watching
2 Branches
1 Contributors
Updated on 07 Mar 2023
TypeScript (90.82%)
JavaScript (7.45%)
Shell (1.74%)
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-87.3%
7
Compared to previous week
Last month
229.4%
112
Compared to previous month
Last year
-29%
908
Compared to previous year
9
⚠️ This is Fork from
mdx-prism
which automate the release process. There are a few fixes that does not have a published version there.Maybe in the future I can delete this repository in favor of having a single but for now I need things a bit more professional.
This is a fork of @mapbox/rehype-prism that adds line highlighting capabilities, e.g.:
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.
1npm install mdx-prism-2
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.
Parameter | Type | Default | Description |
---|---|---|---|
ignoreMissing | boolean | 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 . |
lineHighlight.component | string (HTML element) | div | The HTML tag used to wrap the highlight line. |
lineHighlight.className | string | mdx-marker | CSS class applied to highlight line. |
Use this package as a rehype plugin.
Some examples of how you might do that:
1const rehype = require('rehype'); 2const mdxPrism = require('mdx-prism-2'); 3 4rehype().use(mdxPrism).process(/* some html */);
1const rehype = require('rehype'); 2const mdxPrism = require('mdx-prism-2'); 3 4rehype() 5 .use(mdxPrism, { 6 lineHighlight: { 7 component: 'span', 8 className: 'my-line-highlight-class', 9 }, 10 }) 11 .process(/* some html */);
1const unified = require('unified'); 2const rehypeParse = require('rehype-parse'); 3const mdxPrism = require('mdx-prism-2'); 4 5unified().use(rehypeParse).use(mdxPrism).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 mdxPrism = require('mdx-prism-2'); 5 6unified() 7 .use(remarkParse) 8 .use(remarkRehype) 9 .use(mdxPrism) 10 .process(/* some markdown */);
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 2 class="language-css" 3><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 mdx-prism-2 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
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
13 existing vulnerabilities detected
Details
Score
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 Morerehype-prism-plus
rehype plugin to highlight code blocks in HTML with Prism (via refractor) with line highlighting and line numbers
prismjs
Lightweight, robust, elegant syntax highlighting. A spin-off project from Dabblet.
prism-react-renderer
Renders highlighted Prism output using React
@mdx-js/react
React context for MDX