1. vue-highlight-component
highlight code using highlight.js and vue component.
vue-highlight-component
Package: vue-highlight-component
Created by: egoist
Last modified: Mon, 23 May 2022 15:30:58 GMT
Version: 1.0.0
License: MIT
Downloads: 3,960
Repository: https://github.com/egoist/vue-highlight-component

Install

npm install vue-highlight-component
yarn add vue-highlight-component

vue-highlight-component

NPM version NPM downloads CircleCI donate

Install

 yarn add highlight.js vue-highlight-component

Usage

<template>
  <highlight language="swift">{{ code }}</highlight>
</template>

<script>
import hljs from 'highlight.js'
import Highlight from 'vue-Highlight-component'

// Register the language if it's not supported by default
hljs.registerLanguage('swift', require('highlight.js/lib/languages/swift'))

export default {
  data() {
    return {
      code: `your swift code...`
    }
  },
  components: {
    Highlight
  }
}
</script>

You can also use a prop code to set the code you wanna highlight:

<template>
  <highlight :code="code"></highlight>
</template>

Prop language is optional since highlight.js could automatically infer the language if it's not set.

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-highlight-component © egoist, Released under the MIT License.

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

egoistian.com · GitHub @egoist · Twitter @rem_rin_rin

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin