Skip to content

Commit 76c5987

Browse files
committed
update hljs, add dedicated renderer component
1 parent c4044de commit 76c5987

File tree

3 files changed

+87
-6
lines changed

3 files changed

+87
-6
lines changed

packages/vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"url-parse": "1.5.10"
2323
},
2424
"dependencies": {
25-
"@highlightjs/vue-plugin": "^2.1.0",
25+
"@highlightjs/vue-plugin": "^2.1.2",
2626
"@mdi/font": "^7.3.67",
2727
"@nilock2/pouchdb-authentication": "^1.0.2",
2828
"@tonaljs/tonal": "^3.6.0",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<template>
2+
<div class="code-block-wrapper pa-2">
3+
<div class="language-indicator" v-if="language">{{ language }}</div>
4+
<highlightjs :language="language" :code="code" />
5+
</div>
6+
</template>
7+
8+
<script setup lang="ts">
9+
import hljs from 'highlight.js/lib/core';
10+
import hljsVuePlugin from '@highlightjs/vue-plugin';
11+
import { getCurrentInstance } from 'vue';
12+
13+
// Import only the languages you need
14+
import javascript from 'highlight.js/lib/languages/javascript';
15+
import typescript from 'highlight.js/lib/languages/typescript';
16+
import css from 'highlight.js/lib/languages/css';
17+
import html from 'highlight.js/lib/languages/xml';
18+
import bash from 'highlight.js/lib/languages/bash';
19+
import json from 'highlight.js/lib/languages/json';
20+
import go from 'highlight.js/lib/languages/go';
21+
import python from 'highlight.js/lib/languages/python';
22+
23+
// Register languages
24+
hljs.registerLanguage('js', javascript);
25+
hljs.registerLanguage('javascript', javascript);
26+
hljs.registerLanguage('ts', typescript);
27+
hljs.registerLanguage('typescript', typescript);
28+
hljs.registerLanguage('css', css);
29+
hljs.registerLanguage('html', html);
30+
hljs.registerLanguage('bash', bash);
31+
hljs.registerLanguage('sh', bash);
32+
hljs.registerLanguage('json', json);
33+
hljs.registerLanguage('go', go);
34+
hljs.registerLanguage('golang', go);
35+
hljs.registerLanguage('python', python);
36+
37+
// Get access to the current component instance
38+
const instance = getCurrentInstance();
39+
if (instance) {
40+
// Register the component locally
41+
instance.appContext.app.component('highlightjs', hljsVuePlugin.component);
42+
}
43+
44+
const props = defineProps({
45+
code: {
46+
type: String,
47+
required: true,
48+
},
49+
language: {
50+
type: String,
51+
default: '',
52+
},
53+
});
54+
</script>
55+
56+
<style>
57+
/* Import a highlight.js theme */
58+
@import 'highlight.js/styles/github.css';
59+
60+
.code-block-wrapper {
61+
margin: 1rem 0;
62+
border-radius: 4px;
63+
background-color: #f6f8fa;
64+
overflow: auto;
65+
position: relative;
66+
}
67+
68+
.language-indicator {
69+
position: absolute;
70+
top: 8px;
71+
right: 10px;
72+
padding: 2px 8px;
73+
font-size: 0.75rem;
74+
color: #666;
75+
background-color: rgba(255, 255, 255, 0.7);
76+
border-radius: 4px;
77+
z-index: 1;
78+
font-family: monospace;
79+
text-transform: lowercase;
80+
}
81+
</style>

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,13 +2228,13 @@ __metadata:
22282228
languageName: node
22292229
linkType: hard
22302230

2231-
"@highlightjs/vue-plugin@npm:^2.1.0":
2232-
version: 2.1.0
2233-
resolution: "@highlightjs/vue-plugin@npm:2.1.0"
2231+
"@highlightjs/vue-plugin@npm:^2.1.2":
2232+
version: 2.1.2
2233+
resolution: "@highlightjs/vue-plugin@npm:2.1.2"
22342234
peerDependencies:
22352235
highlight.js: ^11.0.1
22362236
vue: ^3
2237-
checksum: 10c0/c2f71940606319d8505c2adcc552ae57a48fb3ac19a2b495ea716ced1cc0828db17226b0912c8698f7e112cdad74b4fc9eb450f68cbd800eb91f1cced56f275b
2237+
checksum: 10c0/418b5142398aaf187a85e4f23f5ffaceee210b4a72678a77d841e973963e5791fc927c412153bf0cacfcdbc35e04d2b7c7eedf17d241295306e956697ae9c675
22382238
languageName: node
22392239
linkType: hard
22402240

@@ -4948,7 +4948,7 @@ __metadata:
49484948
dependencies:
49494949
"@babel/core": "npm:^7.26.9"
49504950
"@babel/plugin-proposal-class-static-block": "npm:^7.21.0"
4951-
"@highlightjs/vue-plugin": "npm:^2.1.0"
4951+
"@highlightjs/vue-plugin": "npm:^2.1.2"
49524952
"@mdi/font": "npm:^7.3.67"
49534953
"@nilock2/pouchdb-authentication": "npm:^1.0.2"
49544954
"@testing-library/jest-dom": "npm:^6.6.3"

0 commit comments

Comments
 (0)