Don't append a class attribute to the doctype (#284)

* Don't append a class attribute to the doctype

Fixes #282

* Add changeset
This commit is contained in:
Matthew Phillips 2021-06-01 21:03:38 -04:00 committed by GitHub
parent ee5b1ac12f
commit 46871d2d4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixed bug where a class attribute was added to the doctype

View file

@ -14,8 +14,7 @@ const CSS_SEPARATORS = new Set([' ', ',', '+', '>', '~']);
const KEYFRAME_PERCENT = /\d+\.?\d*%/;
/** HTML tags that should never get scoped classes */
export const NEVER_SCOPED_TAGS = new Set<string>(['base', 'body', 'font', 'frame', 'frameset', 'head', 'html', 'link', 'meta', 'noframes', 'noscript', 'script', 'style', 'title']);
export const NEVER_SCOPED_TAGS = new Set<string>(['base', 'body', 'font', 'frame', 'frameset', 'head', 'html', 'link', 'meta', 'noframes', 'noscript', 'script', 'style', 'title', '!doctype']);
/**
* Scope Rules
* Given a selector string (`.btn>span,.nav>span`), add an additional CSS class to every selector (`.btn.myClass>span.myClass,.nav.myClass>span.myClass`)

View file

@ -40,6 +40,14 @@ DType('Automatically prepends the standards mode doctype', async () => {
assert.ok(html.startsWith('<!doctype html>'), 'Doctype always included');
});
DType('No attributes added when doctype is provided by user', async () => {
const result = await runtime.load('/provided');
if (result.error) throw new Error(result.error);
const html = result.contents.toString('utf-8');
assert.ok(html.startsWith('<!doctype html>'), 'Doctype always included');
});
DType.skip('Preserves user provided doctype', async () => {
const result = await runtime.load('/preserve');
if (result.error) throw new Error(result.error);

View file

@ -0,0 +1,9 @@
---
let title = 'My Site';
---
<!doctype html>
<html lang="en">
<head><title>{title}</title></head>
<body><h1>Hello world</h1></body>
</html>