Skip to content

Commit 4516b0c

Browse files
committed
fix: skip doctype output when config doctype is falsy
1 parent 65bf9b3 commit 4516b0c

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export async function build(configInput?: Partial<MaizzleConfig> | string): Prom
9797
}
9898

9999
html = await events.fireAfterTransform({ config, template, html })
100-
html = `${doctype}\n${html}`
100+
if (doctype) html = `${doctype}\n${html}`
101101

102102
const htmlOut = stripForHtml(html)
103103
const sfcOutputPath = rendered.outputPath

src/render/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function render(
6767
if (rendered.templateConfig.useTransformers !== false) {
6868
html = await runTransformers(html, rendered.templateConfig, isFile ? resolve(template) : undefined, doctype, rendered.tailwindBlocks)
6969
}
70-
html = `${doctype}\n${html}`
70+
if (doctype) html = `${doctype}\n${html}`
7171

7272
const globalPlaintext = rendered.templateConfig.plaintext
7373
const sfcPlaintext = rendered.plaintext

src/serve.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ async function serveRenderedTemplate(url: string, config: MaizzleConfig, rendere
363363
const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'
364364

365365
html = await runTransformers(html, templateConfig, absolutePath, doctype, rendered.tailwindBlocks)
366-
html = `${doctype}\n${html}`
366+
if (doctype) html = `${doctype}\n${html}`
367367

368368
res.setHeader('Content-Type', 'text/html')
369369
res.end(stripForHtml(html))
@@ -413,7 +413,7 @@ async function serveHighlightedSource(url: string, config: MaizzleConfig, render
413413
const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'
414414
html = await runTransformers(html, templateConfig, absolutePath, doctype, rendered.tailwindBlocks)
415415

416-
html = stripForHtml(`${doctype}\n${html}`)
416+
html = stripForHtml(doctype ? `${doctype}\n${html}` : html)
417417

418418
const hl = await getHighlighter()
419419
const highlighted = hl.codeToHtml(html, {
@@ -624,7 +624,7 @@ async function serveEmailEndpoint(url: string, req: any, res: any, config: Maizz
624624
const templateConfig = rendered.templateConfig
625625
const doctype = rendered.doctype ?? templateConfig.doctype ?? '<!DOCTYPE html>'
626626
html = await runTransformers(html, templateConfig, absolutePath, doctype, rendered.tailwindBlocks)
627-
html = `${doctype}\n${html}`
627+
if (doctype) html = `${doctype}\n${html}`
628628

629629
const text = createPlaintext(stripForPlaintext(html))
630630
html = stripForHtml(html)

src/tests/render/basic.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ describe('render', () => {
110110
expect(result.html).toMatch(/^<!DOCTYPE html>\n/)
111111
})
112112

113+
it('omits doctype when config doctype is false', async () => {
114+
const result = await render(`
115+
<template>
116+
<div>Test</div>
117+
</template>
118+
`, {
119+
doctype: false,
120+
})
121+
122+
expect(result.html).not.toMatch(/doctype/i)
123+
expect(result.html.startsWith('\n')).toBe(false)
124+
})
125+
113126
it('uses custom doctype from config', async () => {
114127
const result = await render(`
115128
<template>

0 commit comments

Comments
 (0)