-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: compact HTML output #3164
Labels
Milestone
Comments
Labels changed: added priority-later, removed priority-triage. Owner changed to builder@golang.org. Status changed to Thinking. |
Some inspiration: https://developers.google.com/closure/templates/docs/concepts#linejoining It is based on some simple conventions, something very Go-ish imo. |
Just some brainstorm. Still taking the idea from Closure Templates, simplifying it a bit: - Parsing process must accept a configuration/flag to turn on compact mode. Off by default, so nothing that exists change. I'm not sure where this flag is set. - When the flag is on, lines are joined using same Closure heuristics: "if the join location borders a template or HTML tag on either side, the lines are joined with no space. If the join location does not border a template or HTML tag on either side, the lines are joined with exactly one space". - A special action {{sp}} inserts an space for two lines that would otherwise be joined without any space. - No need for the {{nil}} tag used in Closure; simply merge lines with the desired spaces if that is needed. Inline JavaScript may require some more thoughts. |
A special flag for indented output would also be useful. In either case, special care must be given to. Worse yet is that any tag may be css-styled as preformatted text. a single newline should of course never be replaced by a single space, unless you want to save an extra bit in compression. As long a you're parsing html, a {{pre}} template tag could cause all text inside the immediate parent tag to maintain its content precisely. Multiple instances of {{pre}} in the same html subtree would be idempotent. |
This is a dupe of #20879; I'm going to go ahead and close. Probably worth revisiting when the stdlib can be versioned, but until then, the conclusion on that bug seems right to me. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: