From 3c7fd698b0a0e90a1e3975cfe734c71046d38385 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Tue, 27 Jul 2021 00:00:27 +0200 Subject: [PATCH] Fix assertion with trailing comment in at-code blocks, fixes #1655. --- CHANGELOG.md | 5 +++++ src/Utilities/Utilities.jl | 2 +- test/utilities.jl | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a2f713f47b..528654d5b60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Documenter.jl changelog +## Version `v0.27.5` + +* ![Bugfix][badge-bugfix] Fix an error introduced in version `v0.27.4` (PR[#1634][github-1634]) which was triggered by trailing comments in `@eval`/`@repl`/`@example` blocks. ([#1655](github-1655), [#](github-)) + ## 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], [#1628][github-1628], [#1629][github-1629], [#1647][github-1647]) @@ -888,6 +892,7 @@ [github-1645]: https://github.com/JuliaDocs/Documenter.jl/pull/1645 [github-1647]: https://github.com/JuliaDocs/Documenter.jl/pull/1647 [github-1649]: https://github.com/JuliaDocs/Documenter.jl/pull/1649 +[github-1655]: https://github.com/JuliaDocs/Documenter.jl/issues/1655 [julia-38079]: https://github.com/JuliaLang/julia/issues/38079 [julia-39841]: https://github.com/JuliaLang/julia/pull/39841 diff --git a/src/Utilities/Utilities.jl b/src/Utilities/Utilities.jl index 8a4aa175fd3..00d321fac97 100644 --- a/src/Utilities/Utilities.jl +++ b/src/Utilities/Utilities.jl @@ -118,7 +118,7 @@ function parseblock(code::AbstractString, doc, file; skip = 0, keywords = true, end end str = SubString(code, cursor, prevind(code, ncursor)) - if !isempty(strip(str)) + if !isempty(strip(str)) && ex !== nothing push!(results, (ex, str)) end cursor = ncursor diff --git a/test/utilities.jl b/test/utilities.jl index 8bc17ca58e4..ad2b4978c58 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -299,6 +299,46 @@ end end end + @testset "PR #1634, issue #1655" begin + let parse(x) = Documenter.Utilities.parseblock(x, nothing, nothing; + linenumbernode=LineNumberNode(123, "testfile.jl") + ) + code = """ + 1 + 1 + 2 + 2 + """ + exs = parse(code) + @test length(exs) == 2 + @test exs[1][2] == "1 + 1\n" + @test exs[1][1].head == :toplevel + @test exs[1][1].args[1] == LineNumberNode(124, "testfile.jl") + @test exs[1][1].args[2] == Expr(:call, :+, 1, 1) + @test exs[2][2] == "2 + 2\n" + @test exs[2][1].head == :toplevel + @test exs[2][1].args[1] == LineNumberNode(125, "testfile.jl") + @test exs[2][1].args[2] == Expr(:call, :+, 2, 2) + + # corner case trailing whitespace + code1 = """ + 1 + 1 + + """ + # corner case: trailing comment + code2 = """ + 1 + 1 + # comment + """ + for code in (code1, code2) + exs = parse(code) + @test length(exs) == 1 + @test exs[1][2] == "1 + 1\n" + @test exs[1][1].head == :toplevel + @test exs[1][1].args[1] == LineNumberNode(124, "testfile.jl") + @test exs[1][1].args[2] == Expr(:call, :+, 1, 1) + end + end + end + @testset "mdparse" begin mdparse = Documenter.Utilities.mdparse