Comparing version 1.9.2 to 1.10.0
@@ -22,2 +22,3 @@ 'use strict' | ||
low.registerLanguage = registerLanguage | ||
low.registerAlias = registerAlias | ||
low.getLanguage = getLanguage | ||
@@ -119,5 +120,2 @@ | ||
var lang = syntax(low) | ||
var values = lang.aliases | ||
var length = values && values.length | ||
var index = -1 | ||
@@ -128,7 +126,32 @@ languages[name] = lang | ||
while (++index < length) { | ||
aliases[values[index]] = name | ||
if (lang.aliases) { | ||
registerAlias(name, lang.aliases) | ||
} | ||
} | ||
/* Register more aliases for an already registered language. */ | ||
function registerAlias(name, alias) { | ||
var map = name | ||
var key | ||
var list | ||
var length | ||
var index | ||
if (alias) { | ||
map = {} | ||
map[name] = alias | ||
} | ||
for (key in map) { | ||
list = map[key] | ||
list = typeof list === 'string' ? [list] : list | ||
length = list.length | ||
index = -1 | ||
while (++index < length) { | ||
aliases[list[index]] = key | ||
} | ||
} | ||
} | ||
/* Core highlighting function. Accepts a language name, or | ||
@@ -341,3 +364,3 @@ * an alias, and a string with the code to highlight. | ||
subvalue = autoHighlight(modeBuffer, { | ||
subset: top.subLanguage.length ? top.subLanguage : undefined, | ||
subset: top.subLanguage.length === 0 ? undefined : top.subLanguage, | ||
prefix: prefix | ||
@@ -625,5 +648,6 @@ }) | ||
mode.terminators = terminators.length | ||
? langRe(terminators.join(pipe), true) | ||
: {exec: execNoop} | ||
mode.terminators = | ||
terminators.length === 0 | ||
? {exec: execNoop} | ||
: langRe(terminators.join(pipe), true) | ||
@@ -630,0 +654,0 @@ function map(c) { |
{ | ||
"name": "lowlight", | ||
"version": "1.9.2", | ||
"version": "1.10.0", | ||
"description": "Virtual syntax highlighting for virtual DOMs and non-HTML things", | ||
@@ -34,11 +34,11 @@ "license": "MIT", | ||
"chalk": "^2.0.0", | ||
"esmangle": "^1.0.0", | ||
"nyc": "^11.0.0", | ||
"nyc": "^12.0.0", | ||
"prettier": "^1.12.0", | ||
"rehype": "^5.0.0", | ||
"rehype": "^6.0.0", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.4.3", | ||
"unist-util-visit": "^1.0.0", | ||
"xo": "^0.20.0" | ||
"xo": "^0.22.0" | ||
}, | ||
@@ -48,4 +48,4 @@ "scripts": { | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"build-bundle": "browserify index.js --bare -s lowlight > lowlight.js", | ||
"build-mangle": "esmangle lowlight.js > lowlight.min.js", | ||
"build-bundle": "browserify index.js -s lowlight > lowlight.js", | ||
"build-mangle": "browserify index.js -s lowlight -p tinyify > lowlight.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
@@ -69,2 +69,3 @@ "test-api": "node test", | ||
"complexity": "off", | ||
"guard-for-in": "off", | ||
"max-params": "off", | ||
@@ -71,0 +72,0 @@ "object-shorthand": "off", |
@@ -18,2 +18,3 @@ # lowlight [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
* [low.registerLanguage(name, syntax)](#lowregisterlanguagename-syntax) | ||
* [low.registerAlias(name\[, alias\])](#lowregisteraliasname-alias) | ||
* [low.highlight(language, value\[, options\])](#lowhighlightlanguage-value-options) | ||
@@ -100,2 +101,34 @@ * [low.highlightAuto(value\[, options\])](#lowhighlightautovalue-options) | ||
### `low.registerAlias(name[, alias])` | ||
Register a new `alias` for the `name` language. | ||
###### Signatures | ||
* `registerAlias(name, alias|list)` | ||
* `registerAlias(aliases)` | ||
###### Parameters | ||
* `name` (`string`) — [Name][names] of a registered language | ||
* `alias` (`string`) — New alias for the registered language | ||
* `list` (`Array.<alias>`) — List of aliases | ||
* `aliases` (`Object.<alias|list>`) — Map where each key is a `name` and each | ||
value an `alias` or a `list` | ||
###### Example | ||
```js | ||
var low = require('lowlight/lib/core'); | ||
var md = require('highlight.js/lib/languages/markdown'); | ||
low.registerLanguage('markdown', md); | ||
// low.highlight('mdown', '<em>Emphasis</em>') | ||
// ^ would throw: Error: Unknown language: `mdown` is not registered | ||
low.registerAlias({markdown: ['mdown', 'mkdn', 'mdwn', 'ron']}) | ||
low.highlight('mdown', '<em>Emphasis</em>') | ||
// ^ Works! | ||
``` | ||
### `low.highlight(language, value[, options])` | ||
@@ -176,3 +209,3 @@ | ||
I do not suggest using the pre-built files or requiring `lowlight` in | ||
the browser as that would include a 530kb (170kb GZipped) file. | ||
the browser as that would include a 684kb (196kb GZipped) file. | ||
@@ -192,4 +225,4 @@ Instead, require `lowlight/lib/core`, and include only the used | ||
...When using browserify, minifying this results in just 17kb of code | ||
(7kb with GZip). | ||
...When using [browserify][] and minifying with [tinyify][] this results in | ||
just 18kb of code (7kb with GZip). | ||
@@ -256,1 +289,5 @@ ## Related | ||
[refractor]: https://github.com/wooorm/refractor | ||
[browserify]: https://github.com/browserify/browserify | ||
[tinyify]: https://github.com/browserify/tinyify |
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
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
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
39585
822
289
0