From 875b35bb583b096c1c3cf9ac39c431fde3c89722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Galliat?= Date: Sun, 26 Feb 2017 10:28:18 -0500 Subject: [PATCH] Update dependencies, remove Babel and Lodash --- .gitignore | 1 - index.es6.js => index.js | 19 +++++++------------ package.json | 13 +++++-------- test.js | 6 +++--- 4 files changed, 15 insertions(+), 24 deletions(-) rename index.es6.js => index.js (65%) diff --git a/.gitignore b/.gitignore index b8df26b..07e6e47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ /node_modules -/index.js diff --git a/index.es6.js b/index.js similarity index 65% rename from index.es6.js rename to index.js index eae2bdf..07034c7 100644 --- a/index.es6.js +++ b/index.js @@ -1,27 +1,22 @@ -import assign from 'lodash.assign' -import flow from 'lodash.flow' -import hljs from 'highlight.js' +const hljs = require('highlight.js') -const maybe = f => (...args) => { +const maybe = f => { try { - return f(...args) + return f() } catch (e) { return false } } -const get = name => x => x[name] -const maybeValue = f => maybe(flow(f, get('value'))) - // Highlight with given language. const highlight = (code, lang) => - maybeValue(hljs.highlight)(lang, code, true) || '' + maybe(() => hljs.highlight(lang, code, true).value) || '' // Highlight with given language or automatically. const highlightAuto = (code, lang) => lang ? highlight(code, lang) - : maybeValue(hljs.highlightAuto)(code) || '' + : maybe(() => hljs.highlightAuto(code).value) || '' // Wrap a render function to add `hljs` class to code blocks. const wrap = render => @@ -32,7 +27,7 @@ const wrap = render => } const highlightjs = (md, opts) => { - opts = assign({}, highlightjs.defaults, opts) + opts = Object.assign({}, highlightjs.defaults, opts) md.options.highlight = opts.auto ? highlightAuto : highlight md.renderer.rules.fence = wrap(md.renderer.rules.fence) @@ -47,4 +42,4 @@ highlightjs.defaults = { code: true } -export default highlightjs +module.exports = highlightjs diff --git a/package.json b/package.json index a5faf73..abd8211 100644 --- a/package.json +++ b/package.json @@ -21,19 +21,16 @@ "url": "https://github.com/valeriangalliat/markdown-it-highlightjs.git" }, "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" + "lint": "standard", + "prepublish": "npm test", + "test": "npm run lint && node test" }, "dependencies": { "highlight.js": "^9.9.0", - "lodash.assign": "^3.2.0", "lodash.flow": "^3.1.0" }, "devDependencies": { - "babel-cli": "^6.23.0", - "markdown-it": "^4.0.1", - "standard": "^4.0.1" + "markdown-it": "^8.3.0", + "standard": "^8.6.0" } } diff --git a/test.js b/test.js index 22d0c8e..2e06ced 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,6 @@ -import { equal } from 'assert' -import md from 'markdown-it' -import highlightjs from './' +const { equal } = require('assert') +const md = require('markdown-it') +const highlightjs = require('./') equal( md().use(highlightjs).render('```js\nconsole.log(42)\n```'),