• Stars
    star
    206
  • Rank 184,281 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 3 years ago

Reviews

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

Repository Details

📜 Highlight.js syntax highlighter component for Vue.

Vue Highlight.js

license vue 2 npm npm Travis Codacy grade TSLint


💡 Version 4 with Highlight.js v10 support is under development. See version-4 branch.


📜 Highlight.js syntax highlighter component for Vue.

⚙ī¸ Installation

Via npm:

npm

npm install highlight.js vue-highlight.js

Or Yarn:

yarn add highlight.js vue-highlight.js

For TypeScript, Please install @types/highlight.js.

npm install --save-dev @types/highlight.js
# or
yarn add --dev @types/highlight.js

đŸŽŦ Demo

Go to https://gluons.github.io/vue-highlight.js

🛂 Usage

Main file:

There are 2 ways to import Highlight.js languages.

  1. Import only languages that you want.

    import Vue from 'vue';
    import VueHighlightJS from 'vue-highlight.js';
    
    // Highlight.js languages (Only required languages)
    import css from 'highlight.js/lib/languages/css';
    import javascript from 'highlight.js/lib/languages/javascript';
    import vue from 'vue-highlight.js/lib/languages/vue';
    
    /*
    * Import Highlight.js theme
    * Find more: https://highlightjs.org/static/demo/
    */
    import 'highlight.js/styles/default.css';
    
    import App from './App';
    
    /*
    * Use Vue Highlight.js
    */
    Vue.use(VueHighlightJS, {
    	// Register only languages that you want
    	languages: {
    		css,
    		javascript,
    		vue
    	}
    });
    
    new Vue({
    	el: '#app',
    	render: h => h(App)
    });
  2. Import all languages.

    import Vue from 'vue';
    import VueHighlightJS from 'vue-highlight.js';
    
    // Highlight.js languages (All languages)
    import 'vue-highlight.js/lib/allLanguages'
    
    /*
    * Import Highlight.js theme
    * Find more: https://highlightjs.org/static/demo/
    */
    import 'highlight.js/styles/default.css';
    
    import App from './App';
    
    /*
    * Use Vue Highlight.js
    */
    Vue.use(VueHighlightJS);
    
    new Vue({
    	el: '#app',
    	render: h => h(App)
    });

Vue file:

<template>
	<div id="app">
		<!-- Code Block -->
		<highlight-code lang="javascript">
			let str = 'Hello, World!';
			console.log(str);
		</highlight-code>

		<!-- Inline Code Block -->
		<highlight-code lang="javascript" inline>alert('Hello, World!');</highlight-code>
	</div>
</template>

<script>
// JavaScript...
</script>

<style>
/* StyleSheet... */
</style>

⛕ Plugin Options

languages

Type: { [name: string]: HLJSLang }
Default: {}

Highlight.js languages.
Add the languages that you want to use here.

name is the name of language to register with Highlight.js' registerLanguage(name, language) API.

See https://github.com/isagalaev/highlight.js#commonjs about importing each language from highlight.js.

📚 API

<highlight-code>

Highlight.js code block.

🔰 Slots

Static code content.

🔰 Properties

lang

Type: String

Highlight.js language.

inline

Type: Boolean
Default: false

Enable inline code block when set it to true.

code

Type: String

Code content in code block.

You can use this prop if you want to bind code content to your data source.
It's useful for dynamic code content.

Component will ignore slot static content if you use this.

auto

Type: Boolean

Enable auto detecting code language.

Code will be detected by highlight.js' highlightAuto function.

auto will work well when you import all Highlight.js languages.

Component will ignore lang prop if you use auto.

❓ FAQ

  • How to write HTML code inside slot?

    You have to escape all HTML tags before add it into slot.
    If you didn't do that, browser will interpret those tags as HTML element.
    ℹī¸ See isagalaev/highlight.js#866

    If you use code property instead of slot, you don't need to worry about this.
    Vue Highlight.js will automatically escape it for you.

  • Why did I get SyntaxError: Unterminated template literal error when used <script></script> in code property?

    If you add </script> at anywhere inside script tag, although it's a string inside quotes, it will always close the script tag.
    ℹī¸ See "Unterminated template literal" syntax error when literal contains script tag

