Skip to content

Commit

Permalink
Make sure we have LF line endings only.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Aug 13, 2018
1 parent e011a18 commit 6f451f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/DocTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ function doctest(block::Markdown.Code, meta::Dict, doc::Documents.Document, page
meta[:LocalDocTestArguments] = d

for expr in [get(meta, :DocTestSetup, []); get(meta[:LocalDocTestArguments], :setup, [])]
Meta.isexpr(expr, :block) && (expr.head = :toplevel)
@show expr
if Meta.isexpr(expr, :block)
# @show expr.head
(expr.head = :toplevel)
end
@eval sandbox begin
@show LOAD_PATH
@show Base.active_project()
end
Core.eval(sandbox, expr)
end
if occursin(r"^julia> "m, block.code)
Expand Down
7 changes: 3 additions & 4 deletions src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ parsed from.
The keyword argument `skip = N` drops the leading `N` lines from the input string.
"""
function parseblock(code::AbstractString, doc, page; skip = 0, keywords = true)
# work only with LF line endings internally
code = replace(code, "\r\n" => "\n")
# 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
Expand All @@ -128,8 +128,7 @@ function parseblock(code::AbstractString, doc, page; skip = 0, keywords = true)
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)
(QuoteNode(keyword), cursor + lastindex(line) + 1) # +1 for single byte '\n'
else
try
Meta.parse(code, cursor)
Expand Down

0 comments on commit 6f451f3

Please sign in to comment.