-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffCode.vue
More file actions
36 lines (33 loc) · 1.26 KB
/
Copy pathDiffCode.vue
File metadata and controls
36 lines (33 loc) · 1.26 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
<template>
<!--
Highlighted markup must be injected as HTML: nothing else preserves both
syntax spans and word-diff spans on the same line. Every path into `html`
escapes first — plain text via escapeHtml, highlighted output via
spansToHtml — and both are covered by XSS tests in escape.spec.ts and
compose.spec.ts. This is the only v-html in the library.
-->
<!-- eslint-disable-next-line vue/no-v-html -->
<pre><code class="vue-diff-code" v-html="html"></code></pre>
</template>
<script setup lang="ts">
import { useHighlight } from '../composables/useHighlight';
const props = withDefaults(
defineProps<{
code: string;
language?: string;
/** Counterpart text to word-diff against. */
counterpart?: string;
/** Whether this line participates in word-level diffing. */
words?: boolean;
}>(),
{ language: 'plaintext', counterpart: undefined, words: false },
);
// v-html is safe here only because every path through useHighlight escapes:
// the interim plain text via escapeHtml, the final markup via spansToHtml.
const { html } = useHighlight(() => ({
value: props.code,
language: props.language,
counterpart: props.counterpart,
words: props.words,
}));
</script>