rehype-highlight
Advanced tools
Comparing version 2.0.1 to 2.1.0
26
index.js
@@ -13,2 +13,4 @@ 'use strict'; | ||
var prefix = settings.prefix; | ||
var ignoreMissing = settings.ignoreMissing; | ||
var plainText = settings.plainText || []; | ||
var name = 'hljs'; | ||
@@ -39,3 +41,3 @@ var pos; | ||
if (lang === false || (!lang && !detect)) { | ||
if (lang === false || (!lang && !detect) || plainText.indexOf(lang) !== -1) { | ||
return; | ||
@@ -52,12 +54,20 @@ } | ||
if (lang) { | ||
result = lowlight.highlight(lang, toString(node), options); | ||
} else { | ||
result = lowlight.highlightAuto(toString(node), options); | ||
try { | ||
if (lang) { | ||
result = lowlight.highlight(lang, toString(node), options); | ||
} else { | ||
result = lowlight.highlightAuto(toString(node), options); | ||
} | ||
} catch (err) { | ||
if (err && ignoreMissing && /Unknown language/.test(err.message)) { | ||
return; | ||
} | ||
if (result.language) { | ||
props.className.push('language-' + result.language); | ||
} | ||
throw err; | ||
} | ||
if (!lang && result.language) { | ||
props.className.push('language-' + result.language); | ||
} | ||
node.children = result.value; | ||
@@ -64,0 +74,0 @@ } |
{ | ||
"name": "rehype-highlight", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Highlight code blocks", | ||
@@ -13,4 +13,4 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/wooorm/rehype-highlight", | ||
"bugs": "https://github.com/wooorm/rehype-highlight/issues", | ||
"repository": "rehypejs/rehype-highlight", | ||
"bugs": "https://github.com/rehypejs/rehype-highlight/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
@@ -29,8 +29,8 @@ "contributors": [ | ||
"devDependencies": { | ||
"browserify": "^14.1.0", | ||
"browserify": "^15.0.0", | ||
"esmangle": "^1.0.1", | ||
"nyc": "^11.0.0", | ||
"rehype": "^5.0.0", | ||
"remark-cli": "^3.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.0.0", | ||
@@ -37,0 +37,0 @@ "xo": "^0.18.0" |
@@ -74,2 +74,20 @@ # rehype-highlight [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
###### `options.ignoreMissing` | ||
`boolean`, default: `false`. By default, unregistered syntaxes throw an error | ||
when they are used. Pass `true` to swallow those errors and thus ignore code | ||
with unknown code languages. | ||
###### `options.plainText` | ||
`Array.<string>`, default: `[]`. Pass any languages you would like to be kept | ||
as plain-text instead of getting highlighted. | ||
## Contribute | ||
See [`contribute.md` in `rehypejs/rehype`][contribute] for ways to get started. | ||
This organisation has a [Code of Conduct][coc]. By interacting with this | ||
repository, organisation, or community you agree to abide by its terms. | ||
## License | ||
@@ -81,9 +99,9 @@ | ||
[travis-badge]: https://img.shields.io/travis/wooorm/rehype-highlight.svg | ||
[travis-badge]: https://img.shields.io/travis/rehypejs/rehype-highlight.svg | ||
[travis]: https://travis-ci.org/wooorm/rehype-highlight | ||
[travis]: https://travis-ci.org/rehypejs/rehype-highlight | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/rehype-highlight.svg | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-highlight.svg | ||
[codecov]: https://codecov.io/github/wooorm/rehype-highlight | ||
[codecov]: https://codecov.io/github/rehypejs/rehype-highlight | ||
@@ -96,3 +114,3 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[rehype]: https://github.com/wooorm/rehype | ||
[rehype]: https://github.com/rehypejs/rehype | ||
@@ -102,1 +120,5 @@ [lowlight]: https://github.com/wooorm/lowlight | ||
[highlight-js]: https://github.com/isagalaev/highlight.js | ||
[contribute]: https://github.com/rehypejs/rehype/blob/master/contributing.md | ||
[coc]: https://github.com/rehypejs/rehype/blob/master/code-of-conduct.md |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
8072
76
121