Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly highlight multiline console input, even without PS2 prompt #1833

Merged
merged 1 commit into from Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions pygments/lexers/shell.py
Expand Up @@ -192,10 +192,13 @@ def get_tokens_unprocessed(self, text):
[(0, Generic.Prompt, m.group(1))]))
curcode += m.group(2)
backslash_continuation = curcode.endswith('\\\n')
elif line.startswith(self._ps2) and backslash_continuation:
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:len(self._ps2)])]))
curcode += line[len(self._ps2):]
elif backslash_continuation:
if line.startswith(self._ps2):
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:len(self._ps2)])]))
curcode += line[len(self._ps2):]
else:
curcode += line
backslash_continuation = curcode.endswith('\\\n')
else:
if insertions:
Expand Down
16 changes: 16 additions & 0 deletions tests/snippets/console/test_newline_in_echo_no_ps2.txt
@@ -0,0 +1,16 @@
---input---
$ echo \
hi
hi

---tokens---
'$ ' Generic.Prompt
'echo' Name.Builtin
' ' Text
'\\\n' Literal.String.Escape

' ' Text
'hi' Text
'\n' Text

'hi\n' Generic.Output
16 changes: 16 additions & 0 deletions tests/snippets/console/test_newline_in_ls_no_ps2.txt
@@ -0,0 +1,16 @@
---input---
$ ls \
hi
hi

---tokens---
'$ ' Generic.Prompt
'ls' Text
' ' Text
'\\\n' Literal.String.Escape

' ' Text
'hi' Text
'\n' Text

'hi\n' Generic.Output