Skip to content

Commit cf5cad8

Browse files
committed
remove complexity of function with nothing to pass
1 parent e034bac commit cf5cad8

File tree

4 files changed

+111
-117
lines changed

4 files changed

+111
-117
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
.vscode

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ in your templates:
2323
Then simply register the plugin with Vue:
2424

2525
```js
26-
Vue.use(hljsVuePlugin());
26+
Vue.use(hljsVuePlugin);
2727
```
2828

2929

@@ -36,13 +36,13 @@ import vuePlugin from "@highlightjs/vue-plugin";
3636

3737
hljs.registerLanguage('javascript', javascript);
3838

39-
Vue.use(vuePlugin());
39+
Vue.use(vuePlugin);
4040
```
4141

4242
Note: This plugin imports `lib/core` internally (but no languages). Thanks to the magic of ES6 modules you can import Highlight.js anywhere you need in order to register languages or configure the library. Or can also simply use the "common" languages (as of v11):
4343

4444
```js
4545
import hljs from 'highlight.js/lib/common';
4646
import vuePlugin from "@highlightjs/vue-plugin";
47-
Vue.use(vuePlugin());
47+
Vue.use(vuePlugin);
4848
```

dist/highlightjs-vue.min.js

+54-58
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var hljsVuePlugin = (function (highlightjs) {
1+
var hljsVuePlugin = (function (hljs) {
22
'use strict';
33

44
function escapeHTML(value) {
@@ -14,69 +14,65 @@ var hljsVuePlugin = (function (highlightjs) {
1414
return Boolean(value || value === "");
1515
}
1616

17-
function BuildVuePlugin(hljs=highlightjs) {
18-
const Component = {
19-
props: ["language", "code", "autodetect"],
20-
data: function() {
21-
return {
22-
detectedLanguage: "",
23-
unknownLanguage: false
24-
};
25-
},
26-
computed: {
27-
className() {
28-
if (this.unknownLanguage) return "";
17+
const Component = {
18+
props: ["language", "code", "autodetect"],
19+
data: function() {
20+
return {
21+
detectedLanguage: "",
22+
unknownLanguage: false
23+
};
24+
},
25+
computed: {
26+
className() {
27+
if (this.unknownLanguage) return "";
2928

30-
return "hljs " + this.detectedLanguage;
31-
},
32-
highlighted() {
33-
// no idea what language to use, return raw code
34-
if (!this.autoDetect && !hljs.getLanguage(this.language)) {
35-
console.warn(`The language "${this.language}" you specified could not be found.`);
36-
this.unknownLanguage = true;
37-
return escapeHTML(this.code);
38-
}
29+
return "hljs " + this.detectedLanguage;
30+
},
31+
highlighted() {
32+
// no idea what language to use, return raw code
33+
if (!this.autoDetect && !hljs.getLanguage(this.language)) {
34+
console.warn(`The language "${this.language}" you specified could not be found.`);
35+
this.unknownLanguage = true;
36+
return escapeHTML(this.code);
37+
}
3938

40-
let result = {};
41-
if (this.autoDetect) {
42-
result = hljs.highlightAuto(this.code);
43-
this.detectedLanguage = result.language;
44-
} else {
45-
result = hljs.highlight(this.language, this.code, this.ignoreIllegals);
46-
this.detectedLanguage = this.language;
47-
}
48-
return result.value;
49-
},
50-
autoDetect() {
51-
return !this.language || hasValueOrEmptyAttribute(this.autodetect);
52-
},
53-
ignoreIllegals() {
54-
return true;
39+
let result = {};
40+
if (this.autoDetect) {
41+
result = hljs.highlightAuto(this.code);
42+
this.detectedLanguage = result.language;
43+
} else {
44+
result = hljs.highlight(this.language, this.code, this.ignoreIllegals);
45+
this.detectedLanguage = this.language;
5546
}
47+
return result.value;
5648
},
57-
// this avoids needing to use a whole Vue compilation pipeline just
58-
// to build Highlight.js
59-
render(createElement) {
60-
return createElement("pre", {}, [
61-
createElement("code", {
62-
class: this.className,
63-
domProps: { innerHTML: this.highlighted }
64-
})
65-
]);
66-
}
67-
// template: `<pre><code :class="className" v-html="highlighted"></code></pre>`
68-
};
69-
70-
const VuePlugin = {
71-
install(Vue) {
72-
Vue.component('highlightjs', Component);
49+
autoDetect() {
50+
return !this.language || hasValueOrEmptyAttribute(this.autodetect);
7351
},
74-
component: Component
75-
};
52+
ignoreIllegals() {
53+
return true;
54+
}
55+
},
56+
// this avoids needing to use a whole Vue compilation pipeline just
57+
// to build Highlight.js
58+
render(createElement) {
59+
return createElement("pre", {}, [
60+
createElement("code", {
61+
class: this.className,
62+
domProps: { innerHTML: this.highlighted }
63+
})
64+
]);
65+
}
66+
// template: `<pre><code :class="className" v-html="highlighted"></code></pre>`
67+
};
7668

77-
return VuePlugin;
78-
}
69+
var vue = {
70+
install(Vue) {
71+
Vue.component('highlightjs', Component);
72+
},
73+
component: Component
74+
};
7975

80-
return BuildVuePlugin;
76+
return vue;
8177

8278
}(hljs));

src/vue.js

+53-56
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,66 @@
11
import { escapeHTML } from "./lib/utils.js";
2-
import highlightjs from "highlight.js/lib/core.js";
2+
import hljs from "highlight.js/lib/core.js";
33

44
function hasValueOrEmptyAttribute(value) {
55
return Boolean(value || value === "");
66
}
77

8-
export default function BuildVuePlugin(hljs=highlightjs) {
9-
const Component = {
10-
props: ["language", "code", "autodetect"],
11-
data: function() {
12-
return {
13-
detectedLanguage: "",
14-
unknownLanguage: false
15-
};
16-
},
17-
computed: {
18-
className() {
19-
if (this.unknownLanguage) return "";
8+
const Component = {
9+
props: ["language", "code", "autodetect"],
10+
data: function() {
11+
return {
12+
detectedLanguage: "",
13+
unknownLanguage: false
14+
};
15+
},
16+
computed: {
17+
className() {
18+
if (this.unknownLanguage) return "";
2019

21-
return "hljs " + this.detectedLanguage;
22-
},
23-
highlighted() {
24-
// no idea what language to use, return raw code
25-
if (!this.autoDetect && !hljs.getLanguage(this.language)) {
26-
console.warn(`The language "${this.language}" you specified could not be found.`);
27-
this.unknownLanguage = true;
28-
return escapeHTML(this.code);
29-
}
20+
return "hljs " + this.detectedLanguage;
21+
},
22+
highlighted() {
23+
// no idea what language to use, return raw code
24+
if (!this.autoDetect && !hljs.getLanguage(this.language)) {
25+
console.warn(`The language "${this.language}" you specified could not be found.`);
26+
this.unknownLanguage = true;
27+
return escapeHTML(this.code);
28+
}
3029

31-
let result = {};
32-
if (this.autoDetect) {
33-
result = hljs.highlightAuto(this.code);
34-
this.detectedLanguage = result.language;
35-
} else {
36-
result = hljs.highlight(this.language, this.code, this.ignoreIllegals);
37-
this.detectedLanguage = this.language;
38-
}
39-
return result.value;
40-
},
41-
autoDetect() {
42-
return !this.language || hasValueOrEmptyAttribute(this.autodetect);
43-
},
44-
ignoreIllegals() {
45-
return true;
30+
let result = {};
31+
if (this.autoDetect) {
32+
result = hljs.highlightAuto(this.code);
33+
this.detectedLanguage = result.language;
34+
} else {
35+
result = hljs.highlight(this.language, this.code, this.ignoreIllegals);
36+
this.detectedLanguage = this.language;
4637
}
38+
return result.value;
4739
},
48-
// this avoids needing to use a whole Vue compilation pipeline just
49-
// to build Highlight.js
50-
render(createElement) {
51-
return createElement("pre", {}, [
52-
createElement("code", {
53-
class: this.className,
54-
domProps: { innerHTML: this.highlighted }
55-
})
56-
]);
40+
autoDetect() {
41+
return !this.language || hasValueOrEmptyAttribute(this.autodetect);
42+
},
43+
ignoreIllegals() {
44+
return true;
5745
}
58-
// template: `<pre><code :class="className" v-html="highlighted"></code></pre>`
59-
};
46+
},
47+
// this avoids needing to use a whole Vue compilation pipeline just
48+
// to build Highlight.js
49+
render(createElement) {
50+
return createElement("pre", {}, [
51+
createElement("code", {
52+
class: this.className,
53+
domProps: { innerHTML: this.highlighted }
54+
})
55+
]);
56+
}
57+
// template: `<pre><code :class="className" v-html="highlighted"></code></pre>`
58+
};
6059

61-
const VuePlugin = {
62-
install(Vue) {
63-
Vue.component('highlightjs', Component);
64-
},
65-
component: Component
66-
};
60+
export default {
61+
install(Vue) {
62+
Vue.component('highlightjs', Component);
63+
},
64+
component: Component
65+
};
6766

68-
return VuePlugin;
69-
}

0 commit comments

Comments
 (0)