markdown-it-highlightjs
Advanced tools
Comparing version 1.1.2 to 2.0.0
39
index.js
@@ -5,2 +5,4 @@ "use strict"; | ||
var assign = _interopRequire(require("lodash.assign")); | ||
var flow = _interopRequire(require("lodash.flow")); | ||
@@ -10,4 +12,2 @@ | ||
var escapeHtml = require("markdown-it/lib/common/utils").escapeHtml; | ||
var maybe = function (f) { | ||
@@ -36,12 +36,15 @@ return function () { | ||
// Highlight with given language. | ||
var highlight = function (code, lang) { | ||
return maybeValue(hljs.highlight)(lang, code, true) || maybeValue(hljs.highlightAuto)(code) || ""; | ||
return maybeValue(hljs.highlight)(lang, code, true) || ""; | ||
}; | ||
module.exports = function (md) { | ||
md.options.highlight = highlight; | ||
// Highlight with given language or automatically. | ||
var highlightAuto = function (code, lang) { | ||
return lang ? highlight(code, lang) : maybeValue(hljs.highlightAuto)(code) || ""; | ||
}; | ||
var originalFence = md.renderer.rules.fence; | ||
md.renderer.rules.fence = function () { | ||
// Wrap a render function to add `hljs` class to code blocks. | ||
var wrap = function (render) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -51,4 +54,22 @@ args[_key] = arguments[_key]; | ||
return originalFence.apply(this, args).replace("<code class=\"", "<code class=\"hljs ").replace("<code>", "<code class=\"hljs\">"); | ||
return render.apply(this, args).replace("<code class=\"", "<code class=\"hljs ").replace("<code>", "<code class=\"hljs\">"); | ||
}; | ||
}; | ||
var highlightjs = function (md, opts) { | ||
opts = assign({}, highlightjs.defaults, opts); | ||
md.options.highlight = opts.auto ? highlightAuto : highlight; | ||
md.renderer.rules.fence = wrap(md.renderer.rules.fence); | ||
if (opts.code) { | ||
md.renderer.rules.code_block = wrap(md.renderer.rules.code_block); | ||
} | ||
}; | ||
highlightjs.defaults = { | ||
auto: true, | ||
code: true | ||
}; | ||
module.exports = highlightjs; |
{ | ||
"name": "markdown-it-highlightjs", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"description": "Preset to use highlight.js with markdown-it.", | ||
@@ -23,4 +23,11 @@ "keywords": [ | ||
}, | ||
"scripts": { | ||
"build": "babel index.es6.js -o index.js", | ||
"lint": "standard index.es6.js test.js", | ||
"prepublish": "npm run build", | ||
"test": "npm run lint && npm run build && babel-node test.js" | ||
}, | ||
"dependencies": { | ||
"highlight.js": "^8.4.0", | ||
"lodash.assign": "^3.2.0", | ||
"lodash.flow": "^3.1.0" | ||
@@ -30,9 +37,5 @@ }, | ||
"babel": "^4.5.0", | ||
"markdown-it": "^4.0.1" | ||
}, | ||
"scripts": { | ||
"build": "babel index.es6.js -o index.js", | ||
"prepublish": "$npm_package_scripts_build", | ||
"test": "$npm_package_scripts_build && babel-node test.js" | ||
"markdown-it": "^4.0.1", | ||
"standard": "^4.0.1" | ||
} | ||
} |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
6150
5
55
0
24
3
3
+ Addedlodash.assign@^3.2.0
+ Addedlodash._baseassign@3.2.0(transitive)
+ Addedlodash._basecopy@3.0.1(transitive)
+ Addedlodash._bindcallback@3.0.1(transitive)
+ Addedlodash._createassigner@3.1.1(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash._isiterateecall@3.0.9(transitive)
+ Addedlodash.assign@3.2.0(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedlodash.restparam@3.6.1(transitive)