summaryrefslogtreecommitdiff
path: root/pygments/formatters/html.py
diff options
context:
space:
mode:
authorMatthäus G. Chajdas <dev@anteru.net>2020-07-31 12:16:36 +0200
committerMatthäus G. Chajdas <dev@anteru.net>2020-07-31 12:20:04 +0200
commitb6fb70f88a4bf270a36515e958fdf124a70543ad (patch)
treefcf044fef7f4c5f3c019bc9ffe5d85a922a158c2 /pygments/formatters/html.py
parenteaab40379c0c55e5549f67097701abb99123a6e0 (diff)
downloadpygments-git-improve-linenos-handling.tar.gz
Improve HTML formatter output.improve-linenos-handling
With the previous changes, we started to emit one <pre> per line for line numbers. This breaks for instance the Sphinx-RTD-Theme, which expects the line numbers to be formatted the same way as the normal content. This commit makes the following changes: * Emit a single <pre> inside the linenos div * Wrap individual lines into <span> as needed * Update all tests * Don't yield empty <span> elements when no style is specified This also makes the .html test files look correct when looked at with a browser, as there is no extra whitespace in them which needs stripping.
Diffstat (limited to 'pygments/formatters/html.py')
-rw-r--r--pygments/formatters/html.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index c3100967..06327f64 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -677,7 +677,8 @@ class HtmlFormatter(Formatter):
else:
style = ''
- line = '<pre%s>%s</pre>' % (style, line)
+ if style:
+ line = '<span%s>%s</span>' % (style, line)
lines.append(line)
@@ -688,8 +689,8 @@ class HtmlFormatter(Formatter):
# some configurations seem to mess up the formatting...
yield 0, (
'<table class="%stable">' % self.cssclass +
- '<tr><td class="linenos"><div class="linenodiv">' +
- ls + '</div></td><td class="code">'
+ '<tr><td class="linenos"><div class="linenodiv"><pre>' +
+ ls + '</pre></div></td><td class="code">'
)
yield 0, dummyoutfile.getvalue()
yield 0, '</td></tr></table>'
@@ -723,7 +724,10 @@ class HtmlFormatter(Formatter):
else:
style = ' class="linenos"'
- yield 1, '<span%s>%s</span>' % (style, line) + inner_line
+ if style:
+ yield 1, '<span%s>%s</span>' % (style, line) + inner_line
+ else:
+ yield 1, line + inner_line
num += 1
def _wrap_lineanchors(self, inner):