pygments / pygments/pygments

pygmentize -g /dev/null produces an empty line

Open
#1,141 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

S-minor T-bug X-imported
Dominant language
Python
Stars
2.2k
Forks
885
PR merge metrics
No merged PRs in 30d

Description

(Original issue 1437 created by cybershadow on 2018-04-11T17:23:20.474823+00:00)

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the pygmentize command's -g handling for input from stdin and reproduce the hexdump examples with empty input, leading newlines, and trailing newlines. Done means the command preserves leading and trailing whitespace and distinguishes empty input from an input containing newline characters.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.