vue-prism-component

highlight code using prism.js and vue component.

Install

yarn add vue-prism-component
Bash

Usage

First you need to load Prism somewhere in your app:

// yarn add prismjs
import 'prismjs'
import 'prismjs/themes/prism.css'
Js

OR:

<link rel="stylesheet" href="https://unpkg.com/prismjs/themes/prism.css" />
<script src="https://unpkg.com/prismjs"></script>
HTML

Then In SFC:

<template>
  <prism language="javascript">{{ code }}</prism>
</template>

<script>
import Prism from 'vue-prism-component'

export default {
  data() {
    return {
      code: 'const a = b'
    }
  },
  components: {
    Prism
  }
}
</script>
Vue

Or In JSX:

<Prism language="html">{`
  <div>
    <strong>foo</strong>
  </div>
`}</Prism>
Js

For inline rendering, pass the inline prop:

<Prism inline language="javascript" >alert("foo");</Prism>
Js

You can also set the code using a prop:

import 'prismjs/components/prism-rust'

<Prism language="rust" code={ myRustCode } />
Js

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

vue-prism-component © egoist, Released under the MIT License.

Authored and maintained by egoist with help from contributors (list).

GitHub

highlight code using prism.js and vue componentRead More

Latest commit to the master branch on 8-12-2023
Download as zip