vue-highlightjs
Advanced tools
Comparing version 1.1.0 to 1.2.0
66
index.js
@@ -1,33 +0,39 @@ | ||
var hljs = require('highlight.js') | ||
'use strict'; | ||
var vueHighlightJS = {} | ||
const hljs = require('highlight.js'); | ||
vueHighlightJS.install = function (Vue) { | ||
Vue.directive('highlightjs', { | ||
deep: true, | ||
bind: function (el, binding) { | ||
// on first bind, highlight all targets | ||
var targets = el.querySelectorAll('code') | ||
targets.forEach(function(target) { | ||
// if a value is directly assigned to the directive, use this | ||
// instead of the element content. | ||
if (binding.value) { | ||
target.innerHTML = binding.value | ||
} | ||
hljs.highlightBlock(target) | ||
}) | ||
}, | ||
componentUpdated: function (el, binding) { | ||
// after an update, re-fill the content and then highlight | ||
var targets = el.querySelectorAll('code') | ||
targets.forEach(function(target) { | ||
if (binding.value) { | ||
target.innerHTML = binding.value | ||
hljs.highlightBlock(target) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
const vueHighlightJS = {}; | ||
vueHighlightJS.install = function install(Vue) { | ||
Vue.directive('highlightjs', { | ||
deep: true, | ||
bind: function bind(el, binding) { | ||
// on first bind, highlight all targets | ||
const targets = el.querySelectorAll('code'); | ||
for (let i = 0; i < targets.length; i += 1) { | ||
const target = targets[i]; | ||
module.exports = vueHighlightJS | ||
if (binding.value) { | ||
// if a value is directly assigned to the directive, use this | ||
// instead of the element content. | ||
target.innerHTML = binding.value; | ||
} | ||
hljs.highlightBlock(target); | ||
} | ||
}, | ||
componentUpdated: function componentUpdated(el, binding) { | ||
// after an update, re-fill the content and then highlight | ||
const targets = el.querySelectorAll('code'); | ||
for (let i = 0; i < targets.length; i += 1) { | ||
const target = targets[i]; | ||
if (binding.value) { | ||
target.innerHTML = binding.value; | ||
hljs.highlightBlock(target); | ||
} | ||
} | ||
}, | ||
}); | ||
}; | ||
module.exports = vueHighlightJS; |
{ | ||
"name": "vue-highlightjs", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Syntax highlighting with highlight.js for Vue.js 2.x", | ||
@@ -17,3 +17,4 @@ "homepage": "https://github.com/metachris/vue-highlightjs", | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "node test.js", | ||
"lint": "./node_modules/.bin/eslint *.js" | ||
}, | ||
@@ -29,3 +30,8 @@ "keywords": [ | ||
"highlight.js": "*" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.17.1", | ||
"eslint-config-airbnb-base": "^11.1.1", | ||
"eslint-plugin-import": "^2.2.0" | ||
} | ||
} |
@@ -36,2 +36,13 @@ [Vue.js](https://vuejs.org/) syntax highlighting made easy, using [highlight.js](https://highlightjs.org/). | ||
## Contributing | ||
Any sort of contributions and feedback is much appreciated. Just | ||
leave an issue or pull-request! | ||
This project uses the [AirBnB code style](https://github.com/airbnb/javascript). | ||
Please run `npm run lint` and `npm run test` before you submit a pull request! <3 | ||
## About | ||
@@ -42,1 +53,6 @@ | ||
License: MIT | ||
Contributors: | ||
* Chris Hager | ||
* [mr-krille](https://github.com/mr-krille) |
14
test.js
const assert = require('assert'); | ||
var vueHighlightJS = require('./index') | ||
const vueHighlightJS = require('./index'); | ||
assert.equal(typeof vueHighlightJS.install, 'function') | ||
const vueStub = { | ||
directive: function directive(name, options) { | ||
assert.equal(typeof name, 'string'); | ||
assert.equal(typeof options, 'object'); | ||
assert.equal(typeof options.bind, 'function'); | ||
assert.equal(typeof options.componentUpdated, 'function'); | ||
}, | ||
}; | ||
assert.equal(typeof vueHighlightJS.install, 'function'); | ||
vueHighlightJS.install(vueStub); |
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
4355
9
54
57
3