summaryrefslogtreecommitdiff
path: root/pygments/formatters/img.py
diff options
context:
space:
mode:
authorthatch <devnull@localhost>2008-12-28 20:32:23 -0600
committerthatch <devnull@localhost>2008-12-28 20:32:23 -0600
commit62be71ef0f979200c60a25943a3f58de5946e32c (patch)
tree4c8f8f7cef8165d98144e8083ef9692fbbf5fb7c /pygments/formatters/img.py
parentb4afda61ef642b5d04fe46a76d6aa21aa33c4518 (diff)
downloadpygments-62be71ef0f979200c60a25943a3f58de5946e32c.tar.gz
Rework newline handling in image formatter (#380)
Diffstat (limited to 'pygments/formatters/img.py')
-rw-r--r--pygments/formatters/img.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/pygments/formatters/img.py b/pygments/formatters/img.py
index ef3579d7..7c343fd7 100644
--- a/pygments/formatters/img.py
+++ b/pygments/formatters/img.py
@@ -395,26 +395,27 @@ class ImageFormatter(Formatter):
while ttype not in self.styles:
ttype = ttype.parent
style = self.styles[ttype]
+ #TODO make sure tab expansion happens earlier in the chain. It
+ #really ought to be done on the input, as to do it right here is
+ #quite complex.
value = value.expandtabs(4)
- lines = value.splitlines()
+ lines = value.splitlines(True)
#print lines
for i, line in enumerate(lines):
- if not line:
- lineno += 1
- charno = 0
- else:
- # add a line for each extra line in the value
- if i:
- lineno += 1
- charno = 0
+ temp = line.rstrip('\n')
+ if temp:
self._draw_text(
self._get_text_pos(charno, lineno),
- line,
+ temp,
font = self._get_style_font(style),
fill = self._get_text_color(style)
)
- charno += len(value)
+ charno += len(temp)
maxcharno = max(maxcharno, charno)
+ if line.endswith('\n'):
+ # add a line for each extra line in the value
+ charno = 0
+ lineno += 1
self.maxcharno = maxcharno
self.maxlineno = lineno