diff options
| author | Tim Hatch <tim@timhatch.com> | 2016-06-01 00:49:28 -0700 |
|---|---|---|
| committer | Tim Hatch <tim@timhatch.com> | 2016-06-01 00:49:28 -0700 |
| commit | 673514dfa45c7c2eaf3a2e090a0e57c55a4f56c0 (patch) | |
| tree | ed531a7ff14ee15a2fc46dddf75a4da26af3e3bb /pygments/lexers/shell.py | |
| parent | 3ae28f22bfd54db37c8ea2fc5bc48c4c5aef003c (diff) | |
| download | pygments-git-673514dfa45c7c2eaf3a2e090a0e57c55a4f56c0.tar.gz | |
Add backslash-continuation support to console lexer.
Fixes #1237
Diffstat (limited to 'pygments/lexers/shell.py')
| -rw-r--r-- | pygments/lexers/shell.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py index b9368ade..ae790b9e 100644 --- a/pygments/lexers/shell.py +++ b/pygments/lexers/shell.py @@ -137,11 +137,15 @@ class ShellSessionBaseLexer(Lexer): pos = 0 curcode = '' insertions = [] + backslash_continuation = False for match in line_re.finditer(text): line = match.group() m = re.match(self._ps1rgx, line) - if m: + if backslash_continuation: + curcode += line + backslash_continuation = curcode.endswith('\\\n') + elif m: # To support output lexers (say diff output), the output # needs to be broken by prompts whenever the output lexer # changes. @@ -151,10 +155,12 @@ class ShellSessionBaseLexer(Lexer): insertions.append((len(curcode), [(0, Generic.Prompt, m.group(1))])) curcode += m.group(2) + backslash_continuation = curcode.endswith('\\\n') elif line.startswith(self._ps2): insertions.append((len(curcode), [(0, Generic.Prompt, line[:len(self._ps2)])])) curcode += line[len(self._ps2):] + backslash_continuation = curcode.endswith('\\\n') else: if insertions: toks = innerlexer.get_tokens_unprocessed(curcode) |
