<!DOCTYPE html> broke render
See original GitHub issueHTM is a very cool library, thanks a lot to everyone who took part in the development, I really love it! I found one whole curious bug the reason of which I do not yet understand. the following code will produce incorrect output:
const htm = require('htm');
const vhtml = require('vhtml');
const html = htm.bind(vhtml);
console.log( html`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
</body>
</html>
` );
Nothing special, just emmet generated boilerplate ( ! + tab ). (this tool is actively used in front-end development and is built into some IDE by default) Output of this code:
[ 'meta',
{ charset: 'UTF-8' },
'<meta name="viewport" content="width=device-width, initial-scale=1.0">' ]
Interactive repl
Any ideas how to fix this?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Adding doctype for html5 (or any doctype) breaks my site
Short Answer: If <!DOCTYPE html> breaks your format, check whether your use of the % unit is involved, and/or whether replacing % with...
Read more >Doctype declaration breaks my layout. Huuu? - HTML & CSS
Doctype declaration my layout breaks. The left and right sidebars, instead of staying at 100% height, collaps up to the bottom of the...
Read more >Fix Your Site With the Right DOCTYPE! - A List Apart
A recent DOCTYPE that includes a full URI (a complete web address) tells these browsers to render your page in standards–compliant mode, treating...
Read more >How to Render an HTML String Preserving Spaces and Line ...
In this tutorial, you can learn how to render an HTML text preserving spaces and line breaks. You need to use the HTML...
Read more >The !DOCTYPE Tag and Its Effect on Page Rendering
I never gave much thought to the DOCTYPE tag because my HTML ... they inadvertently broke thousands of pages that relied on one...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
HTM is intentionally not a full HTML parser. It can handle arbitrary Element and Comment nodes, but does not support other tag types like Doctype or Processing Instruction.
For this specific case, I’d recommend prepending the doctype as a string:
@Akiyamka I’m not sure, but I think htm is specially targeted to JSX (with some HTML extensions), so it’s not surprising that htm doesn’t support
DOCTYPE
tags.You shouldn’t be doing that anyway, I can’t think of any use case of using htm for a total HTML document. Most likely you should already have the
DOCTYPE
and head tags when the JS code has loaded.