UNPKG

1.71 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue'), require('prismjs')) :
3 typeof define === 'function' && define.amd ? define(['vue', 'prismjs'], factory) :
4 (global = global || self, global.PrismComponent = factory(global.vue, global.Prism));
5}(this, (function (vue, Prism) { 'use strict';
6
7 Prism = Prism && Object.prototype.hasOwnProperty.call(Prism, 'default') ? Prism['default'] : Prism;
8
9 var index = vue.defineComponent({
10 props: {
11 code: {
12 type: String
13 },
14 inline: {
15 type: Boolean,
16 "default": false
17 },
18 language: {
19 type: String,
20 "default": 'markup'
21 }
22 },
23 setup: function setup(props, _ref) {
24 var slots = _ref.slots,
25 attrs = _ref.attrs;
26 var defaultSlot = slots && slots["default"] && slots["default"]() || [];
27 var code = props.code || defaultSlot && defaultSlot.length ? defaultSlot[0].children : '';
28 var inline = props.inline;
29 var language = props.language;
30 var prismLanguage = Prism.languages[language];
31 var className = "language-".concat(language);
32
33 return function () {
34 if (inline) {
35 return vue.h('code', {
36 "class": [className],
37 innerHTML: Prism.highlight(code, prismLanguage)
38 });
39 }
40
41 return vue.h('pre', Object.assign({}, attrs, {
42 "class": [attrs["class"], className]
43 }), [vue.h('code', Object.assign({}, attrs, {
44 "class": [attrs["class"], className],
45 innerHTML: Prism.highlight(code, prismLanguage)
46 }))]);
47 };
48 }
49 });
50
51 return index;
52
53})));