Skip to content
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

html/template: removes content inside html comments #14256

Closed
liggitt opened this issue Feb 8, 2016 · 3 comments
Closed

html/template: removes content inside html comments #14256

liggitt opened this issue Feb 8, 2016 · 3 comments

Comments

@liggitt
Copy link
Contributor

liggitt commented Feb 8, 2016

This breaks templates that rely on things like conditional comments for adding classes.

Example:

    data := `<!DOCTYPE html>
<!--[if IE 8]><html class="ie8"><![endif]-->
<!--[if IE 9]><html class="ie9"><![endif]-->
<!--[if gt IE 9]><!--><html><!--<![endif]-->

... content that relies on ie8/ie9 classes ...
`
    tmpl, _ := template.New("name").Parse(data)
    b := &bytes.Buffer{}
    tmpl.Execute(b, data)
    fmt.Println(b.String())

renders:

<!DOCTYPE html>


<html>

... content that relies on ie8/ie9 classes ...

http://play.golang.org/p/MM27D4Qj9j

The behavior of dropping all content inside comments is also undocumented at https://golang.org/pkg/html/template/

@minux
Copy link
Member

minux commented Feb 8, 2016

This is working as intended.

Please see https://groups.google.com/forum/#!topic/golang-nuts/mriui-HG65A for
discussion and workaround.

@minux minux closed this as completed Feb 8, 2016
@liggitt
Copy link
Contributor Author

liggitt commented Feb 8, 2016

Can the noescape syntax be added to the template godoc? That is useful to know

@liggitt
Copy link
Contributor Author

liggitt commented Feb 8, 2016

actually, saw that noescape no longer exists... the described workaround (a template.HTML variable) assumes control of the go code processing the template, but would not work if a template author needed to use comments in a template, and the go code had not provided a BeginComment var containing <!--

@golang golang locked and limited conversation to collaborators Feb 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants