Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#10136 closed (invalid)

django should not insert newlines in generated html at places where the template has comments

Reported by: sarang@… Owned by: nobody
Component: Template system Version: dev
Severity: Keywords:
Cc: sarang@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am using django 1.0.2 (1.1 pre-alpha) with python 2.5.2 and I noticed that wherever I insert a comment line in the template file, django adds a newline to the generated html. I believe that this is not ideal as it causes comment lines to have some effect on the generated html. More importantly, this prevents me from adding comments at the beginning of template files as then the generated html has a blank line as its first line, making it non-compliant with xhtml 1.1. The same code generated with a template that does not have a comment at its beginning validates perfectly.

Steps to reproduce:

  1. Have a template that begins with comments:
    {# Elements / tags with attributes are inside their corresponding block to enable modification of attributes by descendant templates. #}
    {# Elements / tags without attributes are outside their block so that only the content enclosed by them needs to be in descendant templates #}
    {% block doctype %}<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    	  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    {% endblock %}
    
  2. Generate some html using it. The generated html will have blank lines at its beginning and will not validate at the W3C markup validator.

Change History (4)

comment:1 by Rob Hudson <treborhudson@…>, 16 years ago

Resolution: invalid
Status: newclosed

Django doesn't add newlines to the generated html as stated... they are already there. Django parses the stuff between and including the opening comment tag "{#" and closing comment tag "#}". The newline is outside of those tags, and hence, in the original template.

Long ago there was a proposal to have an alternate syntax to closing tags that would eat a newline (ticket #696), but that got shot down as wontfix.

Marking as invalid.

comment:2 by (none), 16 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:3 by Malcolm Tredinnick, 16 years ago

By the way, there's also a ticket open (or it might be closed and will be reopened if we ever solve it) to remove any lines that only contained template tags in the final result. The trick there is doing that without slowing down the rendering process (early attempts at it introduced anywhere from a 15% to a 50% slowdown, which were unacceptable). So we might well end up solving this in a more general fashion some day.

comment:4 by Chris Beaven, 15 years ago

(#2594)

Note: See TracTickets for help on using tickets.
Back to Top