Skip to content

Commit

Permalink
Correctly highlight multiline console input, even without PS2 prompt (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessetan committed Jun 4, 2021
1 parent 3e9fe3a commit d228fc7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
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

0 comments on commit d228fc7

Please sign in to comment.