• Stars
    star
    197
  • Rank 197,722 (Top 4 %)
  • Language
    TypeScript
  • License
    BSD 3-Clause "New...
  • Created over 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Highlight.js Vue Plugin

Highlight.js plugin for Vue.js

latest version latest version vue 3 vue 2 license

publish size gzipped size slack

This plugin provides a highlightjs component for use in your Vue.js 3 applications:

<div id="app">
    <!-- bind to a data property named `code` -->
    <highlightjs autodetect :code="code" />
    <!-- or literal code works as well -->
    <highlightjs language='javascript' code="var x = 5;" />
</div>

Note: For Vue.js version 2 support see the 1-stable branch here on GitHub. Version 1.x.x is compatible with Vue.js v2; version 2.x.x with Vue.js v3.

Using the pre-built libraries

<link rel="stylesheet" href="/path/to/styles/default.css">
<script src="/path/to/highlight.min.js"></script>
<script src="/path/to/highlight-vue.min.js"></script>

Then simply register the plugin with Vue:

const app = createApp(App)
app.use(hljsVuePlugin)

Using ES6 modules / bundling

import 'highlight.js/styles/stackoverflow-light.css'
import hljs from 'highlight.js/lib/core';
import javascript from 'highlight.js/lib/languages/javascript';
import hljsVuePlugin from "@highlightjs/vue-plugin";

hljs.registerLanguage('javascript', javascript);

const app = createApp(App)
app.use(hljsVuePlugin)
app.mount('#app')

Note: The plugin imports highlight.js/lib/core internally (but no languages). Thanks to the magic of ES6 modules you can import Highlight.js anywhere to register languages or configure the library. Any import of Highlight.js refers to the same singleton instance of the library, so configuring the library anywhere configures it everywhere.

You can also simply load all "common" languages at once (as of v11):

import 'highlight.js/styles/stackoverflow-light.css'
import 'highlight.js/lib/common';
import hljsVuePlugin from "@highlightjs/vue-plugin";

const app = createApp(App)
app.use(hljsVuePlugin)
app.mount('#app')

Note that the highlight.js/lib/common import does not import the hljs object because it registers common languages internally and modern web bundlers like webpack will optimize out unused imported names. If you want to customize the hljs object, you can import it like the previous example.

Using component locally

<template>
    <highlightjs
        language="js"
        code="console.log('Hello World');"
    />
</template>

<script>
import 'highlight.js/lib/common';
import hljsVuePlugin from "@highlightjs/vue-plugin";

export default {
    components: {
        highlightjs: hljsVuePlugin.component
    }
}
</script>

Building the pre-built library from source

We use rollup to build the dist distributable.

npm run build

More Repositories

1

highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
JavaScript
23,602
star
2

highlightjs-solidity

JavaScript
47
star
3

cdn-release

Repository for autoupdating CDN build versions
JavaScript
42
star
4

highlightjs.org

The source code for the official highlightjs.org website, powered by Next.js
TypeScript
21
star
5

highlightjs-gdscript

highlight.js syntax definitions for Godot's GDscript language
JavaScript
21
star
6

highlightjs-structured-text

Highlightjs Structured Text language support IEC 61131-3
JavaScript
19
star
7

highlightjs-cshtml-razor

Highlight.js Razor CSHTML language repository
JavaScript
16
star
8

highlightjs-vue

highlight.js syntax definition for Vue.js
JavaScript
14
star
9

highlightjs-sap-abap

SAP ABAP language grammar for Highlight.js
JavaScript
11
star
10

highlightjs-cypher

Cypher language syntax highlighting plugin for highlight.js
JavaScript
11
star
11

base16-highlightjs

Base16 Template Repository for Highlight.js
CSS
9
star
12

highlightjs-4d

JavaScript
9
star
13

highlightjs-mde-languages

MDE language grammars for Highlight.js
JavaScript
8
star
14

highlightjs-curl

cURL grammar for Highlight.js
JavaScript
8
star
15

highlightjs-raku

Highlight.js grammar definition for Raku (Perl 6)
JavaScript
8
star
16

highlightjs-terraform

terraform language
JavaScript
7
star
17

highlightjs-bbcode

bbcode - a language grammar for highlight.js
JavaScript
7
star
18

highlightjs-tsql

JavaScript syntax highlighter for with zero dependencies for MS SQL Transact-SQL language
JavaScript
7
star
19

highlightjs-apex

Highlight.js grammar for Salesforce Apex language
JavaScript
6
star
20

highlightjs-func

Highlight.js grammar for FunC
JavaScript
5
star
21

highlightjs-robots-txt

robots.txt - a language grammar for highlight.js
JavaScript
5
star
22

highlightjs-shexc

JavaScript
4
star
23

highlightjs-robot

Robot Framework
JavaScript
4
star
24

highlightjs-mirc

mIRC language
JavaScript
3
star
25

highlightjs-c3

C3 - a language grammar for highlight.js
JavaScript
3
star
26

highlightjs-ballerina

Ballerina language grammar for Highlight.js
JavaScript
3
star
27

highlightjs-lang

A highlight.js grammar for Minecraft's language files
JavaScript
3
star
28

highlightjs-pythonlogging

Files to add to highlightjs/highlight.js (in respective locations) to build a highlighter for Python logs
JavaScript
3
star
29

highlightjs-web-idl

Web IDL language grammar for Highlight.js
JavaScript
2
star
30

highlightjs-extempore

Highlight.js Extempore language repository
JavaScript
2
star
31

highlightjs-lustre

Lustre language grammar for Highlight.js
JavaScript
2
star
32

highlightjs-rpm-specfile

JavaScript
2
star
33

highlightjs-turtle

Highlighting for the Turtle and SPARQL semantic web languages
JavaScript
2
star
34

highlightjs-mlir

Highlight.js grammar for MLIR
MLIR
2
star
35

highlightjs-hlsl

Highlight.js grammar for HLSL (High-level shader language)
JavaScript
2
star
36

highlightjs-supercollider

JavaScript
1
star
37

highlightjs-octave

A Highlight.js grammar for GNU Octave
JavaScript
1
star
38

highlightjs-dylan

highlight.js support for the Dylan language
JavaScript
1
star
39

highlightjs-zenscript

Zenscript language grammar for Highlight.js
JavaScript
1
star
40

highlightjs-metasploit

Metasploit language grammar for Highlight.js
1
star
41

highlightjs-iptables

Highlight.js grammar for iptables rules
JavaScript
1
star
42

highlightjs-logtalk

Logtalk language grammar for Highlight.js
1
star
43

highlightjs-closure-templates

Google Closure Templates (soy)
JavaScript
1
star
44

highlightjs-GN

GN is a meta-build system that generates build files for Ninja.
JavaScript
1
star