|
1 | | -# vue-diff |
| 1 | +# vue-diff |
| 2 | + |
| 3 | +Vue diff viewer plugin |
| 4 | + |
| 5 | +> ⚠️ This plugin supports only Vue3 |
| 6 | +> Vue2 doesn't have a support plan yet. |
| 7 | +
|
| 8 | +## Table of Contents |
| 9 | + |
| 10 | +- [Introduction](#introduction) |
| 11 | +- [Features](#features) |
| 12 | +- [Install plugin](#install-plugin) |
| 13 | + * [Options](#options) |
| 14 | +- [Usage diff viewer](#usage-diff-viewer) |
| 15 | + * [props](#props) |
| 16 | +- [Custom theme](#custom-theme) |
| 17 | +- [Extend languages](#extend-languages) |
| 18 | + |
| 19 | +## Introduction |
| 20 | + |
| 21 | +<img src="https://user-images.githubusercontent.com/25652218/104695609-60533c80-5750-11eb-85dd-0e7d0d79d5ac.png" alt="screenshot" style="max-width:100%;"> |
| 22 | + |
| 23 | +You can see the difference between the two codes with the `vue-diff` plugin. |
| 24 | +This plugin dependent on <a href="https://github.com/kpdecker/jsdiff">diff</a> and <a href="https://github.com/highlightjs/highlight.js/">highlight.js</a>, shows similar results to other diff viewers (e.g., Github Desktop). |
| 25 | +Please see the <a href="https://hoiheart.github.io/vue-diff/demo/index.html" target="_blank" style="font-size: 1.2em; text-decoration: underline;">demo</a> |
| 26 | + |
| 27 | +## Features |
| 28 | + |
| 29 | +* [x] Support split / unified mode |
| 30 | +* [x] Support some languages and can be extended |
| 31 | +* [X] Support two themes (dark / light) and can be customized |
| 32 | +* [ ] Support IE11 (IE 11 support for Vue@3 is still pending) |
| 33 | + |
| 34 | +## Install plugin |
| 35 | + |
| 36 | +```bash |
| 37 | +npm install vue-diff |
| 38 | +``` |
| 39 | + |
| 40 | +install plugin in vue application |
| 41 | + |
| 42 | +```ts |
| 43 | +import VueDiff from 'vue-diff' |
| 44 | +// import VueDiff from 'vue-diff/dist/index.es5' // If need to use es5 build |
| 45 | +import 'vue-diff/dist/index.css' |
| 46 | + |
| 47 | +app.use(VueDiff) |
| 48 | +``` |
| 49 | +### Options |
| 50 | + |
| 51 | +```ts |
| 52 | +app.use(VueDiff, { |
| 53 | + componentName: 'VueDiff' |
| 54 | +}) |
| 55 | +``` |
| 56 | + |
| 57 | +| name | type | detault | description | |
| 58 | +|- | - | - | - | |
| 59 | +| componentName | `string` | `'Diff'` | Global diff component name | |
| 60 | + |
| 61 | +## Usage diff viewer |
| 62 | + |
| 63 | +Insert the diff component with props. |
| 64 | + |
| 65 | +```vue |
| 66 | +<template> |
| 67 | + <Diff |
| 68 | + :mode="mode" |
| 69 | + :theme="theme" |
| 70 | + :language="language" |
| 71 | + :prev="prev" |
| 72 | + :current="current" |
| 73 | + /> |
| 74 | +</template> |
| 75 | +``` |
| 76 | + |
| 77 | +### props |
| 78 | + |
| 79 | +| name | type | detault | values | description |
| 80 | +|- | - | - | - |- | |
| 81 | +| mode | `string` | `split` | `split`, `unified` | |
| 82 | +| theme | `string` | `dark` | `dark`, `light` | See <a href="#custom-theme">Custom theme</a> |
| 83 | +| language | `string` | `plaintext` | | See <a href="#extend-languages">Extend languages</a> |
| 84 | +| prev | `string` | `''` | | Prev code | |
| 85 | +| current | `string` | `''` | | Current Code | |
| 86 | + |
| 87 | +## Custom theme |
| 88 | + |
| 89 | +`vue-diff` uses the following <a href="https://github.com/highlightjs/highlight.js/tree/master/src/styles">highlight.js themes</a> and can be customized. |
| 90 | + |
| 91 | +* dark: `highlight.js/scss/monokai.scss` |
| 92 | +* light: `highlight.js/scss/vs.scss` |
| 93 | + |
| 94 | +```bash |
| 95 | +npm install highlight.js |
| 96 | +``` |
| 97 | + |
| 98 | +```vue |
| 99 | +<template> |
| 100 | + <Diff |
| 101 | + :mode="mode" |
| 102 | + theme="custom" |
| 103 | + :language="language" |
| 104 | + :prev="prev" |
| 105 | + :current="current" |
| 106 | + /> |
| 107 | +</template> |
| 108 | +
|
| 109 | +<style lang="scss"> |
| 110 | +.vue-diff-theme-custom { |
| 111 | + @import 'highlight.js/scss/vs2015.scss'; // import theme |
| 112 | +
|
| 113 | + background-color: #000; // Set background color |
| 114 | +} |
| 115 | +</style> |
| 116 | +``` |
| 117 | + |
| 118 | +## Extend languages |
| 119 | + |
| 120 | +`vue-diff` supports the following languages and can be extended through <a href="https://github.com/highlightjs/highlight.js/#es6-modules">highlight.js language registration.</a> |
| 121 | + |
| 122 | +* `css` |
| 123 | +* `xml` |
| 124 | +* `markdown` |
| 125 | +* `javascript` |
| 126 | +* `json` |
| 127 | +* `plaintext` |
| 128 | +* `typescript` |
| 129 | + |
| 130 | +```ts |
| 131 | +import VueDiff from 'vue-diff' |
| 132 | +import 'vue-diff/dist/index.css' |
| 133 | + |
| 134 | +// extend yaml language |
| 135 | +import yaml from 'highlight.js/lib/languages/yaml' |
| 136 | + |
| 137 | +VueDiff.hljs.registerLanguage('yaml', yaml) |
| 138 | + |
| 139 | +app.use(VueDiff) |
| 140 | +``` |
0 commit comments