Skip to content

Commit

Permalink
add tests and fix htmlization of templates
Browse files Browse the repository at this point in the history
  • Loading branch information
elevatebart committed Aug 31, 2022
1 parent a47cbb9 commit 064f334
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-eyes-develop.md
@@ -0,0 +1,5 @@
---
'vue-styleguidist': patch
---

fix editor highlight on sfc components
Expand Up @@ -67,4 +67,46 @@ function foo(param: Vue) : { one: number, two: boolean } {
</Provider>
)
})

it('renders vue SFC with Self-closing tag', () => {
const code = `
<template>
<Checkbox />
</template>
<script lang="ts">
import type { Vue } from 'vue'
function foo(param: Vue) : { one: number, two: boolean } {
return 'bar'
}
</script>
`
mount(
<Provider jsxInExamples>
<EditorPrism code={code} onChange={() => {}} />
</Provider>
)

cy.contains('.token.tag', 'Checkbox').should('be.visible')
})

it('renders vue SFC with style scoped tag', () => {
const code = `
<template>
<Checkbox />
</template>
<style scoped>
.checkbox {
color: red;
}
</script>
`
mount(
<Provider jsxInExamples>
<EditorPrism code={code} onChange={() => {}} />
</Provider>
)

cy.contains('.token.tag', 'Checkbox').should('be.visible')
})
})
Expand Up @@ -44,7 +44,7 @@ const highlight = (lang: 'vsg' | 'vue-sfc', jsxInExamples: boolean): ((code: str

return code => {
const parser = new DOMParser()
const SfcXMLDocument = parser.parseFromString(`<body>${code}</body>`, 'text/html')
const SfcXMLDocument = parser.parseFromString(`<body>${code}</body>`, 'text/xml')
const scriptNodes = SfcXMLDocument.querySelectorAll('script')
const scriptBlocks: { text: string; lg: string }[] = []
scriptNodes.forEach(scriptNode => {
Expand All @@ -55,7 +55,7 @@ const highlight = (lang: 'vsg' | 'vue-sfc', jsxInExamples: boolean): ((code: str
}
scriptNode.textContent = ' '
})
const htmlHighlighted = prismHighlight(SfcXMLDocument.body.innerHTML, langScheme, 'html')
const htmlHighlighted = prismHighlight(SfcXMLDocument.documentElement.innerHTML, langScheme, 'html')
return htmlHighlighted.replace(/<span class="token language-javascript"> <\/span>/g, () => {
const scriptBlock = scriptBlocks.shift()
if (scriptBlock) {
Expand Down

0 comments on commit 064f334

Please sign in to comment.