11<template >
2- <pre :class =" `language-${language}`" ><code
3- :class =" `language-${language}`"
4- v-html =" highlightCode"
5- ></code ></pre >
2+ <pre ><code class =" hljs" v-html =" highlightCode" ></code ></pre >
63</template >
74
85<script lang="ts">
9- import hljs from ' highlight.js'
10- import { defineComponent , ref , onMounted , watch , Ref } from ' vue'
6+ import { highlight } from ' highlight.js'
7+ import { defineComponent , ref , onMounted , watch } from ' vue'
118import { MODIFIED_START_TAG , MODIFIED_CLOSE_TAG } from ' ./utils'
12- import ' highlight.js/styles/monokai.css'
9+
10+ import type { Ref } from ' vue'
1311
1412/**
1513 * Set hightlight code
@@ -19,7 +17,7 @@ const setHighlightCode = ({ highlightCode, language, code }: { highlightCode: Re
1917 const hasModifiedTags = code .match (new RegExp (` (${MODIFIED_START_TAG }|${MODIFIED_CLOSE_TAG }) ` , ' g' ))
2018
2119 if (! hasModifiedTags ) {
22- highlightCode .value = hljs . highlight (language , code ).value
20+ highlightCode .value = highlight (language , code ).value
2321 return
2422 }
2523
@@ -29,7 +27,7 @@ const setHighlightCode = ({ highlightCode, language, code }: { highlightCode: Re
2927 let originalCode = code // original code with modified tags
3028 const pureCode = code .replace (new RegExp (` (${MODIFIED_START_TAG }|${MODIFIED_CLOSE_TAG }) ` , ' g' ), ' ' ) // Without modified tags
3129 let pureElement = document .createElement (' div' )
32- pureElement .innerHTML = hljs . highlight (language , pureCode ).value // Highlight DOM without modified tags
30+ pureElement .innerHTML = highlight (language , pureCode ).value // Highlight DOM without modified tags
3331
3432 const diffElements = (node : HTMLElement ) => {
3533 node .childNodes .forEach (child => {
@@ -113,11 +111,3 @@ export default defineComponent({
113111 }
114112})
115113 </script >
116-
117- <style scoped lang="scss">
118- code {
119- word-wrap : break-all !important ;
120- word-break : break-all !important ;
121- white-space : pre-wrap !important ;
122- }
123- </style >
0 commit comments