hexo-util
Advanced tools
Comparing version 0.6.2 to 0.6.3
@@ -8,6 +8,2 @@ 'use strict'; | ||
hljs.configure({ | ||
classPrefix: '' | ||
}); | ||
function highlightUtil(str, options) { | ||
@@ -17,2 +13,3 @@ if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
var useHljs = options.hasOwnProperty('hljs') ? options.hljs : false; | ||
var gutter = options.hasOwnProperty('gutter') ? options.gutter : true; | ||
@@ -24,6 +21,14 @@ var wrap = options.hasOwnProperty('wrap') ? options.wrap : true; | ||
var tab = options.tab; | ||
hljs.configure({ classPrefix: useHljs ? 'hljs-' : ''}); | ||
var data = highlight(str, options); | ||
if (!wrap) return data.value; | ||
if (useHljs && !gutter) wrap = false; | ||
var before = useHljs ? '<pre><code class="hljs ' + options.lang + '">' : '<pre>'; | ||
var after = useHljs ? '</code></pre>' : '</pre>'; | ||
if (!wrap) return useHljs ? before + data.value + after : data.value; | ||
var lines = data.value.split('\n'); | ||
@@ -39,5 +44,3 @@ var numbers = ''; | ||
numbers += '<span class="line">' + (firstLine + i) + '</span><br>'; | ||
content += '<span class="line'; | ||
content += (mark.indexOf(firstLine + i) !== -1) ? ' marked' : ''; | ||
content += '">' + line + '</span><br>'; | ||
content += formatLine(line, firstLine + i, mark, options); | ||
} | ||
@@ -57,3 +60,3 @@ | ||
result += '<td class="code"><pre>' + content + '</pre></td>'; | ||
result += '<td class="code">' + before + content + after + '</td>'; | ||
result += '</tr></table></figure>'; | ||
@@ -64,2 +67,16 @@ | ||
function formatLine(line, lineno, marked, options) { | ||
var useHljs = options.hljs || false; | ||
var res = useHljs ? '' : '<span class="line'; | ||
if (marked.indexOf(lineno) !== -1) { | ||
// Handle marked lines. | ||
res += useHljs ? '<mark>' + line + '</mark>' : ' marked">' + line + '</span>'; | ||
} else { | ||
res += useHljs ? line : '">' + line + '</span>'; | ||
} | ||
res += '<br>'; | ||
return res; | ||
} | ||
function encodePlainString(str) { | ||
@@ -130,2 +147,4 @@ return entities.encode(str); | ||
if (options.hljs) return hljs.highlight(lang, str); | ||
return tryHighlight(str, result.language) || result; | ||
@@ -132,0 +151,0 @@ } |
{ | ||
"name": "hexo-util", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"description": "Utilities for Hexo.", | ||
@@ -41,9 +41,9 @@ "main": "lib/index", | ||
"dependencies": { | ||
"bluebird": "^3.5.1", | ||
"bluebird": "^3.4.0", | ||
"camel-case": "^3.0.0", | ||
"cross-spawn": "^4.0.2", | ||
"highlight.js": "^9.12.0", | ||
"html-entities": "^1.2.1", | ||
"striptags": "^2.2.1" | ||
"cross-spawn": "^4.0.0", | ||
"highlight.js": "^9.4.0", | ||
"html-entities": "^1.2.0", | ||
"striptags": "^2.1.1" | ||
} | ||
} |
@@ -92,2 +92,3 @@ # hexo-util | ||
`firstLine` | First line number | 1 | ||
`hljs` | Whether to use the `hljs-*` prefix for CSS classes | false | ||
`lang` | Language | | ||
@@ -94,0 +95,0 @@ `caption` | Caption | |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
95090
27
651
248
1
Updatedbluebird@^3.4.0
Updatedcross-spawn@^4.0.0
Updatedhighlight.js@^9.4.0
Updatedhtml-entities@^1.2.0
Updatedstriptags@^2.1.1