Skip to content

Commit

Permalink
Fix parsing of double CRLF newline. (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Aug 14, 2018
1 parent 61a3ae2 commit fe8a644
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,17 @@ function parseblock(code::AbstractString, doc, page; skip = 0, keywords = true)
# Drop `skip` leading lines from the code block. Needed for deprecated `{docs}` syntax.
code = string(code, '\n')
code = last(split(code, '\n', limit = skip + 1))
# Check whether we have windows-style line endings.
offset = occursin("\n\r", code) ? 2 : 1
endofstr = lastindex(code)
results = []
cursor = 1
while cursor < endofstr
# Check for keywords first since they will throw parse errors if we `parse` them.
line = match(r"^(.+)$"m, SubString(code, cursor)).captures[1]
line = match(r"^(.*)\r?\n"m, SubString(code, cursor)).match
keyword = Symbol(strip(line))
(ex, ncursor) =
if keywords && haskey(Docs.keywords, keyword)
# adding offset below should be OK, as `\n` and `\r` are single byte
(QuoteNode(keyword), cursor + lastindex(line) + offset)
# TODO: On 0.7 Symbol("") is in Docs.keywords, remove that check when dropping 0.6
if keywords && (haskey(Docs.keywords, keyword) || keyword == Symbol(""))
(QuoteNode(keyword), cursor + lastindex(line))
else
try
Meta.parse(code, cursor)
Expand Down
14 changes: 14 additions & 0 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ end
@test startswith(output, "println\n[ Info: @info\n┌ Warning: depwarn\n")
end
end

@testset "issue #749, #790" begin
let parse(x) = Documenter.Utilities.parseblock(x, nothing, nothing)
for LE in ("\r\n", "\n")
l1, l2, l3 = parse("x = Int[]$(LE)$(LE)push!(x, 1)$(LE)")
@test l1[1] == :(x = Int[])
@test l1[2] == "x = Int[]$(LE)"
@test l2[1] == QuoteNode(Symbol(""))
@test l2[2] == "$(LE)"
@test l3[1] == :(push!(x, 1))
@test l3[2] == "push!(x, 1)$(LE)"
end
end
end
end

end

0 comments on commit fe8a644

Please sign in to comment.