UNPKG

2.5 kBMarkdownView Raw
1# vue-prism-component
2
3[![NPM version](https://img.shields.io/npm/v/vue-prism-component.svg?style=flat)](https://npmjs.com/package/vue-prism-component) [![NPM downloads](https://img.shields.io/npm/dm/vue-prism-component.svg?style=flat)](https://npmjs.com/package/vue-prism-component) [![Release Package](https://github.com/egoist/vue-prism-component/workflows/Release%20Package/badge.svg)](https://github.com/egoist/vue-prism-component/actions?query=workflow%3A%22Release+Package%22) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/sponsors/egoist)
4
5## Install
6
7```bash
8yarn add vue-prism-component
9```
10
11CDN: [UNPKG](https://unpkg.com/vue-prism-component/dist/) | [jsDelivr](https://cdn.jsdelivr.net/npm/vue-prism-component/dist/)
12
13## Usage
14
15First you need to load `Prism` somewhere in your app:
16
17```js
18// yarn add prismjs
19import 'prismjs'
20import 'prismjs/themes/prism.css'
21```
22
23OR:
24
25```html
26<link rel="stylesheet" href="https://unpkg.com/prismjs/themes/prism.css" />
27<script src="https://unpkg.com/prismjs"></script>
28```
29
30Then In SFC:
31
32```vue
33<template>
34 <prism language="javascript">{{ code }}</prism>
35</template>
36
37<script>
38import Prism from 'vue-prism-component'
39
40export default {
41 data() {
42 return {
43 code: 'const a = b'
44 }
45 },
46 components: {
47 Prism
48 }
49}
50</script>
51```
52
53Or In JSX:
54
55```js
56<Prism language="html">{`
57 <div>
58 <strong>foo</strong>
59 </div>
60`}</Prism>
61```
62
63For inline rendering, pass the `inline` prop:
64
65```js
66<Prism inline language="javascript" >alert("foo");</Prism>
67```
68
69You can also set the code using a prop:
70
71```js
72import 'prismjs/components/prism-rust'
73
74<Prism language="rust" code={ myRustCode } />
75```
76
77## Related
78
79- [vue-highlight-component](https://github.com/egoist/vue-highlight-component): highlight code using highlight.js and vue component.
80
81
82## Contributing
83
841. Fork it!
852. Create your feature branch: `git checkout -b my-new-feature`
863. Commit your changes: `git commit -am 'Add some feature'`
874. Push to the branch: `git push origin my-new-feature`
885. Submit a pull request :D
89
90
91## Author
92
93**vue-prism-component** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.<br>
94Authored and maintained by egoist with help from contributors ([list](https://github.com/egoist/vue-prism-component/contributors)).
95
96> [egoistian.com](https://egoistian.com) · GitHub [@egoist](https://github.com/egoist) · Twitter [@rem_rin_rin](https://twitter.com/rem_rin_rin)