Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rehype-prism

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-prism - npm Package Compare versions

Comparing version 2.1.3 to 2.2.0

.c8rc.json

1

build/tsconfig.test.json

@@ -12,2 +12,1 @@ {

}

@@ -6,2 +6,9 @@ # Change Log

<a name="0.1.1"></a>
## [2.2.0](https://www.github.com/Val-istar-Guo/rehype-prism/compare/v2.1.3...v2.2.0) (2023-01-12)
### Features
* build-in line-numbers module ([09b49fb](https://www.github.com/Val-istar-Guo/rehype-prism/commit/09b49fbb8ff73ace2f3d56abf8ced2548e6dc9f5))
### [2.1.3](https://www.github.com/Val-istar-Guo/rehype-prism/compare/v2.1.2...v2.1.3) (2022-06-26)

@@ -8,0 +15,0 @@

@@ -0,6 +1,6 @@

import 'prismjs';
import unifiedTypes from 'unified';
export interface RehypePrismOptions {
plugins: ('autolinker' | 'autoloader' | 'command-line' | 'copy-to-clipboard' | 'custom-class' | 'data-uri-highlight' | 'diff-highlight' | 'download-button' | 'file-highlight' | 'filter-highlight-all' | 'highlight-keywords' | 'inline-color' | 'jsonp-highlight' | 'keep-markup' | 'line-highlight' | 'line-numbers' | 'match-braces' | 'normalize-whitespace' | 'previewers' | 'remove-initial-line-feed' | 'show-invisibles' | 'show-language' | 'toolbar' | 'treeview' | 'unescaped-markup' | 'wpd')[];
}
declare const rehypePrism: unifiedTypes.Plugin<[RehypePrismOptions?]>;
import { Element } from 'hast';
import { RehypePrismOptions } from './rehype-prism-options.js';
declare const rehypePrism: unifiedTypes.Plugin<[RehypePrismOptions?], Element>;
export default rehypePrism;

@@ -1,48 +0,14 @@

import Prism from 'prismjs';
import parse from 'rehype-parse';
import { unified } from 'unified';
import 'prismjs';
import { visit } from 'unist-util-visit';
import { select } from 'unist-util-select';
const getLang = (node) => {
var _a, _b;
const lang = ((_b = (_a = node.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b[0]) || '';
return lang.replace(/^language-/, '');
};
const visitor = (preNode) => {
const codeNode = select('[tagName=code]', preNode);
if (!codeNode)
return;
const lang = getLang(codeNode);
if (!lang || !Prism.languages[lang])
return;
const textNode = select('text', codeNode);
if (!textNode)
return;
const className = `language-${lang}`;
const html = Prism.highlight(textNode.value, Prism.languages[lang], lang);
const tree = unified()
.use(parse, { fragment: true })
.parse(html);
if (!preNode.properties)
preNode.properties = {};
if (!preNode.properties.className)
preNode.properties.className = [];
if (typeof preNode.properties.className === 'string')
preNode.properties.className = [preNode.properties.className];
if (typeof preNode.properties.className === 'number')
preNode.properties.className = [preNode.properties.className];
if (typeof preNode.properties.className === 'boolean')
preNode.properties.className = [];
preNode.properties.className = [...preNode.properties.className, className];
codeNode.children = tree.children;
};
const selector = (node) => node.tagName === 'pre';
import { preElementSelector } from './pre-element-selector.js';
import { parseCodeVisitor } from './parse-code-vistor.js';
const rehypePrism = (options) => {
if (options && options.plugins) {
for (const plugin of options.plugins) {
const plugins = options.plugins.filter(plugin => plugin !== 'line-numbers');
for (const plugin of plugins) {
import(`prismjs/plugins/${plugin}/prism-${plugin}.js`);
}
}
return (tree) => visit(tree, selector, visitor);
return tree => visit(tree, preElementSelector(), parseCodeVisitor(options));
};
export default rehypePrism;

@@ -7,3 +7,10 @@ {

"scripts": {
"test": "npm run build:test && c8 ava",
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" --fix",
"prepare": "is-ci || husky install",
"ca": "git add -A && git-cz -av",
"ci": "git-cz",
"release": "standard-version",
"release:alpha": "standard-version --prerelease alpha",
"release:first": "standard-version --first-release",
"test": "npm run clean && npm run build:test && c8 ava",
"test:debug": "ava --verbose",

@@ -13,19 +20,13 @@ "test:update": "ava -u",

"coveralls": "c8 report --reporter=text-lcov | coveralls",
"ci": "git-cz",
"ca": "git add -A && git-cz -av",
"release": "standard-version",
"release:alpha": "standard-version --prerelease alpha",
"release:first": "standard-version --first-release",
"prepublishOnly": "npm run build",
"clean": "rm -rf ./lib/*",
"clean": "rm -rf ./lib/* && rm -rf ./es/*",
"prebuild": "npm run clean",
"build": "ttsc && npm run copyfile",
"build:test": "ttsc -p build/tsconfig.test.json && npm run copyfile",
"copyfile": "copyfiles -u 1 \"src/**/*.!(ts)\" lib/src",
"build": "npm run clean && ttsc && npm run copyfile",
"build:test": "npm run clean && ttsc -p build/tsconfig.test.json && npm run copyfile",
"prewatch": "npm run copyfile",
"watch": "NODE_ENV=development ttsc -w",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" --fix",
"prepare": "is-ci || husky install"
"watch": "NODE_ENV=development ttsc -w"
},
"description": "The unified plugin used to highlight code block in html with Prism",
"version": "2.1.3",
"version": "2.2.0",
"directories": {

@@ -62,4 +63,4 @@ "test": "tests"

"@ava/typescript": "^3.0.1",
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@typescript-eslint/eslint-plugin": "^4.15.2",

@@ -69,3 +70,3 @@ "@typescript-eslint/parser": "^4.15.2",

"ava": "^4.3.0",
"c8": "^7.11.3",
"c8": "^7.12.0",
"commitizen": "^4.2.4",

@@ -76,6 +77,6 @@ "copyfiles": "^2.4.1",

"eslint": "^7.20.0",
"husky": "7",
"husky": "^5.2.0",
"is-ci": "^3.0.0",
"lint-staged": "^13.0.2",
"mili": "^4.7.4",
"lint-staged": "^11.0.0",
"mili": "^4.7.5",
"rehype-stringify": "^8.0.0",

@@ -87,4 +88,4 @@ "remark-parse": "^9.0.0",

"ts-node": "^10.8.1",
"ttypescript": "^1.5.12",
"typescript": "^4.2.2",
"ttypescript": "^1.5.13",
"typescript": "^4.7.4",
"typescript-transform-paths": "^3.3.1",

@@ -99,7 +100,8 @@ "unified": "^10.1.2"

"@types/unist": "*",
"hastscript": "^7.2.0",
"prismjs": "^1.24.1",
"rehype-parse": "^7 || ^ 8",
"unist-util-is": "^4 || ^5",
"unist-util-select": "^4",
"unist-util-visit": "^3 || ^4"
"unist-util-select": "^4.0.2",
"unist-util-visit": "^4.1.1"
},

@@ -106,0 +108,0 @@ "peerDependencies": {

@@ -12,7 +12,5 @@ <!-- title -->

[![license](https://img.shields.io/npm/l/rehype-prism.svg?style=flat-square)](https://www.npmjs.com/package/rehype-prism)
[![dependencies](https://img.shields.io/librariesio/release/npm/rehype-prism?style=flat-square)](https://www.npmjs.com/package/rehype-prism)
[![dependencies](https://img.shields.io/librariesio/github/Val-istar-Guo/rehype-prism.svg?style=flat-square)](https://www.npmjs.com/package/rehype-prism)
[![coveralls](https://img.shields.io/coveralls/github/Val-istar-Guo/rehype-prism.svg?style=flat-square)](https://coveralls.io/github/Val-istar-Guo/rehype-prism)
<!-- description -->

@@ -27,3 +25,2 @@ The unified plugin used to highlight code block in html with Prism.

```typescript

@@ -49,2 +46,3 @@ import { unified } from 'unified'

.parse(/* markstring string */)
// .processSync(/* markdown string */)

@@ -56,2 +54,3 @@ // parse code block in html string

.parse(/* html string */)
// .processSync(/* html string */)
```

@@ -70,3 +69,3 @@

> Some plugins will not work(e.g. `line-number`). Because it's only work in browser.
> Some plugins will not work. Because it's only work in browser.

@@ -94,3 +93,2 @@ ## Load Plugins

## Contributing & Development

@@ -97,0 +95,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc