Skip to content

Commit d41062f

Browse files
committed
refactor: Reuse full Djot grammar for playground highlighting
Create ES module version of hljs-djot grammar and import it in the playground instead of duplicating a simplified version.
1 parent 710b58b commit d41062f

2 files changed

Lines changed: 418 additions & 25 deletions

File tree

docs/.vitepress/components/DjotPlayground.vue

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,13 @@
11
<script setup lang="ts">
22
import { ref, watch, onMounted, nextTick } from 'vue'
33
import hljs from 'highlight.js'
4+
import hljsDjot from '../hljs-djot'
45
56
// Register Djot language for syntax highlighting
6-
function registerDjotLanguage() {
7-
if (hljs.getLanguage('djot')) return
8-
9-
hljs.registerLanguage('djot', () => ({
10-
name: 'Djot',
11-
aliases: ['djot'],
12-
case_insensitive: false,
13-
contains: [
14-
{ className: 'section', begin: /^#{1,6}\s/, end: /$/ },
15-
{ className: 'emphasis', begin: /(?<!\w)_(?!\s)/, end: /_(?!\w)/ },
16-
{ className: 'strong', begin: /(?<!\w)\*(?!\s)/, end: /\*(?!\w)/ },
17-
{ className: 'code', begin: /`+/, end: /`+/ },
18-
{ className: 'link', begin: /\[[^\]]*\]\([^)]*\)/ },
19-
{ className: 'quote', begin: /^>/, end: /$/ },
20-
{ className: 'bullet', begin: /^[ \t]*[-*+](?=\s)/ },
21-
{ className: 'bullet', begin: /^[ \t]*\d+[.)](?=\s)/ },
22-
{ className: 'keyword', begin: /^`{3,}\s*[a-zA-Z]*$/ },
23-
{ className: 'attr', begin: /\{(?![=+\-%])[^}]+\}/ },
24-
{ className: 'addition', begin: /\{=/, end: /=\}/ },
25-
{ className: 'addition', begin: /\{\+/, end: /\+\}/ },
26-
{ className: 'deletion', begin: /\{-/, end: /-\}/ },
27-
],
28-
}))
7+
if (!hljs.getLanguage('djot')) {
8+
hljs.registerLanguage('djot', hljsDjot)
299
}
3010
31-
registerDjotLanguage()
32-
3311
const SANDBOX_URL = 'https://sandbox.dereuromark.de/sandbox/djot'
3412
3513
const djotInput = ref(`# Welcome to Djot

0 commit comments

Comments
 (0)