rehype-prism
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -6,2 +6,9 @@ # Change Log | ||
<a name="0.1.1"></a> | ||
### [2.2.1](https://www.github.com/Val-istar-Guo/rehype-prism/compare/v2.2.0...v2.2.1) (2023-03-29) | ||
### Bug Fixes | ||
* toolbar and copy-to-clipboard plugin not work ([30356e7](https://www.github.com/Val-istar-Guo/rehype-prism/commit/30356e70c68ea79ac3563abe489b6b5dd4c912fc)), closes [#20](https://www.github.com/Val-istar-Guo/rehype-prism/issues/20) | ||
## [2.2.0](https://www.github.com/Val-istar-Guo/rehype-prism/compare/v2.1.3...v2.2.0) (2023-01-12) | ||
@@ -8,0 +15,0 @@ |
import 'prismjs'; | ||
import unifiedTypes from 'unified'; | ||
import { Element } from 'hast'; | ||
import { RehypePrismOptions } from './rehype-prism-options.js'; | ||
import { RehypePrismOptions } from './interface/rehype-prism-options.js'; | ||
declare const rehypePrism: unifiedTypes.Plugin<[RehypePrismOptions?], Element>; | ||
export default rehypePrism; |
import 'prismjs'; | ||
import { visit } from 'unist-util-visit'; | ||
import { preElementSelector } from './pre-element-selector.js'; | ||
import { parseCodeVisitor } from './parse-code-vistor.js'; | ||
import { createPreElementSelector } from './create-pre-element-selector.js'; | ||
import { createParseCodeVisitor } from './create-parse-code-vistor.js'; | ||
import { internalPlugins } from './constant.js'; | ||
const rehypePrism = (options) => { | ||
if (options && options.plugins) { | ||
const plugins = options.plugins.filter(plugin => plugin !== 'line-numbers'); | ||
const plugins = options.plugins | ||
.filter(plugin => !internalPlugins.includes(plugin)); | ||
for (const plugin of plugins) { | ||
@@ -12,4 +14,4 @@ import(`prismjs/plugins/${plugin}/prism-${plugin}.js`); | ||
} | ||
return tree => visit(tree, preElementSelector(), parseCodeVisitor(options)); | ||
return tree => visit(tree, createPreElementSelector(), createParseCodeVisitor(options)); | ||
}; | ||
export default rehypePrism; |
@@ -29,3 +29,3 @@ { | ||
"description": "The unified plugin used to highlight code block in html with Prism", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"directories": { | ||
@@ -32,0 +32,0 @@ "test": "tests" |
@@ -16,3 +16,5 @@ <!-- title --> | ||
<!-- description --> | ||
The unified plugin used to highlight code block in html with Prism. | ||
<!-- description --> | ||
@@ -23,2 +25,3 @@ | ||
<!-- usage --> | ||
This package is ESM only: Node 12+ and [unified 10](https://www.npmjs.com/package/unified) is needed to use it and it must be imported instead of required. | ||
@@ -38,2 +41,8 @@ | ||
// load languages manual | ||
// import 'prismjs/components/prism-{language}' | ||
import 'prismjs/components/prism-go' | ||
import 'prismjs/components/prism-java' | ||
import 'prismjs/components/prism-python' | ||
// parse markdown to html | ||
@@ -46,4 +55,4 @@ unified() | ||
.use(rehypeStringify) | ||
.parse(/* markstring string */) | ||
// .processSync(/* markdown string */) | ||
.parse(/* markdown string */) | ||
// .processSync(/* markdown string */) | ||
@@ -55,3 +64,3 @@ // parse code block in html string | ||
.parse(/* html string */) | ||
// .processSync(/* html string */) | ||
// .processSync(/* html string */) | ||
``` | ||
@@ -65,4 +74,4 @@ | ||
* set the `window.Prism = { manual: true }` | ||
* use the attribute `data-manual` on the `<script>` element you used for prism. | ||
- set the `window.Prism = { manual: true }` | ||
- use the attribute `data-manual` on the `<script>` element you used for prism. | ||
@@ -77,12 +86,27 @@ `<script src="prism.js" data-manual></script>` | ||
### Plugins Reimplemented By rehype-prism | ||
The table list plugins that cannot running on the server side. | ||
Therefor it has been re-implemented by rehype-prism. | ||
| Plugin Name | | ||
|:------------------| | ||
| line-numbers | | ||
| toolbar | | ||
| copy-to-clipboard | | ||
> I haven't tested all prism plugins. | ||
> If there are another plugins not work, | ||
> submit issue on github. | ||
## Load More Languages | ||
* Use [babel-plugin-prismjs](https://www.npmjs.com/package/babel-plugin-prismjs).(Recommend) | ||
* Use `loadLanguages()` provided by `prismjs`.(don't use `loadLanguages()` with Webpack or another bundler) | ||
- Use [babel-plugin-prismjs](https://www.npmjs.com/package/babel-plugin-prismjs).(Recommend) | ||
- Use `loadLanguages()` provided by `prismjs`.(don't use `loadLanguages()` with Webpack or another bundler) | ||
## Load Themes | ||
* If you use [babel-plugin-prismjs](https://www.npmjs.com/package/babel-plugin-prismjs). | ||
- If you use [babel-plugin-prismjs](https://www.npmjs.com/package/babel-plugin-prismjs). | ||
`import 'prismjs'` will auto load the theme setted in babel-plugin-prismjs config. | ||
* Import theme css manual. e.g. `import 'prismjs/themes/prism-coy.css'` | ||
- Import theme css manual. e.g. `import 'prismjs/themes/prism-coy.css'` | ||
@@ -92,3 +116,5 @@ <!-- usage --> | ||
<!-- addition --> | ||
If in doubt, please submit an issue. | ||
<!-- addition --> | ||
@@ -95,0 +121,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
51
118
1
31258
330