ultramarked
Advanced tools
Comparing version 0.5.5 to 0.6.0
@@ -10,3 +10,3 @@ { | ||
}, | ||
"version": "0.5.5", | ||
"version": "0.6.0", | ||
"repository": { | ||
@@ -21,4 +21,4 @@ "type": "git", | ||
"he": "^0.4.1", | ||
"highlight.js": "~7.3.0", | ||
"marked": "~0.2.9" | ||
"highlight.js": "^8.0.0", | ||
"marked": "^0.3.2" | ||
}, | ||
@@ -25,0 +25,0 @@ "engines": { |
@@ -25,3 +25,3 @@ # ultramarked | ||
Syntax highlighting powered by [highlight.js](https://github.com/isagalaev/highlight.js), no extra magic. | ||
Syntax highlighting powered by [highlight.js](https://github.com/isagalaev/highlight.js), no extra magic. Classes are prefixed `hljs` for convenience. | ||
@@ -28,0 +28,0 @@ ### options.ultrasanitize |
@@ -13,2 +13,4 @@ 'use strict'; | ||
hljs.configure({ classPrefix: 'hljs-' }); | ||
function merge(obj) { | ||
@@ -29,2 +31,22 @@ var i = 1, target, key; | ||
function getHighlightingRenderer () { | ||
var renderer = new marked.Renderer(); | ||
var baseCodeRenderer = renderer.code; | ||
var baseCodeSpanRenderer = renderer.codespan; | ||
renderer.code = function () { | ||
var result = baseCodeRenderer.apply(this, arguments); | ||
var classed = result.replace(/^<pre><code>/i, '<pre class="hljs-pre"><code class="hljs">'); | ||
console.log(result); | ||
return classed; | ||
}; | ||
renderer.codespan = function () { | ||
var result = baseCodeSpanRenderer.apply(this, arguments); | ||
var classed = result.replace(/^<code>/i, '<code class="hljs">'); | ||
console.log(result); | ||
return classed; | ||
}; | ||
return renderer; | ||
} | ||
function ultramarked(src, opt) { | ||
@@ -38,3 +60,6 @@ var options = merge({}, marked.defaults, opt), | ||
options.highlight = function (code, lang) { | ||
var lower = (lang || no).toLowerCase(); | ||
if (!lang) { | ||
return code; | ||
} | ||
var lower = lang.toLowerCase(); | ||
try{ | ||
@@ -44,2 +69,3 @@ return hljs.highlight(aliases[lower] || lower, code).value; | ||
}; | ||
options.renderer = getHighlightingRenderer(); | ||
} | ||
@@ -50,9 +76,10 @@ | ||
if(options.ultralight){ // fix the language class using common aliases | ||
result = result.replace(/"ultralight-lang-([\w-]+)"/ig, function(match, lang){ | ||
if (options.ultralight) { // fix the language class using common aliases | ||
result = result.replace(/"ultralight-lang-([\w-]+)"/ig, function (match, lang) { | ||
var lower = lang.toLowerCase(), | ||
result = aliases[lower] || lower || no; | ||
return '"' + result + '"'; | ||
return '"hljs ' + result + '"'; | ||
}); | ||
result = result.replace(/^<pre>/, '<pre class="hljs-pre">'); | ||
} | ||
@@ -59,0 +86,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
52813
486
+ Addedhighlight.js@8.9.1(transitive)
+ Addedmarked@0.3.19(transitive)
- Removedhighlight.js@7.3.0(transitive)
- Removedmarked@0.2.10(transitive)
Updatedhighlight.js@^8.0.0
Updatedmarked@^0.3.2