feature: vor und nachteile

This commit is contained in:
Hikyu
2026-05-31 13:54:31 +02:00
parent 552a947a1c
commit e3dad17446
23270 changed files with 3024794 additions and 200 deletions
@@ -0,0 +1,43 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`excerpt > raw excerpt 1`] = `
"<template><div class="markdown-body"><p>This is an excerpt which is kept as <strong>raw Markdown</strong>.</p>
<!-- more -->
<h1>Hello</h1>
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</div></template>
<script setup>
const frontmatter = {"title":"Hey"}
defineExpose({ frontmatter })
const excerpt = "\\nThis is an excerpt which is kept as **raw Markdown**.\\n\\n"
</script>
<script>
export const title = "Hey"
export const excerpt = "\\nThis is an excerpt which is kept as **raw Markdown**.\\n\\n"
</script>"
`;
exports[`excerpt > rendered excerpt 1`] = `
"<template><div class="markdown-body"><p>This is an excerpt which has been rendered to <strong>HTML</strong>.</p>
<!-- more -->
<h1>Hello</h1>
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</div></template>
<script setup>
const frontmatter = {"title":"Hey"}
defineExpose({ frontmatter })
const excerpt = "<p>This is an excerpt which has been rendered to <strong>HTML</strong>.</p>\\n"
</script>
<script>
export const title = "Hey"
export const excerpt = "<p>This is an excerpt which has been rendered to <strong>HTML</strong>.</p>\\n"
</script>"
`;
@@ -0,0 +1,128 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`transform > basic 1`] = `
"<template><div class="markdown-body"><h1>Hello</h1>
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</div></template>
<script setup>
const frontmatter = {"title":"Hey"}
defineExpose({ frontmatter })
</script>
<script>
export const title = "Hey"
</script>"
`;
exports[`transform > code escape 1`] = `
"<template><div class="markdown-body"><p>Hello <code v-pre>{{ world }}</code></p>
<pre><code class="language-js" v-pre>console.log(\`{{ world }}\`)
</code></pre>
</div></template>
<script setup>
const frontmatter = {}
defineExpose({ frontmatter })
</script>"
`;
exports[`transform > couldn't expose frontmatter 1`] = `
"<template><div class="markdown-body">
</div></template>
<script setup>
const frontmatter = {"title":"Hey"}
defineExpose({ test: 'test'})
</script>
<script>
export const title = "Hey"
</script>"
`;
exports[`transform > escapeCodeTagInterpolation 1`] = `
"<template><div class="markdown-body"><div>{{hello}}</div>
<pre><code class="language-ts" v-pre>&lt;div&gt;{{hello}}&lt;/div&gt;
</code></pre>
</div></template>
<script setup>
const frontmatter = {}
defineExpose({ frontmatter })
</script>"
`;
exports[`transform > export keyword frontmatters 1`] = `
"<template><div class="markdown-body"><p>Hello</p>
</div></template>
<script setup>
const frontmatter = {"class":"text","default":"foo"}
defineExpose({ frontmatter })
</script>
<script>
export const _class = "text"
export const _default = "foo"
</script>"
`;
exports[`transform > exposes frontmatter 1`] = `
"<template><div class="markdown-body"><h1>Hello</h1>
</div></template>
<script setup>
const frontmatter = {"title":"Hey"}
defineExpose({ frontmatter })
</script>
<script>
export const title = "Hey"
</script>"
`;
exports[`transform > frontmatter interpolation 1`] = `
"<template><div class="markdown-body"><h1>Hello World</h1>
<p>This is {{frontmatter.name}}</p>
</div></template>
<script setup>
const frontmatter = {"name":"My Cool App"}
defineExpose({ frontmatter })
</script>
<script>
export const name = "My Cool App"
</script>"
`;
exports[`transform > script setup 1`] = `
"<template><div class="markdown-body"><h1>Hello</h1>
</div></template>
<script setup lang="ts">
const frontmatter = {}
defineExpose({ frontmatter })
import Foo from './Foo.vue'
</script>"
`;
exports[`transform > style 1`] = `
"<template><div class="markdown-body"><h1>Hello</h1>
</div></template>
<script setup>
const frontmatter = {}
defineExpose({ frontmatter })
</script>
<style>h1 { color: red }</style>"
`;
exports[`transform > vue directives 1`] = `
"<template><div class="markdown-body">
<p><button @click="onClick"></button></p>
</div></template>
<script setup lang="ts">
const frontmatter = {"name":"My Cool App"}
defineExpose({ frontmatter })
function onClick() {
// ...
}
</script>
<script lang="ts">
export const name = "My Cool App"
</script>"
`;
+60
View File
@@ -0,0 +1,60 @@
import { describe, expect, it } from 'vitest'
import { createMarkdown } from '../src/core/markdown'
import { resolveOptions } from '../src/core/options'
describe('excerpt', () => {
it('rendered excerpt', async () => {
const options = resolveOptions({
excerpt: true,
frontmatterOptions: {
grayMatterOptions: {
excerpt: true,
excerpt_separator: '<!-- more -->',
},
},
})
const markdownToVue = createMarkdown(options)
const md = `---
title: Hey
---
This is an excerpt which has been rendered to **HTML**.
<!-- more -->
# Hello
- A
- B
- C`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
it('raw excerpt', async () => {
const options = resolveOptions({
excerpt: true,
frontmatterOptions: {
renderExcerpt: false,
grayMatterOptions: {
excerpt: true,
excerpt_separator: '<!-- more -->',
},
},
})
const markdownToVue = createMarkdown(options)
const md = `---
title: Hey
---
This is an excerpt which is kept as **raw Markdown**.
<!-- more -->
# Hello
- A
- B
- C`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
})
@@ -0,0 +1,12 @@
---
title: Hello World
description: testing is the path to true happiness
---
# My H1
lorem ipsum
## Transformed
base: {{ title }}
@@ -0,0 +1,53 @@
import type { MetaProperty, ResolvedOptions } from '../src/types'
import { readFile } from 'node:fs/promises'
import { describe, expect, it } from 'vitest'
import { createMarkdown } from '../src/core/markdown'
import { resolveOptions } from '../src/core/options'
const frontmatterPreprocess: ResolvedOptions['frontmatterPreprocess'] = (fm) => {
const frontmatter = {
title: 'default title',
description: 'default description',
...fm,
}
const meta: MetaProperty[] = [
{ property: 'og:title', name: 'twitter:title', itemprop: 'title', content: frontmatter.title },
{
property: 'og:description',
name: 'twitter:description',
itemprop: 'description',
content: frontmatter.description,
},
]
return {
head: { ...frontmatter, meta },
frontmatter: { ...frontmatter, meta },
}
}
describe('provide bespoke frontmatter processor', () => {
it('inline markdown is used over default properties', async () => {
const markdownToVue = createMarkdown(resolveOptions({ frontmatterPreprocess }))
const md = (await markdownToVue('', await readFile('test/fixtures/simple.md', 'utf-8'))).code
// Positive tests
expect(
md.includes('Hello World'),
'the title attribute is retained over the default \'title\' value',
).toBeTruthy()
expect(
md.includes('testing is the path to true happiness'),
'description property is also retained',
).toBeTruthy()
// Negative tests
expect(
md.includes('default title'),
'the title attribute is retained over the default \'title\' value',
).toBeFalsy()
expect(md.includes('default description'), 'default description is ignored').toBeFalsy()
// Meta props
expect(md.includes('og:title')).toBeTruthy()
expect(md.includes('og:description')).toBeTruthy()
})
})
+127
View File
@@ -0,0 +1,127 @@
import { describe, expect, it } from 'vitest'
import { createMarkdown } from '../src/core/markdown'
import { resolveOptions } from '../src/core/options'
describe('transform', async () => {
const options = resolveOptions({})
const markdownToVue = createMarkdown(options)
it('basic', async () => {
const md = `---
title: Hey
---
# Hello
- A
- B
- C
`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
it('style', async () => {
const md = `
# Hello
<style>h1 { color: red }</style>
`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
it('script setup', async () => {
const md = `
# Hello
<script setup lang="ts">
import Foo from './Foo.vue'
</script>
`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
it('exposes frontmatter', async () => {
const md = `---
title: Hey
---
# Hello`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
it('couldn\'t expose frontmatter', async () => {
const md = `---
title: Hey
---
<script setup>
defineExpose({ test: 'test'})
</script>
`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
it('escapeCodeTagInterpolation', async () => {
const md = `
<div>{{hello}}</div>
\`\`\`ts
<div>{{hello}}</div>
\`\`\`
`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
it('frontmatter interpolation', async () => {
const md = `
---
name: 'My Cool App'
---
# Hello World
This is {{frontmatter.name}}
`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
it('vue directives', async () => {
const md = `
---
name: 'My Cool App'
---
<script setup lang="ts">
function onClick() {
// ...
}
</script>
<button @click="onClick"></button>
`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
it('export keyword frontmatters', async () => {
const md = `
---
class: 'text'
default: 'foo'
---
Hello
`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
it('code escape', async () => {
const md = `
Hello \`{{ world }}\`
\`\`\`js
console.log(\`{{ world }}\`)
\`\`\`
`
expect((await markdownToVue('', md)).code).toMatchSnapshot()
})
})