summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/html.py13
-rw-r--r--coverage/htmlfiles/pyfile.html14
2 files changed, 12 insertions, 15 deletions
diff --git a/coverage/html.py b/coverage/html.py
index 7567c605..a7a92095 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -263,7 +263,7 @@ class HtmlReporter(Reporter):
'fr': fr, 'nums': nums, 'lines': lines,
'time_stamp': self.time_stamp,
}
- html = spaceless(self.source_tmpl.render(template_values))
+ html = self.source_tmpl.render(template_values)
html_filename = rootname + ".html"
html_path = os.path.join(self.directory, html_filename)
@@ -426,17 +426,6 @@ def escape(t):
return t.replace("&", "&amp;").replace("<", "&lt;")
-def spaceless(html):
- """Squeeze out some annoying extra space from an HTML string.
-
- Nicely-formatted templates mean lots of extra space in the result.
- Get rid of some.
-
- """
- html = re.sub(r">\s+<p ", ">\n<p ", html)
- return html
-
-
def pair(ratio):
"""Format a pair of numbers so JavaScript can read them in an attribute."""
return "%s %s" % ratio
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html
index fb8e131e..b8336760 100644
--- a/coverage/htmlfiles/pyfile.html
+++ b/coverage/htmlfiles/pyfile.html
@@ -71,13 +71,21 @@
<table>
<tr>
<td class="linenos">
- {% for line in lines %}
+ {% for line in lines -%}
<p id="n{{line.number}}" class="{{line.class}}"><a href="#n{{line.number}}">{{line.number}}</a></p>
{% endfor %}
</td>
<td class="text">
- {% for line in lines %}
- <p id="t{{line.number}}" class="{{line.class}}">{% if line.annotate %}<span class="annotate short">{{line.annotate}}</span><span class="annotate long">{{line.annotate_long}}</span>{% endif %}{{line.html}}<span class="strut">&nbsp;</span></p>
+ {# These are the source lines, which are very sensitive to whitespace. #}
+ {# The `{ # - # }` below are comments which slurp up the following space. #}
+ {% for line in lines -%}
+ <p id="t{{line.number}}" class="{{line.class}}">{#-#}
+ {% if line.annotate -%}
+ <span class="annotate short">{{line.annotate}}</span>{#-#}
+ <span class="annotate long">{{line.annotate_long}}</span>{#-#}
+ {% endif -%}
+ {{line.html}}<span class="strut">&nbsp;</span>{#-#}
+ </p>
{% endfor %}
</td>
</tr>