File tree Expand file tree Collapse file tree 3 files changed +8
-15
lines changed
views/components-doc/components Expand file tree Collapse file tree 3 files changed +8
-15
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import hljs from 'highlight.js/lib/core'
2727import javascript from 'highlight.js/lib/languages/javascript'
2828import css from 'highlight.js/lib/languages/css'
2929import html from 'highlight.js/lib/languages/xml'
30+ import tsPath from 'highlight.js/lib/languages/typescript'
3031import docsearch from '@docsearch/js'
3132import '@docsearch/css'
3233import { doSearchEverySite } from './tools/docsearch'
@@ -37,6 +38,7 @@ const envTarget = import.meta.env.VITE_BUILD_TARGET || 'open'
3738hljs . registerLanguage ( 'javascript' , javascript )
3839hljs . registerLanguage ( 'css' , css )
3940hljs . registerLanguage ( 'html' , html )
41+ hljs . registerLanguage ( 'ts' , tsPath )
4042
4143if ( ! location . href . includes ( 'tiny-vue-plus' ) ) {
4244 docsearch ( {
Original file line number Diff line number Diff line change 99import { defineComponent , ref , watch } from ' vue'
1010import hljs from ' highlight.js/lib/core'
1111import ' highlight.js/styles/github.css'
12- import tsPath from ' highlight.js/lib/languages/typescript'
1312
1413export default defineComponent ({
1514 name: ' AsyncHighlight' ,
@@ -18,29 +17,21 @@ export default defineComponent({
1817 type: String ,
1918 default: ' '
2019 },
21- types : {
20+ filename : {
2221 type: String
2322 }
2423 },
2524 setup (props ) {
2625 const highlightFinish = ref (false )
2726 const highlightCode = ref (' ' )
2827
29- const getFormatCodes = (types ) => {
30- hljs .registerLanguage (' ts' , tsPath)
31- const textHtml = hljs .highlight (props .code , { language: types }).value
32-
33- return textHtml
34- }
3528 watch (
3629 props,
3730 () => {
3831 setTimeout (() => {
3932 // highlight和其他同步任务叠加容易形成长任务,改成异步消除长任务。
40- if (props .types && props .types === ' html' ) {
41- highlightCode .value = props .code
42- } else if (props .types && props .types === ' ts' ) {
43- highlightCode .value = getFormatCodes (props .types )
33+ if (props .filename && props .filename .endsWith (' .vue' )) {
34+ highlightCode .value = hljs .highlight (props .code , { language: ' html' }).value
4435 } else {
4536 highlightCode .value = hljs .highlightAuto (props .code ).value
4637 }
Original file line number Diff line number Diff line change 2929 />
3030
3131 <i
32- v-if =" !isPlus"
32+ v-if =" !isPlus"
3333 v-auto-tip =" { content: i18nByKey('playground'), effect: 'light', always: true }"
3434 class =" i-ti-playground ml8 ti-w16 ti-h16 ti-cur-hand"
3535 @click =" openPlayground(demo)"
5757 <template v-if =" files ?.length " >
5858 <tiny-tabs v-model =" state.tabValue" class =" code-tabs" >
5959 <tiny-tab-item v-for =" (file, idx) in files" :key =" file.fileName" :name =" 'tab' + idx" :title =" file.fileName" >
60- <async-highlight :code =" file.code" ></async-highlight >
60+ <async-highlight :code =" file.code" :filename = " file.fileName " ></async-highlight >
6161 </tiny-tab-item >
6262 </tiny-tabs >
6363 </template >
6464 <div v-else-if =" files[0]" >
65- <async-highlight :code =" files[0].code" ></async-highlight >
65+ <async-highlight :code =" files[0].code" :filename = " files[0].fileName " ></async-highlight >
6666 </div >
6767 </div >
6868 </div >
You can’t perform that action at this time.
0 commit comments