From: Vladimír Vondruš Date: Tue, 30 Apr 2019 21:30:25 +0000 (+0200) Subject: m.code: add ZWNJ before ANSI colored squares. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=c2acda77aba93d05cb12c98c904e8ba4bb4b2882;p=blog.git m.code: add ZWNJ before ANSI colored squares. Otherwise it wasn't wrapping even with .m-console-wrap. Not sure why, didn't work either. --- diff --git a/documentation/test_doxygen/contents_code_language/ansi.html b/documentation/test_doxygen/contents_code_language/ansi.html index 4457075d..d5aa5488 100644 --- a/documentation/test_doxygen/contents_code_language/ansi.html +++ b/documentation/test_doxygen/contents_code_language/ansi.html @@ -22,9 +22,11 @@

ANSI color escape code highlighting

-
![mosra@don-perverzo m.css]$ 
██ ██ ██ ██ ██ ▓▓ ▒▒
+
![mosra@don-perverzo m.css]$ 
‌██ ‌██ ‌██ ‌██ ‌██ ‌▓▓ ‌▒▒
 
-      ░░ ▒▒ ▓▓ ██
+Leading zeros: ‌▒▒ ‌▒▒ + + ‌░░ ‌▒▒ ‌▓▓ ‌██
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 did not + # help. + t = _ansi_fg_bg_color_re.sub('style="color: #\\1; background-color: #\\1">‌', t) + t = _ansi_fg_color_re.sub('style="color: #\\1">‌', t) #t += 'H' yield i, t diff --git a/plugins/m/test/code/page.html b/plugins/m/test/code/page.html index 7d50e386..55d10880 100644 --- a/plugins/m/test/code/page.html +++ b/plugins/m/test/code/page.html @@ -35,11 +35,11 @@ rendered as plain monospace text: code.

CONTRIBUTING.rst CREDITS.rst doc plugins README.rst COPYING css documentation pelican-theme site

Console colors:

-
██ ██ ██ ██ ██ ▓▓ ▒▒
+
‌██ ‌██ ‌██ ‌██ ‌██ ‌▓▓ ‌▒▒
 
-Leading zeros: ▒▒ ▒▒
+Leading zeros: ‌▒▒ ‌▒▒
 
-      ░░ ▒▒ ▓▓ ██
+ ‌░░ ‌▒▒ ‌▓▓ ‌██
// this language is not highlighted

Properly preserve backslashes: \frac{a}{b}

Don't trim leading spaces in blocks: