-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for ANSI colors #1441
Conversation
7975d02
to
f2ea031
Compare
Nice! Is there ever a reason not to have this by default? Perhaps we can just look at the command line flag instead. |
One problem with
Do you have any other good ideas? |
I think this is fine. |
I also think it's the safer of the three. Even if we don't offer the colored |
There is still a lot of work to be done, but the As suggested in #1441 (comment), instead of adding the |
Currently, I added the |
028d64e
to
56a1e81
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've put an ANSI escape code translator for HTML in a new package AnsiColoredPrinters.jl to make this feature work. The package is experimental and under development, and there are things left to be discussed before it is registered, including the name of the package. I won't refuse to contribute it as part of Documenter.jl, but I prefer to modularize the functionality into minimal packages.
I think the functionality is quite well-defined and general, so it make sense to have it as a separate package. Would you mind having that under the JuliaDocs umbrella though?
I would love to have you as its primary maintainer, but it would be good if there is a wider set of people who would can, if need be, release quick fixes, since the Julia master branch will be depending on this code.
After making some miscellaneous changes (I think they will take about a week), I'd like to transfer the package to JuliaDocs. 😃 However, before we do that, we need to decide on the package name. Even if it is based on the current name, I'd like to change "Ansi" to "ANSI". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, before we do that, we need to decide on the package name. Even if it is based on the current name, I'd like to change "Ansi" to "ANSI".
I also think that the capitalized name would look better.
|
Sorry I haven't been able to update this PR. I will try to |
b9341bf
to
cc0f26a
Compare
It also looks like hljs overrules things like
turning it into
|
For
perhaps we need to emit something like
i.e. split into two blocks where only the first is used with hljs |
I have some fixes for my last two comments which I can push after. I think that this PR can be merged once the dark theme css is fixed and I will make a follow up PR: |
OMG in the test package I tried this on I had a custom css file overriding the documenter one..... |
I was considering the approach of writing a highlight.js plugin, but the plugin API does not work well with DOM manipulation. In this PR, I will postpone the ansi color support for |
Sounds good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
Thank you guys for working on this! Fredrik and I briefly discussed this on Slack how to proceed with this in terms of versions:
Otherwise, if Fredrik is happy with this, then from my side this just needs a CHANGELOG entry. |
I pushed those changes and added docs + changelog. |
- Adds `ansicolor::Bool=false` option to `Documenter.HTML` for enabling/disabling mapping of ANSI escape codes to HTML. - Adds option to locally disable/enable color using the `ansicolor` keyword argument in the `@example`/`@repl` block. - Add styles for ANSI colors to the default themes Co-authored-by: kimikage <kimikage.ceo@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
This starts from a Discourse topic: https://discourse.julialang.org/t/how-do-i-enable-ansi-colored-text-output-within-documenter-jl/48398
This changes:
add a new field / argumentansicolor
toUser
/makedocs()
for global settingansicolor
in the@example
blockansicolor
option for the:color
I/O context propertyHTMLWriter
These changes allow you to colorize the lazy print objects in the
@example
output blocks.However, there are some issues to be resolved.
I've put an ANSI escape code translator for HTML in a new package
AnsiColoredPrinters.jl
to make this feature work. The package is experimental and under development, and there are things left to be discussed before it is registered, including the name of the package. I won't refuse to contribute it as part of Documenter.jl, but I prefer to modularize the functionality into minimal packages.The other is that currently there is no way to specify the
:color
I/O context property for output tostdout
/stderr
. (Edit: solved by JuliaDocs/IOCapture.jl#1)This means that even if the@example
or@repl
code potentially supports ANSI colors, we cannot get the colored result.Also, althoughwe need to strip the ANSI escape codes if the output format does not support ANSI colors. (This will be implemented soon.)ansicolor
isfalse
by default and is the responsibility of the user,When the solutions for the above are found, we will need to discuss the compatibility with
highlight.js
, the theme for system 16 colors, etc.