UNPKG

1.81 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('prismjs')) :
3 typeof define === 'function' && define.amd ? define(['prismjs'], factory) :
4 (global = global || self, global.PrismComponent = factory(global.Prism));
5}(this, (function (Prism) { 'use strict';
6
7 Prism = Prism && Object.prototype.hasOwnProperty.call(Prism, 'default') ? Prism['default'] : Prism;
8
9 function assign(obj) {
10 for (var i = 1; i < arguments.length; i++) {
11 // eslint-disable-next-line guard-for-in, prefer-rest-params
12 for (var p in arguments[i]) {
13 obj[p] = arguments[i][p];
14 }
15 }
16
17 return obj;
18 }
19
20 var index = {
21 functional: true,
22 props: {
23 code: {
24 type: String
25 },
26 inline: {
27 type: Boolean,
28 "default": false
29 },
30 language: {
31 type: String,
32 "default": 'markup'
33 }
34 },
35 render: function render(h, ctx) {
36 var code = ctx.props.code || (ctx.children && ctx.children.length > 0 ? ctx.children[0].text : '');
37 var inline = ctx.props.inline;
38 var language = ctx.props.language;
39 var prismLanguage = Prism.languages[language];
40 var className = "language-".concat(language);
41
42 if (inline) {
43 return h('code', assign({}, ctx.data, {
44 "class": [ctx.data["class"], className],
45 domProps: assign({}, ctx.data.domProps, {
46 innerHTML: Prism.highlight(code, prismLanguage)
47 })
48 }));
49 }
50
51 return h('pre', assign({}, ctx.data, {
52 "class": [ctx.data["class"], className]
53 }), [h('code', {
54 "class": className,
55 domProps: {
56 innerHTML: Prism.highlight(code, prismLanguage)
57 }
58 })]);
59 }
60 };
61
62 return index;
63
64})));