Skip to content

Commit

Permalink
fix(md): fix multi-single line <script setup> tag
Browse files Browse the repository at this point in the history
Related Issue: DevCloudFE#1879
  • Loading branch information
fu050409 committed Jun 21, 2024
1 parent 2aba868 commit 5dc533c
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions packages/devui-vue/docs/.vitepress/plugins/md-transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Plugin } from 'vite';

const hasDemoBlock = (str: string) => /:::demo/gim.test(str);

export function MdTransformer(): Plugin {
return {
name: 'devui-markdown-demo-transformer',
Expand All @@ -12,15 +14,29 @@ export function MdTransformer(): Plugin {
if (id.split('/').at(-3) !== 'components') {
return code;
}
const setup = markdownStringArray.some(hasDemoBlock)
? `

const tag = '<script setup>';
if (code.includes(tag)) {
console.log("!!!!!!")
code = code.replace(
tag,
`
<script setup lang="ts">
const demoList = import.meta.globEager('../../components/${componentName}/*.vue') ?? []
const demoList = import.meta.glob('../../components/${componentName}/*.vue') ?? []
console.log(demoList);
`
);
} else {
code = `
<script setup lang="ts">
const demoList = import.meta.glob('../../components/${componentName}/*.vue') ?? []
</script>
`
: '';
${code}
`;
}
console.log(code);
return {
code: `${setup}\n${code}`,
code,
};
},
};
Expand Down

0 comments on commit 5dc533c

Please sign in to comment.