blob: 2da00edf7544f2d55f4e2a38b511e4a325cbdee9 (
plain)
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
|
<template>
<table cellspacing="0px">
<tbody>
<tr v-for="(line, index) in content_lines" :key="index">
<td :line="index + 1" />
<td>
<code v-html="line" />
</td>
</tr>
</tbody>
</table>
</template>
<script>
import { ref } from "vue";
import hljs from "highlight.js";
import hljs_languages from "../util/hljs-languages";
import path from "path";
export default {
name: "RepositoryTreeBlob",
props: {
repository: {
type: String,
required: true
},
path: {
type: String,
required: true
},
content: {
type: String,
required: true
}
},
watch: {
content() {
this.initHighlightedContent();
}
},
mounted() {
this.initHighlightedContent();
},
setup(props) {
const content_lines = ref([]);
const initHighlightedContent = async() => {
const language = hljs_languages.find((lang) => lang.extensions.some((extension) => path.extname(props.path) === extension));
const highlighted = language ? hljs.highlight(props.content, { language: language.name }) : hljs.highlightAuto(props.content);
content_lines.value = highlighted.value.split("\n");
};
return { content_lines, initHighlightedContent };
}
};
</script>
<style lang="scss">
@import "~highlight.js/scss/srcery.scss";
code {
white-space: pre-wrap;
word-wrap: anywhere;
}
[line]::before {
content: attr(line);
padding-right: 10px;
}
</style>
|