Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/core/src/render-node/sfc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ describe('renderSFCString', async () => {
expect(rendered).not.toBe('')
expect(rendered).toBe('# Count: 0\n\n2025-07-01\n')
})

it('should strip Vue SSR comments like <!--[--> <!--]--> <!--v-if-->', async () => {
const content = await readFile(join(dirname(fileURLToPath(import.meta.url)), 'testdata', 'vue-comments.velin.vue'), 'utf-8')
const { rendered } = await renderSFCString(content)
expect(rendered).not.toContain('<!--')
expect(rendered).toContain('Title')
expect(rendered).toContain('visible')
})
})

describe('evaluateSFC', async () => {
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/render-node/testdata/vue-comments.velin.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script setup>
import { ref } from 'vue'

const show = ref(true)
const items = ref(['a', 'b', 'c'])
</script>

<template>
<div>
<h1>Title</h1>
<p v-if="show">visible</p>

Check warning on line 11 in packages/core/src/render-node/testdata/vue-comments.velin.vue

View workflow job for this annotation

GitHub Actions / Lint

Expected 1 line break before closing tag (`</p>`), but no line breaks found

Check warning on line 11 in packages/core/src/render-node/testdata/vue-comments.velin.vue

View workflow job for this annotation

GitHub Actions / Lint

Expected 1 line break after opening tag (`<p>`), but no line breaks found
<ul>
<li v-for="item in items" :key="item">{{ item }}</li>

Check warning on line 13 in packages/core/src/render-node/testdata/vue-comments.velin.vue

View workflow job for this annotation

GitHub Actions / Lint

Expected 1 line break before closing tag (`</li>`), but no line breaks found

Check warning on line 13 in packages/core/src/render-node/testdata/vue-comments.velin.vue

View workflow job for this annotation

GitHub Actions / Lint

Expected 1 line break after opening tag (`<li>`), but no line breaks found
</ul>
</div>
</template>
13 changes: 13 additions & 0 deletions packages/utils/src/to-md/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from 'vitest'

import { toMarkdown } from '.'

describe('toMarkdown', () => {
it('should strip Vue SSR comments like <!--[--> <!--]--> <!--v-if-->', async () => {
const html = '<!--[--><p>hello</p><!--]--><!--v-if--><p>world</p>'
const result = await toMarkdown(html)
expect(result).not.toContain('<!--')
expect(result).toContain('hello')
expect(result).toContain('world')
})
})
2 changes: 2 additions & 0 deletions packages/utils/src/to-md/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import rehypeParse from 'rehype-parse'
import rehypeRemark from 'rehype-remark'
import rehypeRemoveComments from 'rehype-remove-comments'
import remarkStringify from 'remark-stringify'

import { unified } from 'unified'

export async function toMarkdown(html: string): Promise<string> {
const htmlToMarkdownProcessor = unified()
.use(rehypeParse, { fragment: true })
.use(rehypeRemoveComments, { removeConditional: true })
.use(rehypeRemark)
.use(remarkStringify, { bullet: '-' })

Expand Down
Loading