vue-prism-component
Advanced tools
Comparing version
@@ -5,17 +5,6 @@ 'use strict'; | ||
var vue = require('vue'); | ||
var Prism = _interopDefault(require('prismjs')); | ||
function assign(obj) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
// eslint-disable-next-line guard-for-in, prefer-rest-params | ||
for (var p in arguments[i]) { | ||
obj[p] = arguments[i][p]; | ||
} | ||
} | ||
return obj; | ||
} | ||
var index = { | ||
functional: true, | ||
var index = vue.defineComponent({ | ||
props: { | ||
@@ -34,6 +23,9 @@ code: { | ||
}, | ||
render: function render(h, ctx) { | ||
var code = ctx.props.code || (ctx.children && ctx.children.length > 0 ? ctx.children[0].text : ''); | ||
var inline = ctx.props.inline; | ||
var language = ctx.props.language; | ||
setup: function setup(props, _ref) { | ||
var slots = _ref.slots, | ||
attrs = _ref.attrs; | ||
var defaultSlot = slots && slots["default"] && slots["default"]() || []; | ||
var code = props.code || defaultSlot && defaultSlot.length ? defaultSlot[0].children : ''; | ||
var inline = props.inline; | ||
var language = props.language; | ||
var prismLanguage = Prism.languages[language]; | ||
@@ -46,22 +38,20 @@ var className = "language-".concat(language); | ||
if (inline) { | ||
return h('code', assign({}, ctx.data, { | ||
"class": [ctx.data["class"], className], | ||
domProps: assign({}, ctx.data.domProps, { | ||
return function () { | ||
if (inline) { | ||
return vue.h('code', { | ||
"class": [className], | ||
innerHTML: Prism.highlight(code, prismLanguage) | ||
}) | ||
})); | ||
} | ||
}); | ||
} | ||
return h('pre', assign({}, ctx.data, { | ||
"class": [ctx.data["class"], className] | ||
}), [h('code', { | ||
"class": className, | ||
domProps: { | ||
return vue.h('pre', Object.assign({}, attrs, { | ||
"class": [attrs["class"], className] | ||
}), [vue.h('code', Object.assign({}, attrs, { | ||
"class": [attrs["class"], className], | ||
innerHTML: Prism.highlight(code, prismLanguage) | ||
} | ||
})]); | ||
}))]); | ||
}; | ||
} | ||
}; | ||
}); | ||
module.exports = index; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('prismjs')) : | ||
typeof define === 'function' && define.amd ? define(['prismjs'], factory) : | ||
(global = global || self, global.PrismComponent = factory(global.Prism)); | ||
}(this, (function (Prism) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue'), require('prismjs')) : | ||
typeof define === 'function' && define.amd ? define(['vue', 'prismjs'], factory) : | ||
(global = global || self, global.PrismComponent = factory(global.vue, global.Prism)); | ||
}(this, (function (vue, Prism) { 'use strict'; | ||
Prism = Prism && Object.prototype.hasOwnProperty.call(Prism, 'default') ? Prism['default'] : Prism; | ||
function assign(obj) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
// eslint-disable-next-line guard-for-in, prefer-rest-params | ||
for (var p in arguments[i]) { | ||
obj[p] = arguments[i][p]; | ||
} | ||
} | ||
return obj; | ||
} | ||
var index = { | ||
functional: true, | ||
var index = vue.defineComponent({ | ||
props: { | ||
@@ -35,28 +23,29 @@ code: { | ||
}, | ||
render: function render(h, ctx) { | ||
var code = ctx.props.code || (ctx.children && ctx.children.length > 0 ? ctx.children[0].text : ''); | ||
var inline = ctx.props.inline; | ||
var language = ctx.props.language; | ||
setup: function setup(props, _ref) { | ||
var slots = _ref.slots, | ||
attrs = _ref.attrs; | ||
var defaultSlot = slots && slots["default"] && slots["default"]() || []; | ||
var code = props.code || defaultSlot && defaultSlot.length ? defaultSlot[0].children : ''; | ||
var inline = props.inline; | ||
var language = props.language; | ||
var prismLanguage = Prism.languages[language]; | ||
var className = "language-".concat(language); | ||
if (inline) { | ||
return h('code', assign({}, ctx.data, { | ||
"class": [ctx.data["class"], className], | ||
domProps: assign({}, ctx.data.domProps, { | ||
return function () { | ||
if (inline) { | ||
return vue.h('code', { | ||
"class": [className], | ||
innerHTML: Prism.highlight(code, prismLanguage) | ||
}) | ||
})); | ||
} | ||
}); | ||
} | ||
return h('pre', assign({}, ctx.data, { | ||
"class": [ctx.data["class"], className] | ||
}), [h('code', { | ||
"class": className, | ||
domProps: { | ||
return vue.h('pre', Object.assign({}, attrs, { | ||
"class": [attrs["class"], className] | ||
}), [vue.h('code', Object.assign({}, attrs, { | ||
"class": [attrs["class"], className], | ||
innerHTML: Prism.highlight(code, prismLanguage) | ||
} | ||
})]); | ||
}))]); | ||
}; | ||
} | ||
}; | ||
}); | ||
@@ -63,0 +52,0 @@ return index; |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("prismjs")):"function"==typeof define&&define.amd?define(["prismjs"],n):(e=e||self).PrismComponent=n(e.Prism)}(this,function(e){"use strict";function n(e){for(var n=1;n<arguments.length;n++)for(var t in arguments[n])e[t]=arguments[n][t];return e}return e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,{functional:!0,props:{code:{type:String},inline:{type:Boolean,default:!1},language:{type:String,default:"markup"}},render:function(t,r){var o=r.props.code||(r.children&&r.children.length>0?r.children[0].text:""),a=r.props.inline,i=r.props.language,s=e.languages[i],l="language-".concat(i);return a?t("code",n({},r.data,{class:[r.data.class,l],domProps:n({},r.data.domProps,{innerHTML:e.highlight(o,s)})})):t("pre",n({},r.data,{class:[r.data.class,l]}),[t("code",{class:l,domProps:{innerHTML:e.highlight(o,s)}})])}}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("vue"),require("prismjs")):"function"==typeof define&&define.amd?define(["vue","prismjs"],n):(e=e||self).PrismComponent=n(e.vue,e.Prism)}(this,function(e,n){"use strict";return n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n,e.defineComponent({props:{code:{type:String},inline:{type:Boolean,default:!1},language:{type:String,default:"markup"}},setup:function(t,i){var s=i.slots,r=i.attrs,a=s&&s.default&&s.default()||[],o=t.code||a&&a.length?a[0].children:"",u=t.inline,l=t.language,c=n.languages[l],d="language-".concat(l);return function(){return u?e.h("code",{class:[d],innerHTML:n.highlight(o,c)}):e.h("pre",Object.assign({},r,{class:[r.class,d]}),[e.h("code",Object.assign({},r,{class:[r.class,d],innerHTML:n.highlight(o,c)}))])}}})}); | ||
//# sourceMappingURL=vue-prism-component.min.js.map |
{ | ||
"name": "vue-prism-component", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "vue component for prism.js", | ||
@@ -17,7 +17,7 @@ "repository": { | ||
"scripts": { | ||
"test": "npm run build", | ||
"test": "echo skip", | ||
"lint": "xo", | ||
"prepublish": "npm run build", | ||
"prepublishOnly": "npm run build", | ||
"build": "npm run build:umd && npm run build:cjs", | ||
"build:umd": "bili --file-name \"vue-prism-component[min].js\" --format umd --format umd-min --env.NODE_ENV production --module-name PrismComponent --external prismjs", | ||
"build:umd": "bili --file-name \"vue-prism-component[min].js\" --format umd --format umd-min --env.NODE_ENV production --module-name PrismComponent --external prismjs --external vue", | ||
"build:cjs": "bili --file-name \"vue-prism-component.common.js\" --format cjs" | ||
@@ -32,2 +32,3 @@ }, | ||
"prismjs": "^1.6.0", | ||
"vue": "^3.0.4", | ||
"xo": "^0.18.0" | ||
@@ -34,0 +35,0 @@ }, |
# vue-prism-component | ||
[](https://npmjs.com/package/vue-prism-component) [](https://npmjs.com/package/vue-prism-component) [](https://circleci.com/gh/egoist/vue-prism-component/tree/master) [](https://github.com/egoist/donate) | ||
[](https://npmjs.com/package/vue-prism-component) [](https://npmjs.com/package/vue-prism-component) [](https://github.com/egoist/vue-prism-component/actions?query=workflow%3A%22Release+Package%22) [](https://github.com/sponsors/egoist) | ||
@@ -5,0 +5,0 @@ ## Install |
Sorry, the diff of this file is not supported yet
11419
-5.72%5
25%99
-14.66%