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
|
8 | yarn add vue-prism-component
|
9 | ```
|
10 |
|
11 | CDN: [UNPKG](https://unpkg.com/vue-prism-component/dist/) | [jsDelivr](https://cdn.jsdelivr.net/npm/vue-prism-component/dist/)
|
12 |
|
13 | ## Usage
|
14 |
|
15 | First you need to load `Prism` somewhere in your app:
|
16 |
|
17 | ```js
|
18 | // yarn add prismjs
|
19 | import 'prismjs'
|
20 | import 'prismjs/themes/prism.css'
|
21 | ```
|
22 |
|
23 | OR:
|
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 |
|
30 | Then In SFC:
|
31 |
|
32 | ```vue
|
33 | <template>
|
34 | <prism language="javascript">{{ code }}</prism>
|
35 | </template>
|
36 |
|
37 | <script>
|
38 | import Prism from 'vue-prism-component'
|
39 |
|
40 | export default {
|
41 | data() {
|
42 | return {
|
43 | code: 'const a = b'
|
44 | }
|
45 | },
|
46 | components: {
|
47 | Prism
|
48 | }
|
49 | }
|
50 | </script>
|
51 | ```
|
52 |
|
53 | Or In JSX:
|
54 |
|
55 | ```js
|
56 | <Prism language="html">{`
|
57 | <div>
|
58 | <strong>foo</strong>
|
59 | </div>
|
60 | `}</Prism>
|
61 | ```
|
62 |
|
63 | For inline rendering, pass the `inline` prop:
|
64 |
|
65 | ```js
|
66 | <Prism inline language="javascript" >alert("foo");</Prism>
|
67 | ```
|
68 |
|
69 | You can also set the code using a prop:
|
70 |
|
71 | ```js
|
72 | import '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 |
|
84 | 1. Fork it!
|
85 | 2. Create your feature branch: `git checkout -b my-new-feature`
|
86 | 3. Commit your changes: `git commit -am 'Add some feature'`
|
87 | 4. Push to the branch: `git push origin my-new-feature`
|
88 | 5. 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>
|
94 | Authored 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)
|