A user reported that colors used for cterm color codes 0-15 are not correct for 256-bit color terminals.
From email:
The actual colors a user sees with syntax highlighting are very much terminal-dependent. For example, on GNOME Terminal, the user can pick among several color palettes, which directly influence the resulting colors. But this part of the 2html.vim file is the "best guess if we can't determine" section, and as such, should reflect the standard colors.
To be perfectly honest, I could only find the standard color mappings for xterm-256, and two different charts (both found on Wikipedia) agreed:
https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg
If the above references are correct, then at a minimum, in 256-color mode, the color mappings in 2html.vim are incorrect for color codes 1,3,4,5,9,12,13.
Currently the conditional clauses in this file "cascade" so that the values for 16-color mode are also used for 88- and 256-color modes. I couldn't find a standard reference for 8-color and 16-color mappings, but if there is one, and if the "correct" values for those modes are the ones currently listed in the 2html.vim file, then I'll need to revise my patch so that the first 16 values for 256-color mode are defined specifically for that mode.
It's possible that whoever wrote the initial file entered the "correct" values for 8-color and 16-color, and mistakenly assumed that 256-color shared the same first 16 values as 16-color mode. If that's the case, then my patch is wrong, since I clearly made the opposite assumption.
I found the authoritative source code for xterm colors for both 88-color mode and 256-color mode ( https://invisible-island.net/xterm/xterm.faq.html#latest_version ). I can confirm that the current 2html.vim isn't quite right, but my previous proposed batch is the wrong solution. Also, the creator of Xterm mentioned this:
ANSI specified eight (8) colors. In fact, ANSI did not specify the appearance. That is an implementation detail.
( https://invisible-island.net/xterm/xterm.faq.html#bold_vs_16colors )
Considering all of this, I now think the best approach is to leave the current 8-color and 16-color mappings as they are, and then implement a second set of mappings for codes 0-15 to use specifically with the xterm-88 and xterm-256 modes.
here's the patch:
https://github.com/msp0/vim/commit/6ec5fce1b4b43b070601809260ea56e53d78343a
maybe there's a better approach anyway. As far as I can tell, the rendering of color codes above 15 should be dependable across terminals. But color codes 0-15 are highly variable and easy for the user to manipulate on some terminals. If there were some way for the user to select among different color profiles for the 0-15 range when calling TOhtml, that might be more user-friendly than my patch. My patch incorporates the "official" xterm colors, but many users will have their terminals set to different colors for codes 0-15. For example, on gnome-terminal, there are 5 built-in color profiles (Tango, Linux console, XTerm, Rxvt, Solarized), plus a Custom option where the user can define 0-15 individually. All of these profiles directly affect the 0-15 range, while the 16-255 range renders always the same, according to the xterm values. I expect other terminals will have their own profiles, too.
Maybe we can collect some common profiles for that range that are out there, code them as options in 2html.vim, and allow the user to add an optional argument when calling TOhtml. I don't know how optional arguments would work in that context, so this suggestion might be unworkable, but something like:
:1,20TOhtml solarized
As I responded via email:
If there's a way to autodetect the color profile that would probably be best. Although we could leave that to a plugin if it is complicated or involves invoking a bunch of shell commands. I've done something like that before with a plugin on Windows to detect all the supported file encodings on the current system and add mappings for them to the file encoding logic. ( https://www.vim.org/scripts/script.php?script_id=3316 )
For this sort of thing, rather than an argument to the :TOhtml command, I'd want to have a global variable so users could put something like "let g:html_term_color_profile = 'tango'" with a default value of the xterm colors. Maybe it could take a list or dictionary as well to specify colors manually.
Last edit: fritzophrenic 2020-07-02
Might be some relevant info in this discussion: https://groups.google.com/forum/#!topic/vim_dev/gCWZsXVUta0