Skip to content

Commit

Permalink
Fix assertion with trailing comment in at-code blocks, fixes #1655.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jul 26, 2021
1 parent 1e8667d commit 3c7fd69
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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])
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3c7fd69

Please sign in to comment.