Socket
Socket
Sign inDemoInstall

rehype-highlight

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-highlight - npm Package Compare versions

Comparing version 5.0.2 to 6.0.0

8

lib/index.d.ts

@@ -26,6 +26,10 @@ /// <reference types="highlight.js" />

/**
* Whether to detect the programming language on code without a language
* class.
*/
detect?: boolean | undefined
/**
* Scope of languages to check when auto-detecting (default: all languages).
* Pass `false` to not highlight code without language classes.
*/
subset?: boolean | string[] | undefined
subset?: string[] | undefined
/**

@@ -32,0 +36,0 @@ * Swallow errors for missing languages.

@@ -12,5 +12,7 @@ /**

* Prefix to use before classes.
* @property {boolean|Array<string>} [subset]
* @property {boolean} [detect=false]
* Whether to detect the programming language on code without a language
* class.
* @property {Array<string>} [subset]
* Scope of languages to check when auto-detecting (default: all languages).
* Pass `false` to not highlight code without language classes.
* @property {boolean} [ignoreMissing=false]

@@ -45,3 +47,4 @@ * Swallow errors for missing languages.

export default function rehypeHighlight(options = {}) {
const {aliases, languages, prefix, plainText, ignoreMissing, subset} = options
const {aliases, languages, prefix, plainText, ignoreMissing, subset, detect} =
options
let name = 'hljs'

@@ -69,3 +72,3 @@

return (tree) => {
return (tree, file) => {
// eslint-disable-next-line complexity

@@ -89,3 +92,3 @@ visit(tree, 'element', (node, _, givenParent) => {

lang === false ||
(!lang && subset === false) ||
(!lang && !detect) ||
(lang && plainText && plainText.includes(lang))

@@ -110,8 +113,7 @@ ) {

? lowlight.highlight(lang, toText(parent), {prefix})
: // @ts-expect-error: we checked that `subset` is not a boolean.
lowlight.highlightAuto(toText(parent), {prefix, subset})
: lowlight.highlightAuto(toText(parent), {prefix, subset})
} catch (error) {
const exception = /** @type {Error} */ (error)
if (!ignoreMissing || !/Unknown language/.test(exception.message)) {
throw error
file.fail(exception, node, 'rehype-highlight:missing-language')
}

@@ -118,0 +120,0 @@

{
"name": "rehype-highlight",
"version": "5.0.2",
"version": "6.0.0",
"description": "rehype plugin to highlight code blocks with lowlight (highlight.js)",

@@ -48,3 +48,3 @@ "license": "MIT",

"rehype": "12.0.0",
"remark-cli": "^10.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",

@@ -54,4 +54,4 @@ "rimraf": "^3.0.0",

"type-coverage": "^2.0.0",
"typescript": "~4.4.0",
"xo": "^0.47.0"
"typescript": "^4.0.0",
"xo": "^0.52.0"
},

@@ -58,0 +58,0 @@ "scripts": {

@@ -48,6 +48,7 @@ # rehype-highlight

`css`, etc.
By default, even without a class, all `<pre><code>` is highlighted by
automatically detecting which code language it seems to be.
You can prevent that with a `no-highlight` or `nohighlight` class on the
`<code>` or by passing `options.subset: false`.
By default, code without such a language class is not highlighted.
Pass `detect: true` to detect their programming language and highlight the code
anyway.
You can still prevent specific blocks from being highlighted with a
`no-highlight` or `nohighlight` class on the `<code>`.

@@ -85,13 +86,13 @@ **unified** is a project that transforms content with abstract syntax trees

In Deno with [Skypack][]:
In Deno with [`esm.sh`][esmsh]:
```js
import rehypeHighlight from 'https://cdn.skypack.dev/rehype-highlight@5?dts'
import rehypeHighlight from 'https://esm.sh/rehype-highlight@5'
```
In browsers with [Skypack][]:
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import rehypeHighlight from 'https://cdn.skypack.dev/rehype-highlight@5?min'
import rehypeHighlight from 'https://esm.sh/rehype-highlight@5?bundle'
</script>

@@ -118,12 +119,8 @@ ```

main()
const file = await rehype()
.data('settings', {fragment: true})
.use(rehypeHighlight)
.process(await read('example.html'))
async function main() {
const file = await rehype()
.data('settings', {fragment: true})
.use(rehypeHighlight)
.process(await read('example.html'))
console.log(String(file))
}
console.log(String(file))
```

@@ -157,7 +154,11 @@

###### `options.detect`
Whether to detect the programming language on code without a language class
(`boolean`, default: `false`).
###### `options.subset`
Scope of languages to check when automatically detecting (`boolean` or
`Array<string>`, default: all languages).
Pass `false` to not highlight code without language classes.
Languages to check when automatically detecting (`Array<string>`, default: all
languages).

@@ -460,3 +461,3 @@ ###### `options.plainText`

[skypack]: https://www.skypack.dev
[esmsh]: https://esm.sh

@@ -463,0 +464,0 @@ [health]: https://github.com/rehypejs/.github

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