Skip to content

Commit c5efac7

Browse files
authored
Add option treat_markdown_warnings_as_error (#2792)
1 parent 41a8d5e commit c5efac7

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## Unreleased
77

8+
### Added
9+
10+
* Added option `treat_markdown_warnings_as_error` which throws an error when encountering a markdown/interpolation warning ([#2792], [#2751])
11+
812
### Changed
913

1014
* Page category is removed from the search index and now everything is in section category. ([#2762], [#2413])
@@ -2161,13 +2165,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21612165
[#2737]: https://github.com/JuliaDocs/Documenter.jl/issues/2737
21622166
[#2748]: https://github.com/JuliaDocs/Documenter.jl/issues/2748
21632167
[#2750]: https://github.com/JuliaDocs/Documenter.jl/issues/2750
2168+
[#2751]: https://github.com/JuliaDocs/Documenter.jl/issues/2751
21642169
[#2753]: https://github.com/JuliaDocs/Documenter.jl/issues/2753
21652170
[#2761]: https://github.com/JuliaDocs/Documenter.jl/issues/2761
21662171
[#2762]: https://github.com/JuliaDocs/Documenter.jl/issues/2762
21672172
[#2772]: https://github.com/JuliaDocs/Documenter.jl/issues/2772
21682173
[#2773]: https://github.com/JuliaDocs/Documenter.jl/issues/2773
21692174
[#2774]: https://github.com/JuliaDocs/Documenter.jl/issues/2774
21702175
[#2787]: https://github.com/JuliaDocs/Documenter.jl/issues/2787
2176+
[#2792]: https://github.com/JuliaDocs/Documenter.jl/issues/2792
21712177
[JuliaLang/julia#36953]: https://github.com/JuliaLang/julia/issues/36953
21722178
[JuliaLang/julia#38054]: https://github.com/JuliaLang/julia/issues/38054
21732179
[JuliaLang/julia#39841]: https://github.com/JuliaLang/julia/issues/39841

src/documents.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ struct User
363363
highlightsig::Bool # assume leading unlabeled code blocks in docstrings to be Julia.
364364
draft::Bool
365365
meta::Dict{Symbol, Any} # default @meta block data for pages
366+
treat_markdown_warnings_as_error::Bool # option to treat markdown warnings as an error
366367
end
367368

368369
"""
@@ -426,6 +427,7 @@ function Document(;
426427
highlightsig::Bool = true,
427428
draft::Bool = false,
428429
meta::Dict{Symbol} = Dict{Symbol, Any}(),
430+
treat_markdown_warnings_as_error::Bool = false,
429431
others...
430432
)
431433

@@ -492,6 +494,7 @@ function Document(;
492494
highlightsig,
493495
draft,
494496
meta,
497+
treat_markdown_warnings_as_error,
495498
)
496499
internal = Internal(
497500
assetsdir(),

src/html/HTMLWriter.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,19 +2436,23 @@ function domify(dctx::DCtx, node::Node, t::MarkdownAST.Table)
24362436
)
24372437
end
24382438

2439-
function domify(::DCtx, ::Node, e::MarkdownAST.JuliaValue)
2440-
@warn(
2441-
"""
2442-
Unexpected Julia interpolation in the Markdown. This probably means that you
2443-
have an unbalanced or un-escaped \$ in the text.
2439+
function domify(dctx::DCtx, ::Node, e::MarkdownAST.JuliaValue)
2440+
message = """
2441+
Unexpected Julia interpolation in the Markdown. This probably means that you have an
2442+
unbalanced or un-escaped \$ in the text.
24442443
24452444
To write the dollar sign, escape it with `\\\$`
24462445
24472446
We don't have the file or line number available, but we got given the value:
24482447
24492448
`$(e.ref)` which is of type `$(typeof(e.ref))`
2450-
"""
2451-
)
2449+
"""
2450+
2451+
if dctx.ctx.doc.user.treat_markdown_warnings_as_error
2452+
error(message)
2453+
else
2454+
@warn(message)
2455+
end
24522456
return string(e.ref)
24532457
end
24542458

src/latex/LaTeXWriter.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -850,18 +850,21 @@ latex(io::Context, node::Node, ::Documenter.MetaNode) = _println(io, "\n")
850850
latex(io::Context, node::Node, ::Documenter.SetupNode) = nothing
851851

852852
function latex(io::Context, node::Node, value::MarkdownAST.JuliaValue)
853-
@warn(
854-
"""
855-
Unexpected Julia interpolation in the Markdown. This probably means that you
856-
have an unbalanced or un-escaped \$ in the text.
853+
message = """
854+
Unexpected Julia interpolation in the Markdown. This probably means that you have an unbalanced
855+
or un-escaped \$ in the text.
857856
858-
To write the dollar sign, escape it with `\\\$`
857+
To write the dollar sign, escape it with `\\\$`
859858
860-
We don't have the file or line number available, but we got given the value:
859+
We don't have the file or line number available, but we got given the value:
861860
862-
`$(value.ref)` which is of type `$(typeof(value.ref))`
863-
"""
864-
)
861+
`$(value.ref)` which is of type `$(typeof(value.ref))`
862+
"""
863+
if io.doc.user.treat_markdown_warnings_as_error
864+
error(message)
865+
else
866+
@warn(message)
867+
end
865868
return latexesc(io, string(value.ref))
866869
end
867870

src/makedocs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ The only case where you may want to consider passing `true` is when you are auto
234234
deploying the documentation for a package release. In that case, `warnonly` should be set
235235
dynamically by checking the relevant environment variables set by the CI system.
236236
237+
**`treat_markdown_warnings_as_error`** can be used to control whether a build fails with error, or
238+
simply prints a warning if it detects unintended julia values within the markdown.
239+
237240
**`workdir`** determines the working directory where `@example` and `@repl` code blocks are
238241
executed. It can be either a path or the special value `:build` (default).
239242

0 commit comments

Comments
 (0)