JuliaDocs / Documenter.jl

A documentation generator for Julia.

Home Page:https://documenter.juliadocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling of ANSI foreground/background inversion is incorrect

tecosaur opened this issue · comments

As I've been doing a round of improvements to the StyledStrings docs, it occurred to me that it would be good to show some styled content. One of the examples I showed was with background colour. Documenter could obtain HTML representations of AnnotatedStrings with the show(::IO, ::MIME"text/html", ::AnnotatedString) method provided by StyledStrings (and I will make another issue on this), but for now I've tried using @repl; ansicolor=true blocks.

When used with styled"{magenta:some {inverse:inverse} text}", Documenter using an IO with :color would see \e[35msome \e[7minverse\e[27m text\e[39m and produces:

image

However, this is not correct. In the terminal one sees this:

image

and StyledStrings produces the following HTML:

<span style="color: #803d9b;">some </span><span style="background-color: #803d9b;">inverse</span><span style="color: #803d9b;"> text</span>

The conversion to HTML is handled by https://github.com/JuliaDocs/ANSIColoredPrinters.jl I believe. cc @kimikage

This is essentially due to the problem that default background and foreground colors (i.e., default inverse colors) are not known at the time the escape codes are interpreted in ANSIColoredPrinters.jl. The actual colors vary with the CSS of the container.
https://juliadocs.org/ANSIColoredPrinters.jl/dev/supported-codes/#Invert

I would like to examine ways to make it easier to solve this problem with CSS.

Linking to #2488 too, something that might be of interest to ANSIColoredPrinters in the future is refactoring to work via applying Faces to the new Base.AnnotatedString type, a 'la (and using) StyledStrings.

BTW, it seems that ANSIColoredPrinters has a parser error when it encounters OSC 8 links.