Skip to content

Commit

Permalink
[WIP] Add support for ANSI colors
Browse files Browse the repository at this point in the history
This changes:
- add a new field / argument `ansicolor` to `User` / `makedocs()`
  - for global setting
- add support for a keyword argument `ansicolor` in the `@example` block
  - for per-block setting to overide the global setting
- use the `ansicolor` option for the `:color` I/O context property
- translate "text/plain" output with ANSI escape codes in `HTMLWriter`
- add styles for ANSI colors to the default themes
  • Loading branch information
kimikage committed Oct 19, 2020
1 parent f7c13a4 commit 7975d02
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linkcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
with:
version: '1.5'
- name: Install dependencies
run: julia --color=yes --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
run: julia --color=yes --project=docs/ -e 'using Pkg; Pkg.add(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main"); Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate();'
- name: Build and check documentation
run: julia --color=yes --project=docs/ docs/make.jl
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ branches:
- /^release-.*$/
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/

script:
- | # FIXME: use default script
julia --project -e '
using Pkg
Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main"))
Pkg.instantiate()
Pkg.test(; coverage=true)
'
after_success:
- if [ -f test/quietly.log ]; then cat test/quietly.log; fi
- if [[ $TRAVIS_JULIA_VERSION = 1.1 ]] && [[ $TRAVIS_OS_NAME = linux ]]; then
Expand All @@ -29,13 +37,14 @@ jobs:
include:
- stage: "Additional tests"
script:
- julia --project=test/themes -e 'using Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))'
- julia --project=test/themes -e 'using Pkg; Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main")); Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))'
- julia --project=test/themes test/themes/themes.jl
name: "Themes"
- script:
- |
julia --project=test/examples -e '
using Pkg
Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main"))
Pkg.instantiate()
Pkg.develop(PackageSpec(path=pwd()))
Pkg.add(["IOCapture", "DocumenterMarkdown"])
Expand All @@ -44,12 +53,12 @@ jobs:
name: "PDF/LaTeX backend"
- stage: "Documentation"
script:
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- julia --project=docs/ -e 'using Pkg; Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main")); Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- julia --project=docs/ docs/make.jl skiplinks
name: "HTML"
after_success: skip
- script:
- julia --project=docs/pdf/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- julia --project=docs/pdf/ -e 'using Pkg; Pkg.add(PackageSpec(url="https://github.com/kimikage/AnsiColoredPrinters.jl", rev="main")); Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- julia --project=docs/pdf/ docs/pdf/make.jl
name: "PDF"
after_success: skip
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.25.2"

[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.1"
DocStringExtensions = "0.4, 0.5, 0.6, 0.7, 0.8"
IOCapture = "0.1"
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 @@ -90,6 +90,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"
83 changes: 82 additions & 1 deletion assets/html/themes/documenter-dark.css

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

120 changes: 120 additions & 0 deletions assets/html/themes/documenter-light.css

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

11 changes: 11 additions & 0 deletions docs/src/showcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ println("Hello World")
42
```

**TODO:** `ansicolor` keyword argument.
````markdown
```@example ; ansicolor = true
code_typed(sqrt, (Float64,))
```
````

```@example ; ansicolor = true
code_typed(sqrt, (Float64,))
```

### REPL-type

[`@repl` block](@ref) can be used to simulate the REPL evaluation of code blocks. For example, the following block
Expand Down
7 changes: 5 additions & 2 deletions src/Documents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ struct User
authors :: String
version :: String # version string used in the version selector by default
highlightsig::Bool # assume leading unlabeled code blocks in docstrings to be Julia.
ansicolor::Bool # enable ANSI color codes, i.e. `:color => true` in io context.
end

"""
Expand Down Expand Up @@ -284,8 +285,9 @@ function Document(plugins = nothing;
repo :: AbstractString = "",
sitename :: AbstractString = "",
authors :: AbstractString = "",
version :: AbstractString = "",
version :: AbstractString = "",
highlightsig::Bool = true,
ansicolor:: Bool = false,
others...
)
Utilities.check_kwargs(others)
Expand Down Expand Up @@ -318,7 +320,8 @@ function Document(plugins = nothing;
sitename,
authors,
version,
highlightsig
highlightsig,
ansicolor
)
internal = Internal(
Utilities.assetsdir(),
Expand Down
Loading

0 comments on commit 7975d02

Please sign in to comment.