@@ -4,8 +4,8 @@ import { formatCode } from '@renderer/assets/js/format-code'
44import json from ' highlight.js/lib/languages/json'
55import yaml from ' highlight.js/lib/languages/yaml'
66import xml from ' highlight.js/lib/languages/xml'
7+ import { ref , watch , nextTick } from ' vue'
78import hljs from ' highlight.js/lib/core'
8- import { ref , watch } from ' vue'
99
1010hljs .registerLanguage (' json' , json )
1111hljs .registerLanguage (' xml' , xml )
@@ -21,6 +21,7 @@ const props = defineProps<Props>()
2121useHighlightTheme ()
2222
2323const highlighted = ref (' ' )
24+ const codeTextRef = ref <HTMLElement >()
2425
2526watch (
2627 [() => props .code , () => props .language ],
@@ -32,13 +33,26 @@ watch(
3233 highlighted .value = hljs .highlight (code , {
3334 language: props .language
3435 }).value
36+
37+ nextTick (() => {
38+ if (! codeTextRef .value ) return
39+
40+ codeTextRef .value .querySelectorAll (' span.hljs-number' ).forEach ((el ) => {
41+ const text = el .textContent ?.trim () ?? ' '
42+
43+ if (/ ^ -? \d + (\. \d + )? $ / .test (text )) {
44+ const num = parseFloat (text )
45+ el .textContent = num .toLocaleString (undefined , { maximumFractionDigits: 12 })
46+ }
47+ })
48+ })
3549 },
3650 { immediate: true }
3751)
3852 </script >
3953
4054<template >
41- <span v-if =" language !== 'raw'" class =" code-text" v-html =" highlighted" />
55+ <span v-if =" language !== 'raw'" ref = " codeTextRef " class =" code-text" v-html =" highlighted" />
4256 <span v-else class =" code-text" v-text =" code" />
4357</template >
4458
0 commit comments