
Security News
TypeScript Native Previews: 10x Faster Compiler Now on npm for Public Testing
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.
v-code-diff
Advanced tools
A code diff display plugin, available for Vue2 / Vue3.
English | 简体中文
Old Version:
0.x version, latest version 0.3.12 (traditional version, improved based on vue-code-diff, is no longer maintained. We will try to align the functionality of 0.x version in 1.x version and minimize migration cost as much as possible). This project references the following projects, and I would like to express my gratitude to the original authors!
install v-code-diff
# npm
npm i v-code-diff
# yarn
yarn add v-code-diff
# pnpm
pnpm add v-code-diff
Vue2 developers need install composition-api
pnpm add @vue/composition-api
import {createApp} from 'vue'
import CodeDiff from 'v-code-diff'
app
.use(CodeDiff)
.mount('#app')
然后
<template>
<code-diff
:old-string="'12345'"
:new-string="'3456'"
output-format="side-by-side"/>
</template>
Not recommended, but the relevant capabilities are retained to facilitate migration for 0.x users.
import Vue from 'vue';
import CodeDiff from 'v-code-diff'
Vue.use(CodeDiff);
Not recommended, but the relevant capabilities are retained to facilitate migration for 0.x users.
Prop | Description | Type | Optional Values | Default Value |
---|---|---|---|---|
language | Code language, such as typescript, defaults to plain text. View all supported languages | string | - | plaintext |
oldString | Old string | string | - | - |
newString | New string | string | - | - |
context | The number of lines to separate different parts so that they are not hidden | number | - | 10 |
outputFormat | Display mode | string | line-by-line,side-by-side | line-by-line |
diffStyle | Difference style, word-level differences or letter-level differences | string | word, char | word |
trim | Remove blank characters at the beginning and end of the string | boolean | - | false |
noDiffLineFeed | Don't diff Windows line feed (CRLF) and Linux line feed (LF) | boolean | - | false |
maxHeight | Maximum height of component, for example: 300px | string | - | undefined |
filename | Filename | string | - | undefined |
In order to reduce the size of the packaged file, the system only supports the following commonly used languages by default.
If the language you need is not included, you can manually import the relevant language highlighting module.
pnpm add highlight.js
import CodeDiff from 'v-code-diff';
// Extend C language
import c from 'highlight.js/lib/languages/c';
CodeDiff.hljs.registerLanguage('c', c);
The v-code-diff 1.x version has features such as reduced packaging size and improved performance compared to the 0.x version. And we will try to align the functions with the 0.x version as much as possible to reduce your migration cost.
Key points:
Below is a detailed comparison of the two versions, you can refer to it to complete the migration.
The component events are no longer provided in the 1.x version as rendering and highlighting are carried out simultaneously.
Event Name | Change Status |
---|---|
before-render | No longer provided |
after-render | No longer provided |
Prop | Description | Change Status |
---|---|---|
highlight | Control code highlighting | Removed in version 1.x |
language | Code language | None |
oldString | Old string | None |
newString | New string | None |
context | The number of lines to separate different parts so that they are not hidden | None |
output-format | Display mode | None |
diffStyle | Difference style, word-level differences or letter-level differences | None |
drawFileList | Display file comparison list | Removed in version 1.x |
renderNothingWhenEmpty | Do not render when there is no comparison | Removed in version 1.x |
fileName | File name | To be determined, not under development |
isShowNoChange | Display source code when there is no comparison | Removed as it became the default in version 1.x |
trim | Remove blank characters at the beginning and end of the string | None |
noDiffLineFeed | Don't diff Windows line feed (CRLF) and Linux line feed (LF) | None |
syncScroll
due to bug. Synchronized scrolling is now enabled by defaultsyncScroll
to control whether the horizontal scroll bar needs to be scrolled synchronously.d2h-wrapper
divd2h-file-header
, same as vue-code-diffnoDiffLineFeed
, do not diff windows line feed (CRLF) and linux line feed (LF)language
, make highlighting more accuratetrim
, it will remove the blank characters before and after the stringdiffStyle
to control whether to display word-level differences or char-level differencesbefore-render
, after-render
highlight
to control whether to highlight the code.context
default value changed from 5 to 10antd.css
in antd-vue)First Version.
MIT License
Copyright (c) 2021 Shimada666
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
template component for vue-demi, can dev and build
The npm package v-code-diff receives a total of 6,176 weekly downloads. As such, v-code-diff popularity was classified as popular.
We found that v-code-diff demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.
Research
Security News
Malicious npm packages targeting React, Vue, Vite, Node.js, and Quill remained undetected for two years while deploying destructive payloads.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.