From: Vladimír Vondruš
ANSI color escape code highlighting
-![mosra@don-perverzo m.css]$
ââ ââ ââ ââ ââ ââ ââ
+
diff --git a/plugins/ansilexer.py b/plugins/ansilexer.py
index d9d12e39..e22686b7 100644
--- a/plugins/ansilexer.py
+++ b/plugins/ansilexer.py
@@ -86,8 +86,8 @@ class AnsiLexer(RegexLexer):
('\x1b\\[(\\d+)(;\\d+)?m([^\x1b]*)', callback)]
}
-_ansi_fg_color_re = re.compile('class="g g-AnsiForegroundColor([0-9a-f]{6})"')
-_ansi_fg_bg_color_re = re.compile('class="g g-AnsiForegroundBackgroundColor([0-9a-f]{6})"')
+_ansi_fg_color_re = re.compile('class="g g-AnsiForegroundColor([0-9a-f]{6})">')
+_ansi_fg_bg_color_re = re.compile('class="g g-AnsiForegroundBackgroundColor([0-9a-f]{6})">')
class HtmlAnsiFormatter(HtmlFormatter):
def wrap(self, source, outfile):
@@ -96,7 +96,12 @@ class HtmlAnsiFormatter(HtmlFormatter):
def _wrap_code(self, source):
for i, t in source:
if i == 1: # it's a line of formatted code
- t = _ansi_fg_bg_color_re.sub('style="color: #\\1; background-color: #\\1"', t)
- t = _ansi_fg_color_re.sub('style="color: #\\1"', t)
+ # Add ZWNJ for before each character because otherwise it's
+ # somehow impossible to wrap even with word-break: break-all.
+ # Not sure why (and not sure if this is the best solution), but
+ # had to ship a thing so there it is. Adding ![mosra@don-perverzo m.css]$
ââ ââ ââ ââ ââ ââ ââ
- ââ ââ ââ ââ
+Leading zeros: ââ ââ
+
+ ââ ââ ââ ââcode
.
Console colors:
-ââ ââ ââ ââ ââ ââ ââ +ââ ââ ââ ââ ââ ââ ââ -Leading zeros: ââ ââ +Leading zeros: ââ ââ - ââ ââ ââ ââ+ ââ ââ ââ ââ
// this language is not highlighted
Properly preserve backslashes: \frac{a}{b}
Don't trim leading spaces in blocks: