Skip to content

Commit

Permalink
fix(NcRichText): adjust import conditions for rehype-highlight library
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Dec 27, 2024
1 parent 6ae7d7c commit 0a571d7
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/components/NcRichText/NcRichText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,13 @@ import { RouterLink } from 'vue-router'
/**
* Heavy libraries should be loaded on demand to reduce component size
*/
let rehypeHighlight
const rehypeHighlightLoaded = ref(false)
const rehypeHighlight = ref(null)
/**
* Load 'rehype-highlight' library when code block is rendered with `useExtendedMarkdown`
*/
async function importRehypeLibrary() {
async function importRehypeHighlightLibrary() {
const module = await import('rehype-highlight')
rehypeHighlight = module.default
rehypeHighlightLoaded.value = true
rehypeHighlight.value = module.default
}

export default {
Expand Down Expand Up @@ -470,7 +468,7 @@ export default {
},
},
})
.use((this.useExtendedMarkdown && rehypeHighlightLoaded.value) ? rehypeHighlight : undefined)
.use(this.useExtendedMarkdown ? rehypeHighlight.value : undefined)
// .use(rehypeAddClasses, this.markdownCssClasses)
.use(remarkPlaceholder)
.use(rehypeExternalLinks, {
Expand Down Expand Up @@ -523,8 +521,9 @@ export default {
if (!String(type).startsWith('#')) {
let nestedNode = null
if (this.useExtendedMarkdown) {
if (String(type) === 'code' && !rehypeHighlightLoaded.value) {
importRehypeLibrary()
if (String(type) === 'code' && !rehypeHighlight.value
&& props?.class?.includes('language')) {
importRehypeHighlightLibrary()
}
if (String(type) === 'li' && Array.isArray(children)
&& children[0].type === 'input'
Expand Down

0 comments on commit 0a571d7

Please sign in to comment.