Vue.js syntax highlighting made easy, using highlight.js.
Simply install the npm package vue-highlightjs
:
npm install --save vue-highlightjs
In your main JavaScript file (eg. main.js
):
// Import Vue and vue-highlgihtjs
import Vue from 'vue'
import VueHighlightJS from 'vue-highlightjs'
// Tell Vue.js to use vue-highlightjs
Vue.use(VueHighlightJS)
In your template, in order to highlight javascript code:
<!-- If your code lives in a variable called 'sourcecode' -->
<pre v-highlightjs="sourcecode"><code class="javascript"></code></pre>
<!-- If you want to highlight hardcoded code -->
<pre v-highlightjs><code class="javascript">const s = new Date().toString()</code></pre>
Any sort of contributions and feedback is much appreciated. Just leave an issue or pull-request!
This project uses the AirBnB code style.
Please run npm run lint
and npm run test
before you submit a pull request! <3
Author: Chris Hager chris@linuxuser.at (https://www.metachris.com)
License: MIT
Contributors:
v1.3.3
v1.3.1
const
to var
for compatibility with PhantomJS and UglifyJSv1.2.2
Author: metachris
GitHub: https://github.com/metachris/vue-highlightjs
#vuejs #javascript #vue #vue-js