diff options
author | HampusM <hampus@hampusmat.com> | 2021-06-05 19:37:52 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-06-05 19:37:52 +0200 |
commit | 4da3272bf7893760f6710c9a1ec7de02358136e6 (patch) | |
tree | 92eb961bf20a7ef9f7c0650ba288baf512986fca /packages/client/src/components/RepositoryTreeBlob.vue | |
parent | 4e3074dfd752dd52951d300090c642aee76cfaac (diff) |
Reorganized into a monorepo, refactored the frontend again, goodbye Parcel
Diffstat (limited to 'packages/client/src/components/RepositoryTreeBlob.vue')
-rw-r--r-- | packages/client/src/components/RepositoryTreeBlob.vue | 71 |
1 files changed, 71 insertions, 0 deletions
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> |