Skip to content

Commit

Permalink
fix: allow lang='ts' on scripts in markdown (#693) (#701)
Browse files Browse the repository at this point in the history
fix #693
  • Loading branch information
brc-dd committed Jun 6, 2022
1 parent a8a1623 commit 59df105
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/node/markdownToVue.ts
Expand Up @@ -162,8 +162,9 @@ export async function createMarkdownToVueRenderFn(
}

const scriptRE = /<\/script>/
const scriptLangTsRE = /<\s*script[^>]*\blang=['"]ts['"][^>]*/
const scriptSetupRE = /<\s*script[^>]*\bsetup\b[^>]*/
const scriptClientRe = /<\s*script[^>]*\bclient\b[^>]*/
const scriptClientRE = /<\s*script[^>]*\bclient\b[^>]*/
const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/

Expand All @@ -176,10 +177,12 @@ function genPageDataCode(tags: string[], data: PageData) {
return (
scriptRE.test(tag) &&
!scriptSetupRE.test(tag) &&
!scriptClientRe.test(tag)
!scriptClientRE.test(tag)
)
})

const isUsingTS = tags.findIndex((tag) => scriptLangTsRE.test(tag)) > -1

if (existingScriptIndex > -1) {
const tagSrc = tags[existingScriptIndex]
// user has <script> tag inside markdown
Expand All @@ -196,7 +199,9 @@ function genPageDataCode(tags: string[], data: PageData) {
)
} else {
tags.unshift(
`<script>${code}\nexport default {name:'${data.relativePath}'}</script>`
`<script ${isUsingTS ? 'lang="ts"' : ''}>${code}\nexport default {name:'${
data.relativePath
}'}</script>`
)
}

Expand Down

0 comments on commit 59df105

Please sign in to comment.