Comparing version 2.8.0 to 2.9.0
26
core.js
@@ -46,2 +46,3 @@ 'use strict' | ||
refract.register = register | ||
refract.alias = alias | ||
refract.registered = registered | ||
@@ -70,2 +71,27 @@ refract.listLanguages = listLanguages | ||
function alias(name, alias) { | ||
var languages = refract.languages | ||
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) { | ||
languages[list[index]] = languages[key] | ||
} | ||
} | ||
} | ||
function highlight(value, name) { | ||
@@ -72,0 +98,0 @@ var sup = Prism.highlight |
{ | ||
"name": "refractor", | ||
"version": "2.8.0", | ||
"version": "2.9.0", | ||
"description": "Lightweight, robust, elegant virtual syntax highlighting using Prism", | ||
@@ -48,3 +48,3 @@ "license": "MIT", | ||
"not": "^0.1.0", | ||
"nyc": "^13.0.0", | ||
"nyc": "^14.0.0", | ||
"prettier": "^1.12.1", | ||
@@ -51,0 +51,0 @@ "rehype": "^7.0.0", |
@@ -23,2 +23,3 @@ # refractor [![Build][build-badge]][build] [![Coverage][coverage-badge]][coverage] [![Downloads][downloads-badge]][downloads] [![Size][size-badge]][size] | ||
* [refractor.register(syntax)](#refractorregistersyntax) | ||
* [refractor.alias(name\[, alias\])](#refractoraliasname-alias) | ||
* [refractor.highlight(value, language)](#refractorhighlightvalue-language) | ||
@@ -117,2 +118,35 @@ * [refractor.registered(language)](#refractorregisteredlanguage) | ||
### `refractor.alias(name[, alias])` | ||
Register a new `alias` for the `name` language. | ||
###### Signatures | ||
* `alias(name, alias|list)` | ||
* `alias(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 refractor = require('./core') | ||
var markdown = require('./lang/markdown') | ||
refractor.register(markdown) | ||
// refractor.highlight('*Emphasis*', 'mdown') | ||
// ^ would throw: Error: Unknown language: `mdown` is not registered | ||
refractor.alias({markdown: ['mdown', 'mkdn', 'mdwn', 'ron']}) | ||
refractor.highlight('*Emphasis*', 'mdown') | ||
// ^ Works! | ||
``` | ||
### `refractor.highlight(value, language)` | ||
@@ -119,0 +153,0 @@ |
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
497747
10778
578