-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doctype preamble for elem.Html #91
Comments
@daenney Great catch! That would be great if you could add it. Maybe, we could do something like: func Html(attrs attrs.Props, children ...Node) *Element {
return NewElement("html", attrs, children...).withCustomOptions(CustomOptions{OpeningTag: "<!DOCTYPE html>"})
} I've been avoiding chaining since the pattern isn't used elsewhere in the library, but in this case since it's not an exposed API and it would be used so infrequently, I'm not opposed to it. What do you think? I guess we could also have a new function like |
@daenney What I wrote earlier was incorrect since the doctype preamble actually comes before the func (e *Element) Render() string {
var builder strings.Builder
// Automatically add DOCTYPE for 'html' elements
if e.Tag == "html" {
builder.WriteString("<!DOCTYPE html>")
}
e.RenderTo(&builder)
return builder.String()
} If anyone needs different preambles down the road we could have a custom option in |
Ah fair enough. Sorry for not responding to the earlier comment, it completely slipped my mind. I'll take a look at whipping up a PR for this next week. |
The doctype preamble needs to be emmitted in order to ensure browsers don't switch to legacy/quirks mode rendering. Fixes: chasefleming#91
When using
elem.Html
, everything gets neatly wrapped in an<html></html>
element as expected.But it's expected/required by browsers to have a
<!DOCTYPE html>
preamble. It'll work without it, but you immediately get a warning in the console as without the preamble you're rendering in the legacy/quirks mode which is usually not desirable. Since a document can only have a singlehtml
element, it seems like elem-go could safely emit it.So two questions:
RenderTo()
which feels a bit iffy. Is there a better way?The text was updated successfully, but these errors were encountered: