Socket
Socket
Sign inDemoInstall

rehype-highlight

Package Overview
Dependencies
12
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0 to 4.0.1

59

index.js
'use strict'
var toText = require('hast-util-to-text')
var lowlight = require('lowlight')
var visit = require('unist-util-visit')
var lowlight = require('lowlight')
var toText = require('hast-util-to-text')

@@ -11,25 +11,19 @@ module.exports = attacher

var settings = options || {}
var detect = settings.subset !== false
var prefix = settings.prefix
var ignoreMissing = settings.ignoreMissing
var plainText = settings.plainText || []
var aliases = settings.aliases
var languages = settings.languages
var name = 'hljs'
var pos
if (aliases) {
lowlight.registerAlias(aliases)
if (settings.aliases) {
lowlight.registerAlias(settings.aliases)
}
if (languages) {
if (settings.languages) {
// eslint-disable-next-line guard-for-in
for (let name in languages) {
lowlight.registerLanguage(name, languages[name])
for (let name in settings.languages) {
lowlight.registerLanguage(name, settings.languages[name])
}
}
if (prefix) {
pos = prefix.indexOf('-')
name = pos === -1 ? prefix : prefix.slice(0, pos)
if (settings.prefix) {
pos = settings.prefix.indexOf('-')
name = pos > -1 ? settings.prefix.slice(0, pos) : settings.prefix
}

@@ -44,3 +38,3 @@

function visitor(node, index, parent) {
var props = node.properties
var props
var result

@@ -57,4 +51,4 @@ var lang

lang === false ||
(!lang && !detect) ||
plainText.indexOf(lang) !== -1
(!lang && settings.subset === false) ||
(settings.plainText && settings.plainText.indexOf(lang) > -1)
) {

@@ -64,2 +58,4 @@ return

props = node.properties
if (!props.className) {

@@ -69,3 +65,3 @@ props.className = []

if (props.className.indexOf(name) === -1) {
if (props.className.indexOf(name) < 0) {
props.className.unshift(name)

@@ -75,13 +71,11 @@ }

try {
if (lang) {
result = lowlight.highlight(lang, toText(parent), options)
} else {
result = lowlight.highlightAuto(toText(parent), options)
}
result = lang
? lowlight.highlight(lang, toText(parent), options)
: lowlight.highlightAuto(toText(parent), options)
} catch (error) {
if (error && ignoreMissing && /Unknown language/.test(error.message)) {
return
if (!settings.ignoreMissing || !/Unknown language/.test(error.message)) {
throw error
}
throw error
result = {}
}

@@ -93,3 +87,5 @@

node.children = result.value
if (result.value) {
node.children = result.value
}
}

@@ -101,7 +97,6 @@ }

var className = node.properties.className || []
var length = className.length
var index = -1
var value
while (++index < length) {
while (++index < className.length) {
value = className[index]

@@ -121,4 +116,2 @@

}
return null
}
{
"name": "rehype-highlight",
"version": "4.0.0",
"version": "4.0.1",
"description": "rehype plugin to highlight code blocks with lowlight (highlight.js)",

@@ -36,16 +36,16 @@ "license": "MIT",

"devDependencies": {
"browserify": "^16.0.0",
"browserify": "^17.0.0",
"nyc": "^15.0.0",
"prettier": "^1.0.0",
"rehype": "9.0.0",
"remark-cli": "^7.0.0",
"remark-preset-wooorm": "^6.0.0",
"tape": "^4.0.0",
"tinyify": "^2.0.0",
"xo": "^0.28.0"
"prettier": "^2.0.0",
"rehype": "11.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"xo": "^0.37.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
"build-bundle": "browserify . -s rehypeHighlight > rehype-highlight.js",
"build-mangle": "browserify . -s rehypeHighlight -p tinyify > rehype-highlight.min.js",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify . -s rehypeHighlight -o rehype-highlight.js",
"build-mangle": "browserify . -s rehypeHighlight -o rehype-highlight.min.js -p tinyify",
"build": "npm run build-bundle && npm run build-mangle",

@@ -52,0 +52,0 @@ "test-api": "node test",

@@ -130,5 +130,5 @@ # rehype-highlight

[build-badge]: https://img.shields.io/travis/rehypejs/rehype-highlight.svg
[build-badge]: https://github.com/rehypejs/rehype-highlight/workflows/main/badge.svg
[build]: https://travis-ci.org/rehypejs/rehype-highlight
[build]: https://github.com/rehypejs/rehype-highlight/actions

@@ -153,5 +153,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-highlight.svg

[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://spectrum.chat/unified/rehype
[chat]: https://github.com/rehypejs/rehype/discussions

@@ -162,7 +162,7 @@ [npm]: https://docs.npmjs.com/cli/install

[contributing]: https://github.com/rehypejs/.github/blob/master/contributing.md
[contributing]: https://github.com/rehypejs/.github/blob/HEAD/contributing.md
[support]: https://github.com/rehypejs/.github/blob/master/support.md
[support]: https://github.com/rehypejs/.github/blob/HEAD/support.md
[coc]: https://github.com/rehypejs/.github/blob/master/code-of-conduct.md
[coc]: https://github.com/rehypejs/.github/blob/HEAD/code-of-conduct.md

@@ -169,0 +169,0 @@ [license]: license

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc