Skip to content

Commit

Permalink
Handle at-ref replacements that span multiple lines, fixes #224 (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros authored Jan 3, 2024
1 parent 433efde commit ff4a1c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Literate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ function replace_default(content, sym;
# Run some Documenter specific things
if !isdocumenter(config)
## - remove documenter style `@ref`s and `@id`s
push!(repls, r"\[(.*?)\]\(@ref\)" => s"\1") # [foo](@ref) => foo
push!(repls, r"\[(.*?)\]\(@ref .*?\)" => s"\1") # [foo](@ref bar) => foo
push!(repls, r"\[(.*?)\]\(@id .*?\)" => s"\1") # [foo](@id bar) => foo
push!(repls, r"\[([^]]+?)\]\(@ref\)"s => s"\1") # [foo](@ref) => foo
push!(repls, r"\[([^]]+?)\]\(@ref .*?\)"s => s"\1") # [foo](@ref bar) => foo
push!(repls, r"\[([^]]+?)\]\(@id .*?\)"s => s"\1") # [foo](@id bar) => foo
end

# do the replacements
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ content = """
#nb # %% [markdown] {"meta": "data"}
#nb # # Explicit markdown cell with metadata
# It can sometimes happen that a text editor line-wraps [a link which shouldn't
# break](@ref bbaarr)
#=
First multiline
comment
Expand Down Expand Up @@ -441,6 +444,11 @@ const GITLAB_ENV = Dict(
@test occursin("# \\int f(x) dx", script)
@test occursin("# First multiline", script)
@test occursin("# Second multiline comment", script)
@test occursin(
"""
# It can sometimes happen that a text editor line-wraps a link which shouldn't
# break""",
script)

# mdstrings
mdstrings_file = "inputfile_mdstrings.jl"
Expand Down Expand Up @@ -631,6 +639,9 @@ end end
hidden2 * hidden2
````
It can sometimes happen that a text editor line-wraps [a link which shouldn't
break](@ref bbaarr)
First multiline
comment
Expand Down

0 comments on commit ff4a1c2

Please sign in to comment.