pygmentize -g /dev/null produces an empty line

Issue #1437 new
Vladimir Panteleev
created an issue

I think it is expected that with an empty input, pygmentize should produce an empty output. However, both an empty input and an input consisting of a single blank line (i.e. one newline character) produce the same output, a single blank line.

$ pygmentize -V
Pygments version 2.2.0, (c) 2006-2017 by Georg Brandl.
$ true | pygmentize -g | hexdump -C
00000000  0a                                                |.|
00000001
$ echo | pygmentize -g | hexdump -C
00000000  0a                                                |.|
00000001

Actually, any number of leading new lines seems to be discarded by pygmentize, and the trailing newline is added when missing:

$ ( echo ; echo ) | pygmentize -g | hexdump -C
00000000  0a                                                |.|
00000001
$ ( echo ; echo ; echo ) | pygmentize -g | hexdump -C
00000000  0a                                                |.|
00000001
$ ( echo ; echo ; echo a ) | pygmentize -g | hexdump -C
00000000  61 0a                                             |a.|
00000002
$ ( echo ; echo ; echo -n a ) | pygmentize -g | hexdump -C
00000000  61 0a                                             |a.|
00000002

It would be better if pygmentize would preserve whitespace, especially leading/trailing newlines. Otherwise, this poses a problem when integrating it for more advanced purposes, such as VCS diff drivers - such inconsistencies in pygmentize's output can cause artifacts in the resulting diff, or hide actual differences in the data.