@highlightjs/vue-plugin
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
var hljsVuePlugin=function(e){"use strict";const t={props:["language","code","autodetect"],data:function(){return{detectedLanguage:"",unknownLanguage:!1}},computed:{className(){return this.unknownLanguage?"":"hljs "+this.detectedLanguage},highlighted(){if(!this.autoDetect&&!e.getLanguage(this.language))return console.warn(`The language "${this.language}" you specified could not be found.`),this.unknownLanguage=!0,this.code.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'");let t={};return this.autoDetect?(t=e.highlightAuto(this.code),this.detectedLanguage=t.language):(t=e.highlight(this.code,{language:this.language,ignoreIllegals:this.ignoreIllegals}),this.detectedLanguage=this.language),t.value},autoDetect(){return!this.language||(e=this.autodetect,Boolean(e||""===e));var e},ignoreIllegals:()=>!0},render(e){return e("pre",{},[e("code",{class:this.className,domProps:{innerHTML:this.highlighted}})])}};return{install(e){e.component("highlightjs",t)},component:t}}(hljs); | ||
var hljsVuePlugin=function(e,u){"use strict";var n=e.defineComponent({props:{code:{type:String,required:!0},language:{type:String,default:""},autodetect:{type:Boolean,default:!0},ignoreIllegals:{type:Boolean,default:!0}},setup:function(n){var t=e.ref(n.language);e.watch((function(){return n.language}),(function(e){t.value=e}));var a=e.computed((function(){return n.autodetect||!t.value})),l=e.computed((function(){return!a.value&&!u.getLanguage(t.value)}));return{className:e.computed((function(){return l.value?"":"hljs "+t.value})),highlightedCode:e.computed((function(){var e;if(l.value)return console.warn('The language "'+t.value+'" you specified could not be found.'),n.code.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'");if(a.value){var r=u.highlightAuto(n.code);return t.value=null!==(e=r.language)&&void 0!==e?e:"",r.value}return(r=u.highlight(n.code,{language:t.value,ignoreIllegals:n.ignoreIllegals})).value}))}},render:function(){return e.h("pre",{},[e.h("code",{class:this.className,innerHTML:this.highlightedCode})])}});return{install:function(e){e.component("highlightjs",n)}}}(Vue,hljs); |
{ | ||
"name": "@highlightjs/vue-plugin", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Highlight.js Vue Plugin", | ||
"main": "src/vue.js", | ||
"main": "dist/highlightjs-vue.min.js", | ||
"module": "dist/highlightjs-vue.esm.min.js", | ||
"types": "dist/highlightjs-vue.d.ts", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"publish": "npm publish --access public" | ||
"publish": "npm publish --access public --tag next" | ||
}, | ||
@@ -16,6 +18,10 @@ "type": "module", | ||
"rollup": "^2.42.3", | ||
"rollup-plugin-terser": "^7.0.2" | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.4" | ||
}, | ||
"dependencies": { | ||
"highlight.js": "^10.7.2" | ||
"highlight.js": "^10.7.2", | ||
"vue": "^3" | ||
}, | ||
@@ -22,0 +28,0 @@ "files": [ |
@@ -1,5 +0,9 @@ | ||
# Highlight.js plugin for Vue.js v2 | ||
# Highlight.js plugin for Vue.js | ||
[](https://www.npmjs.com/package/@highlightjs/vue-plugin) | ||
[](https://www.npmjs.com/package/@highlightjs/vue-plugin) | ||
[](https://www.npmjs.com/package/@highlightjs/vue-plugin) | ||
 | ||
 | ||
[](https://github.com/highlightjs/vue-plugin/blob/main/LICENSE) | ||
[](https://packagephobia.com/result?p=@highlightjs/vue-plugin) | ||
@@ -10,7 +14,6 @@ [](https://bundlephobia.com/result?p=@highlightjs/vue-plugin) | ||
This plugin provides a `highlightjs` component for use | ||
in your Vue.js applications: | ||
This plugin provides a `highlightjs` component for use in your Vue.js 3 applications: | ||
```html | ||
<div id="app"> | ||
<div id="app"> | ||
<!-- bind to a data property named `code` --> | ||
@@ -20,5 +23,7 @@ <highlightjs autodetect :code="code" /> | ||
<highlightjs language='javascript' code="var x = 5;" /> | ||
</div> | ||
</div> | ||
``` | ||
Note: For Vue.js version 2 support see the [1-stable](https://github.com/highlightjs/vue-plugin/tree/1-stable) branch here on GitHub. The `latest` tag via NPM is compatible with Vue.js v2; the `next` tag Vue.js v3. | ||
## Using the pre-built libraries | ||
@@ -35,3 +40,4 @@ | ||
```js | ||
Vue.use(hljsVuePlugin); | ||
const app = createApp(App) | ||
app.use(hljsVuePlugin) | ||
``` | ||
@@ -45,7 +51,9 @@ | ||
import javascript from 'highlight.js/lib/languages/javascript'; | ||
import vuePlugin from "@highlightjs/vue-plugin"; | ||
import hljsVuePlugin from "@highlightjs/vue-plugin"; | ||
hljs.registerLanguage('javascript', javascript); | ||
Vue.use(vuePlugin); | ||
const app = createApp(App) | ||
app.use(hljsVuePlugin) | ||
app.mount('#app') | ||
``` | ||
@@ -59,4 +67,7 @@ | ||
import hljs from 'highlight.js/lib/common'; | ||
import vuePlugin from "@highlightjs/vue-plugin"; | ||
Vue.use(vuePlugin); | ||
import hljsVuePlugin from "@highlightjs/vue-plugin"; | ||
const app = createApp(App) | ||
app.use(hljsVuePlugin) | ||
app.mount('#app') | ||
``` | ||
@@ -70,2 +81,2 @@ | ||
npm run build | ||
``` | ||
``` |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
10687
43.51%11
83.33%96
33.33%77
18.46%2
100%5
150%3
50%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added