Skip to content

Commit

Permalink
Update dependencies, remove Babel and Lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriangalliat committed Feb 26, 2017
1 parent 8666c28 commit 875b35b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,2 +1 @@
/node_modules
/index.js
19 changes: 7 additions & 12 deletions index.es6.js → 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 =>
Expand All @@ -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)
Expand All @@ -47,4 +42,4 @@ highlightjs.defaults = {
code: true
}

export default highlightjs
module.exports = highlightjs
13 changes: 5 additions & 8 deletions package.json
Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions 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```'),
Expand Down

0 comments on commit 875b35b

Please sign in to comment.