Skip to content

Commit

Permalink
feat: add CodeReader component
Browse files Browse the repository at this point in the history
  • Loading branch information
Shimada666 committed Aug 29, 2024
1 parent 2880a13 commit 4cff7a7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/CodeReader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script setup lang="ts">
import CodeDiff from './CodeDiff.vue'
withDefaults(defineProps<{
language?: string
text: string
}>(), {
language: 'plaintext',
})
</script>

<template>
<CodeDiff
hide-header
:language="language"
:old-string="text"
:new-string="text"
/>
</template>

<style scoped>
.code-diff-view :deep(td:nth-child(1)) {
display: none;
}
</style>
2 changes: 2 additions & 0 deletions src/global.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import CodeDiff from './CodeDiff.vue'
import CodeReader from './CodeReader.vue'
import hljs from './highlight'

function install(app: any) {
app.component('CodeDiff', CodeDiff)
app.component('CodeReader', CodeReader)
}

export default {
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import CodeDiff from './CodeDiff.vue'
import CodeReader from './CodeReader.vue'
import hljs from './highlight'

function install(app: any) {
app.component('CodeDiff', CodeDiff)
app.component('CodeReader', CodeReader)
}

export {
CodeDiff,
CodeReader,
hljs,
}

Expand Down
3 changes: 3 additions & 0 deletions vue2-playground/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { reactive, version } from 'vue-demi'
import { CodeReader } from '../src/index'
const form = reactive({
oldString: '{\n "code": "200",\n "msg": "请求成功",\n "data": {\n "hitokoto": "往者不可谏,来者犹可追。",\n "from": "论语·微子篇"\n },\n "time": "2024-01-12 17:27:03"\n}',
Expand All @@ -25,6 +26,8 @@ const form = reactive({
:ignore-matching-lines="form.ignoreMatchingLines"
output-format="side-by-side"
/>
<hr>
<CodeReader :text="form.newString" :language="form.language" />
</div>
</template>

Expand Down
3 changes: 3 additions & 0 deletions vue2.7-playground/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import { version } from 'vue-demi'
import { reactive } from 'vue'
import { CodeReader } from '../src/index'
const form = reactive({
oldString: '{\n "code": "200",\n "msg": "请求成功",\n "data": {\n "hitokoto": "往者不可谏,来者犹可追。",\n "from": "论语·微子篇"\n },\n "time": "2024-01-12 17:27:03"\n}',
Expand All @@ -26,6 +27,8 @@ const form = reactive({
:ignore-matching-lines="form.ignoreMatchingLines"
output-format="side-by-side"
/>
<hr>
<CodeReader :text="form.newString" :language="form.language" />
</div>
</template>

Expand Down
4 changes: 3 additions & 1 deletion vue3-playground/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { version } from 'vue-demi'
import { reactive } from 'vue'
import c from 'highlight.js/lib/languages/c'
import { CodeDiff, hljs } from '../src/index'
import { CodeDiff, CodeReader, hljs } from '../src/index'
hljs.registerLanguage('c', c)
// import { oldLongText } from '../demo/text/old-long-text'
Expand Down Expand Up @@ -42,6 +42,8 @@ const form = reactive({
:diff-style="form.diffStyle"
:context="form.context"
/>
<hr>
<CodeReader :text="form.newString" :language="form.language" />
</template>

<style>
Expand Down

0 comments on commit 4cff7a7

Please sign in to comment.