Skip to content

Commit

Permalink
Add support for ANSI colors in output
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
kimikage and fredrikekre committed Jul 6, 2021
1 parent 6c8679b commit 7d79d3b
Show file tree
Hide file tree
Showing 15 changed files with 646 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Documenter.jl changelog


## Version `v0.27.4`

* ![Feature][badge-feature] `@example`- and `@repl`-blocks now support colored output by mapping ANSI escape sequences to HTML. This requires Julia >= 1.6 and passing `ansicolor=true` to `Documenter.HTML` (e.g. `makedocs(format=Documenter.HTML(ansicolor=true, ...), ...)`). In Documenter 0.28.0 this will be the default so to (preemptively) opt-out pass `ansicolor=false`. ([#1441][github-1441])

## Version `v0.27.3`

* ![Feature][badge-feature] Documenter can now deploy documentation directly to the "root" instead of versioned folders. ([#1615][github-1615], [#1616][github-1616])
Expand Down Expand Up @@ -784,6 +789,7 @@
[github-1430]: https://github.com/JuliaDocs/Documenter.jl/pull/1430
[github-1435]: https://github.com/JuliaDocs/Documenter.jl/pull/1435
[github-1438]: https://github.com/JuliaDocs/Documenter.jl/issues/1438
[github-1441]: https://github.com/JuliaDocs/Documenter.jl/pull/1441
[github-1448]: https://github.com/JuliaDocs/Documenter.jl/pull/1448
[github-1440]: https://github.com/JuliaDocs/Documenter.jl/pull/1440
[github-1449]: https://github.com/JuliaDocs/Documenter.jl/issues/1449
Expand Down
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.27.3"

[deps]
ANSIColoredPrinters = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand All @@ -17,6 +18,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[compat]
ANSIColoredPrinters = "0.0.1"
DocStringExtensions = "0.4, 0.5, 0.6, 0.7, 0.8"
IOCapture = "0.2"
JSON = "0.19, 0.20, 0.21"
Expand Down
2 changes: 2 additions & 0 deletions assets/html/scss/documenter-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ html.theme--#{$themename} {
// }
// }

@import "documenter/ansicolors";

// FIXME: Hack to get a proper theme for highlight.js in the Darkly theme
@import "highlightjs/a11y-dark";
// Also, a11y-dark does not highlight string interpolation properly.
Expand Down
2 changes: 2 additions & 0 deletions assets/html/scss/documenter-light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
@import "documenter/patches";
@import "documenter/layout/all";

@import "documenter/ansicolors";

// Workaround to compile in highlightjs theme, so that we could have different
// themes for both
@import "highlightjs/default"
216 changes: 216 additions & 0 deletions assets/html/scss/documenter/_ansicolors.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
$ansi-black: $black-ter !default;
$ansi-red: null !default;
$ansi-green: null !default;
$ansi-yellow: null !default;
$ansi-blue: null !default;
$ansi-magenta: null !default;
$ansi-cyan: null !default;
$ansi-white: $grey-lighter !default;

$ansi-light-black: null !default;
$ansi-light-red: null !default;
$ansi-light-green: null !default;
$ansi-light-yellow: null !default;
$ansi-light-blue: null !default;
$ansi-light-magenta: null !default;
$ansi-light-cyan: null !default;
$ansi-light-white: $white-ter !default;

@if $documenter-is-dark-theme {
$ansi-red: $red !default;
$ansi-green: $green !default;
$ansi-yellow: $yellow !default;
$ansi-blue: $blue !default;
$ansi-magenta: $purple !default;
$ansi-cyan: $turquoise !default;

$ansi-light-black: $grey-light !default;

$ansi-light-red: lighten($ansi-red, 15) !default;
$ansi-light-green: lighten($ansi-green, 15) !default;
$ansi-light-yellow: lighten($ansi-yellow, 10) !default;
$ansi-light-blue: lighten($ansi-blue, 15) !default;
$ansi-light-magenta: lighten($ansi-magenta, 10) !default;
$ansi-light-cyan: lighten($ansi-cyan, 15) !default;
}

@else {
$ansi-light-red: $red !default;
$ansi-light-green: $green !default;
$ansi-light-yellow: $yellow !default;
$ansi-light-blue: $blue !default;
$ansi-light-magenta: $purple !default;
$ansi-light-cyan: $turquoise !default;

$ansi-light-black: $grey !default;

$ansi-red: darken($ansi-light-red, 10) !default;
$ansi-green: darken($ansi-light-green, 10) !default;
$ansi-yellow: darken($ansi-light-yellow, 18) !default;
$ansi-blue: darken($ansi-light-blue, 10) !default;
$ansi-magenta: darken($ansi-light-magenta, 15) !default;
$ansi-cyan: darken($ansi-light-cyan, 10) !default;
}

.ansi span {
&.sgr1 {
font-weight: bolder;
}

&.sgr2 {
font-weight: lighter;
}

&.sgr3 {
font-style: italic;
}

&.sgr4 {
text-decoration: underline;
}

&.sgr7 {
color: $body-background-color;
background-color: $text;
}

&.sgr8 {
color: transparent;

span {
color: transparent;
}
}

&.sgr9 {
text-decoration: line-through;
}

&.sgr30 {
color: $ansi-black;
}

&.sgr31 {
color: $ansi-red;
}

&.sgr32 {
color: $ansi-green;
}

&.sgr33 {
color: $ansi-yellow;
}

&.sgr34 {
color: $ansi-blue;
}

&.sgr35 {
color: $ansi-magenta;
}

&.sgr36 {
color: $ansi-cyan;
}

&.sgr37 {
color: $ansi-white;
}

&.sgr40 {
background-color: $ansi-black;
}

&.sgr41 {
background-color: $ansi-red;
}

&.sgr42 {
background-color: $ansi-green;
}

&.sgr43 {
background-color: $ansi-yellow;
}

&.sgr44 {
background-color: $ansi-blue;
}

&.sgr45 {
background-color: $ansi-magenta;
}

&.sgr46 {
background-color: $ansi-cyan;
}

&.sgr47 {
background-color: $ansi-white;
}

&.sgr90 {
color: $ansi-light-black;
}

&.sgr91 {
color: $ansi-light-red;
}

&.sgr92 {
color: $ansi-light-green;
}

&.sgr93 {
color: $ansi-light-yellow;
}

&.sgr94 {
color: $ansi-light-blue;
}

&.sgr95 {
color: $ansi-light-magenta;
}

&.sgr96 {
color: $ansi-light-cyan;
}

&.sgr97 {
color: $ansi-light-white;
}

&.sgr100 {
background-color: $ansi-light-black;
}

&.sgr101 {
background-color: $ansi-light-red;
}

&.sgr102 {
background-color: $ansi-light-green;
}

&.sgr103 {
background-color: $ansi-light-yellow;
}

&.sgr104 {
background-color: $ansi-light-blue;
}

&.sgr105 {
background-color: $ansi-light-magenta;
}

&.sgr106 {
background-color: $ansi-light-cyan;
}

&.sgr107 {
background-color: $ansi-light-white;
}
}
81 changes: 81 additions & 0 deletions assets/html/themes/documenter-dark.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7d79d3b

Please sign in to comment.