More Repositories

1

powershell-git-aliases

:octocat: Oh My Zsh's Git aliases for PowerShell.
PowerShell
376
star
2

vue-thailand-address

🇹🇭 Thai address input for Vue.
TypeScript
58
star
3

vue-github-buttons

:octocat: GitHub buttons component for Vue.
TypeScript
37
star
4

vue-gh-corners

:octocat: GitHub Corners for Vue.
Vue
29
star
5

vuex-typescript-example

Vuex with TypeScript example.
TypeScript
17
star
6

Font-Awesome-Icon-Chars

The list of Font Awesome icon unicode characters in several file format.
TypeScript
13
star
7

vue-up

🎀 Bundle @vuejs library via @rollup.
TypeScript
8
star
8

download-directory-helper

📁 A Firefox add-on to use download-directory easily.
TypeScript
7
star
9

gridsome-plugin-pug

@pugjs plugin for @gridsome.
TypeScript
6
star
10

npm-reinstall

🔄 Just reinstall NPM package.
TypeScript
4
star
11

poi-plugin-resolve-alias

Use your custom resolve alias in ⚡ī¸ Poi.
JavaScript
3
star
12

browserslist-config-vue

🔎 A @browserslist shareable config for @vuejs.
JavaScript
3
star
13

vue-pack

🎀 Bundle @vuejs library via @webpack.
TypeScript
2
star
14

NoGithubDarkMode-Firefox

:octocat: Bring back the old GitHub menu bar.
CSS
2
star
15

vue-radio-toggle-buttons

🔘 Radio toggle buttons for Vue.
Vue
2
star
16

ConfC

🆕 Start new project with your default configs.
TypeScript
2
star
17

vscode-atom-javascript-snippet

:atom: Atom JavaScript Snippet for Visual Studio Code.
2
star
18

NVL

🚮 Replace a blank value with fallback value.
TypeScript
2
star
19

gridsome-plugin-ts

TypeScript plugin for @gridsome.
TypeScript
2
star
20

AMO-Add-to-Collection-Stylish

Force AMO (addons.mozilla.org) to reveal Favorites and Add to Collection buttons. (🚮 Deprecated)
CSS
2
star
21

dotfiles

⚙ī¸ My personal dotfiles.
PowerShell
2
star
22

EVL

😈 Function fallback when error.
TypeScript
1
star
23

generator-gluons

@gluons' personal scaffolding generator.
JavaScript
1
star
24

setup

🛠ī¸ My personal setup scripts for my laptop.
Shell
1
star
25

cle

A simple CLI tool to completely clear terminal screen.
Ruby
1
star
26

figures.dart

Unicode symbols for Dart.
Dart
1
star
27

vscode-ramda-theme

🐏 Ramda REPL theme for Visual Studio Code.
1
star
28

template-gluons

@gluons' personal SAO scaffolding template.
JavaScript
1
star
29

ConfC.gem

🆕 Start new project with your default configs. (💎 Ruby version)
Ruby
1
star
30

tslint-config-gluons

@gluons' personal TSLint shareable config.
TypeScript
1
star
31

stylelint-config-gluons

@gluons' personal stylelint shareable config.
JavaScript
1
star
32

eslint-config-gluons

@gluons' personal @eslint shareable config.
TypeScript
1
star
33

cson-json-converter

🔃 An online CSON - JSON converter. (Mirror from https://gitlab.com/gluons/cson-json-converter)
Vue
1
star
34

rollup-vue-example

An example of bundling @vuejs library with @rollup.
JavaScript
1
star
35

gulp-json2cson

Gulp plugin to parse JSON to CSON
CoffeeScript
1
star