summaryrefslogtreecommitdiff
path: root/pygments/formatters
diff options
context:
space:
mode:
authorAyowel <Ayowel@users.noreply.github.com>2022-11-01 21:22:49 +0100
committerAyowel <Ayowel@users.noreply.github.com>2022-11-06 09:47:32 +0100
commite61134bb3a2a00dc133fc4fc91a2ba1dff8a336e (patch)
tree2cdd6e141d42f83d0b3abccce94a2413cb9c21b0 /pygments/formatters
parent8371114d265fe0de654581398aae9f9e8a4a3c02 (diff)
downloadpygments-git-e61134bb3a2a00dc133fc4fc91a2ba1dff8a336e.tar.gz
Remove unneeded _format_unencoded_with_lineno function from IRCFormatter and fix line endings insertion
Diffstat (limited to 'pygments/formatters')
-rw-r--r--pygments/formatters/irc.py35
1 files changed, 5 insertions, 30 deletions
diff --git a/pygments/formatters/irc.py b/pygments/formatters/irc.py
index fd263bb0..fd5c0d89 100644
--- a/pygments/formatters/irc.py
+++ b/pygments/formatters/irc.py
@@ -128,38 +128,12 @@ class IRCFormatter(Formatter):
self._lineno = 0
def _write_lineno(self, outfile):
- self._lineno += 1
- outfile.write("\n%04d: " % self._lineno)
-
- def _format_unencoded_with_lineno(self, tokensource, outfile):
- self._write_lineno(outfile)
-
- for ttype, value in tokensource:
- if value.endswith("\n"):
- self._write_lineno(outfile)
- value = value[:-1]
- color = self.colorscheme.get(ttype)
- while color is None:
- ttype = ttype.parent
- color = self.colorscheme.get(ttype)
- if color:
- color = color[self.darkbg]
- spl = value.split('\n')
- for line in spl[:-1]:
- self._write_lineno(outfile)
- if line:
- outfile.write(ircformat(color, line[:-1]))
- if spl[-1]:
- outfile.write(ircformat(color, spl[-1]))
- else:
- outfile.write(value)
-
- outfile.write("\n")
+ if self.linenos:
+ self._lineno += 1
+ outfile.write("%04d: " % self._lineno)
def format_unencoded(self, tokensource, outfile):
- if self.linenos:
- self._format_unencoded_with_lineno(tokensource, outfile)
- return
+ self._write_lineno(outfile)
for ttype, value in tokensource:
color = self.colorscheme.get(ttype)
@@ -173,6 +147,7 @@ class IRCFormatter(Formatter):
if line:
outfile.write(ircformat(color, line))
outfile.write('\n')
+ self._write_lineno(outfile)
if spl[-1]:
outfile.write(ircformat(color, spl[-1]))
else: