Comparing version 0.2.1 to 0.3.0
'use strict'; | ||
var hljs = require('highlight.js/lib/highlight'); | ||
var Entities = require('html-entities').XmlEntities; | ||
var entities = new Entities(); | ||
var hljs; | ||
var alias = require('../build/highlight_alias.json'); | ||
hljs.configure({ | ||
classPrefix: '' | ||
}); | ||
module.exports = function(str, options) { | ||
@@ -11,4 +16,2 @@ if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
if (!hljs) initHighlight(); | ||
var gutter = options.hasOwnProperty('gutter') ? options.gutter : true; | ||
@@ -55,10 +58,2 @@ var wrap = options.hasOwnProperty('wrap') ? options.wrap : true; | ||
function initHighlight() { | ||
hljs = require('highlight.js'); | ||
hljs.configure({ | ||
classPrefix: '' | ||
}); | ||
} | ||
function encodePlainString(str) { | ||
@@ -80,2 +75,20 @@ return entities.encode(str); | ||
function loadLanguage(lang) { | ||
hljs.registerLanguage(lang, require('highlight.js/lib/languages/' + lang)); | ||
} | ||
function tryLanguage(lang) { | ||
if (hljs.getLanguage(lang)) return true; | ||
if (!alias.aliases[lang]) return false; | ||
loadLanguage(alias.aliases[lang]); | ||
return true; | ||
} | ||
function loadAllLanguages() { | ||
alias.languages.filter(function(lang) { | ||
return !hljs.getLanguage(lang); | ||
}).forEach(loadLanguage); | ||
} | ||
function highlight(str, options) { | ||
@@ -87,2 +100,3 @@ var lang = options.lang; | ||
if (autoDetect) { | ||
loadAllLanguages(); | ||
return hljs.highlightAuto(str); | ||
@@ -103,3 +117,3 @@ } | ||
if (!hljs.getLanguage(result.language)) { | ||
if (!tryLanguage(result.language)) { | ||
result.language = 'plain'; | ||
@@ -106,0 +120,0 @@ return result; |
'use strict'; | ||
var hash = require('./hash'); | ||
exports.escapeDiacritic = require('./escape_diacritic'); | ||
@@ -15,1 +17,3 @@ exports.escapeHTML = require('./escape_html'); | ||
exports.wordWrap = require('./word_wrap'); | ||
exports.hash = hash.hash; | ||
exports.HashStream = hash.HashStream; |
{ | ||
"name": "hexo-util", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Utilities for Hexo.", | ||
@@ -15,5 +15,2 @@ "main": "lib/index", | ||
}, | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
}, | ||
"repository": "hexojs/hexo-util", | ||
@@ -29,13 +26,15 @@ "homepage": "http://hexo.io/", | ||
"devDependencies": { | ||
"chai": "^3.4.0", | ||
"eslint": "^1.8.0", | ||
"istanbul": "^0.4.0", | ||
"jscs": "^2.5.0", | ||
"mocha": "^2.3.3" | ||
"chai": "^3.4.1", | ||
"eslint": "^1.10.3", | ||
"eslint-config-hexo": "^1.0.2", | ||
"istanbul": "^0.4.1", | ||
"jscs": "^2.6.0", | ||
"jscs-preset-hexo": "^1.0.1", | ||
"mocha": "^2.3.4" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^3.0.5", | ||
"highlight.js": "^8.9.1", | ||
"bluebird": "^3.0.6", | ||
"highlight.js": "^9.0.0", | ||
"html-entities": "^1.2.0" | ||
} | ||
} |
@@ -31,2 +31,25 @@ # hexo-util | ||
### hash(str) | ||
Generates SHA1 hash. | ||
``` js | ||
hash('123456'); | ||
// <Buffer 7c 4a 8d 09 ca 37 62 af 61 e5 95 20 94 3d c2 64 94 f8 94 1b> | ||
``` | ||
### HashStream() | ||
Generates SHA1 hash with a transform stream. | ||
``` js | ||
var stream = new HashStream(); | ||
fs.createReadStream('/path/to/file') | ||
.pipe(stream) | ||
.on('finish', function(){ | ||
console.log(stream.read()); | ||
}); | ||
``` | ||
### highlight(str, [options]) | ||
@@ -33,0 +56,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
34313
23
525
217
7
4
+ Addedhighlight.js@9.18.5(transitive)
- Removedhighlight.js@8.9.1(transitive)
Updatedbluebird@^3.0.6
Updatedhighlight.js@^9.0.0