From 4da3272bf7893760f6710c9a1ec7de02358136e6 Mon Sep 17 00:00:00 2001
From: HampusM <hampus@hampusmat.com>
Date: Sat, 5 Jun 2021 19:37:52 +0200
Subject: Reorganized into a monorepo, refactored the frontend again, goodbye
 Parcel

---
 .../client/src/components/RepositoryTreeBlob.vue   | 71 ++++++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 packages/client/src/components/RepositoryTreeBlob.vue

(limited to 'packages/client/src/components/RepositoryTreeBlob.vue')

diff --git a/packages/client/src/components/RepositoryTreeBlob.vue b/packages/client/src/components/RepositoryTreeBlob.vue
new file mode 100644
index 0000000..2da00ed
--- /dev/null
+++ b/packages/client/src/components/RepositoryTreeBlob.vue
@@ -0,0 +1,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>
-- 
cgit v1.2.3-18-g5258

