Skip to content

Commit ced42e5

Browse files
authored
Allow renderers to override _any_color_fmt. (#2490)
1 parent e247c79 commit ced42e5

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
* Added anchor links to admonition blocks, making it possible to create direct links to specific admonitions. ([#2505], [#2676], [#2688])
1111
* Added different banners for dev and unreleased docs ([#2382], [#2682])
12+
* Added an API function `writer_supports_ansicolor` for a Documenter writer to indicate that it supports rendering ANSI-colored strings. This is useful for new backends that may be implemented. ([#2490])
1213

1314
### Fixed
1415

@@ -1383,7 +1384,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13831384

13841385
* The at-blocks now support `MIME"text/html"` rendering of objects (e.g. for interactive plots). I.e. if a type has `show(io, ::MIME"text/html", x)` defined, Documenter now uses that when rendering the objects in the document. ([#764])
13851386

1386-
* Addeds to the sidebar. When loading a page, the sidebar will jump to the current page now. Also, the scrollbar in WebKit-based browsers look less intrusive now. ([#792], [#854], [#863])
1387+
* Added to the sidebar. When loading a page, the sidebar will jump to the current page now. Also, the scrollbar in WebKit-based browsers look less intrusive now. ([#792], [#854], [#863])
13871388

13881389
* Minor style enhancements to admonitions. ([#841])
13891390

@@ -1987,6 +1988,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19871988
[#2480]: https://github.com/JuliaDocs/Documenter.jl/issues/2480
19881989
[#2482]: https://github.com/JuliaDocs/Documenter.jl/issues/2482
19891990
[#2485]: https://github.com/JuliaDocs/Documenter.jl/issues/2485
1991+
[#2490]: https://github.com/JuliaDocs/Documenter.jl/pull/2490
19901992
[#2496]: https://github.com/JuliaDocs/Documenter.jl/issues/2496
19911993
[#2497]: https://github.com/JuliaDocs/Documenter.jl/issues/2497
19921994
[#2499]: https://github.com/JuliaDocs/Documenter.jl/issues/2499

docs/src/lib/public.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,12 @@ DocumenterTools.generate
4040
DocumenterTools.genkeys
4141
DocumenterTools.OutdatedWarning.generate
4242
```
43+
44+
## Extensions
45+
46+
These APIs are intended for extension and plugin authors to use.
47+
They would normally not be relevant for usual end-users.
48+
49+
```@docs
50+
Documenter.writer_supports_ansicolor
51+
```

src/expander_pipeline.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,13 +784,25 @@ end
784784
# @example
785785
# --------
786786

787-
# Find if there is any format with color output
787+
# Find if there is any format with color output.
788788
function _any_color_fmt(doc)
789-
idx = findfirst(x -> x isa Documenter.HTML, doc.user.format)
789+
idx = findfirst(writer_supports_ansicolor, doc.user.format)
790790
idx === nothing && return false
791791
return doc.user.format[idx].ansicolor
792792
end
793793

794+
# General fallback.
795+
"""
796+
writer_supports_ansicolor(::Documenter.Writer)::Bool
797+
798+
Returns whether the writer supports ANSI-colored output (`true`) or not (`false`).
799+
800+
This is usually relevant in Documenter blocks that execute code, like `@example` or `@repl`.
801+
802+
If `true`, these blocks will call `show` on the returned Julia object with `color = true`. If `false`, then show is called with `color=false`.
803+
"""
804+
writer_supports_ansicolor(::Writer) = false
805+
794806
function Selectors.runner(::Type{Expanders.ExampleBlocks}, node, page, doc)
795807
@assert node.element isa MarkdownAST.CodeBlock
796808
x = node.element

src/html/HTMLWriter.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@ struct HTML <: Documenter.Writer
581581
end
582582
end
583583

584+
# HTML accepts ANSI, so this is `true`.
585+
Documenter.writer_supports_ansicolor(::HTML) = true
586+
587+
584588
# Cache of downloaded highlight.js bundles
585589
const HLJSFILES = Dict{String, String}()
586590
# Look for node and highlight.js

0 commit comments

Comments
 (0)