Socket
Socket
Sign inDemoInstall

markdown-it-highlightjs

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-it-highlightjs - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

CHANGELOG.md

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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc