-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathmarkdown-diff.vue
More file actions
142 lines (120 loc) · 3.03 KB
/
Copy pathmarkdown-diff.vue
File metadata and controls
142 lines (120 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<template>
<div class="markdown-diff-tool">
<div flex justify-center mb-4>
<c-buttons-select
v-model:value="mode"
:options="modeOptions"
size="small"
/>
</div>
<c-card v-if="mode === 'code'" w-full important:flex-1 important:pa-0>
<c-diff-editor
v-model:original="sourceMarkdown"
v-model:modified="targetMarkdown"
test-id="markdown-diff-editor"
language="markdown"
height="clamp(620px, 72vh, 820px)"
/>
</c-card>
<c-card v-else data-test-id="markdown-preview" w-full>
<div class="markdown-preview-grid">
<section>
<h3>Source Markdown</h3>
<div class="markdown-preview-pane" data-test-id="source-markdown-preview">
<c-markdown :markdown="sourceMarkdown" />
</div>
</section>
<section>
<h3>Modified Markdown</h3>
<div class="markdown-preview-pane" data-test-id="modified-markdown-preview">
<c-markdown :markdown="targetMarkdown" />
</div>
</section>
</div>
</c-card>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { modifiedMarkdown, originalMarkdown } from './markdown-diff.constants';
type MarkdownDiffMode = 'code' | 'preview';
const mode = ref<MarkdownDiffMode>('code');
const sourceMarkdown = ref(originalMarkdown);
const targetMarkdown = ref(modifiedMarkdown);
const modeOptions: Array<{ label: string; value: MarkdownDiffMode }> = [
{ label: 'Code', value: 'code' },
{ label: 'Preview', value: 'preview' },
];
</script>
<style lang="less" scoped>
.markdown-preview-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 24px;
section {
min-width: 0;
}
h3 {
margin: 0 0 12px;
font-size: 18px;
font-weight: 600;
}
}
.markdown-diff-tool {
width: 100%;
max-width: 1200px;
flex: 1 1 1200px !important;
}
.markdown-preview-pane {
min-height: clamp(620px, 72vh, 820px);
padding: 18px;
border: 1px solid #d8dee8;
border-radius: 8px;
overflow: auto;
}
:deep(.markdown-preview-pane) {
line-height: 1.65;
}
:deep(.markdown-preview-pane > div > *:first-child) {
margin-top: 0;
}
:deep(.markdown-preview-pane > div > *:last-child) {
margin-bottom: 0;
}
:deep(.markdown-preview-pane table) {
width: 100%;
border-collapse: collapse;
margin: 16px 0;
}
:deep(.markdown-preview-pane th),
:deep(.markdown-preview-pane td) {
padding: 10px 12px;
border: 1px solid #cfd6e2;
text-align: left;
}
:deep(.markdown-preview-pane th) {
font-weight: 600;
background: rgb(248 250 252);
}
:deep(.markdown-preview-pane code) {
padding: 2px 5px;
border-radius: 4px;
background: rgb(241 245 249);
}
:deep(.markdown-preview-pane pre) {
padding: 14px;
border-radius: 6px;
overflow: auto;
background: rgb(15 23 42);
}
:deep(.markdown-preview-pane pre code) {
padding: 0;
color: rgb(226 232 240);
background: transparent;
}
@media (max-width: 900px) {
.markdown-preview-grid {
grid-template-columns: 1fr;
}
}
</style>