fredrikekre / Literate.jl

Simple package for literate programming in Julia
https://fredrikekre.github.io/Literate.jl
Other
534 stars 61 forks source link

Correctly handle refs that span multiple lines #233

Closed kbarros closed 8 months ago

kbarros commented 8 months ago

Fixes https://github.com/fredrikekre/Literate.jl/issues/224.

The new regexes have the following behavior:

repls = []
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

content = """
    # # [Example](@id example-id)
    # [foo](@ref), [bar](@ref bbaarr)
    x = 1
    """
for repl in repls
    content = replace(content, repl)
end
@assert content == """
    # # Example
    # foo, bar
    x = 1
    """

content = """
    # # [Example](@id example-id)
    #
    # [This is a long example which
    # wraps a line](@ref)
    #
    # [In this case the](@ref reference also
    # wraps a line)
    #    
    # x = 1
    """
for repl in repls
    content = replace(content, repl)
end
@assert content == """
    # # Example
    #
    # This is a long example which
    # wraps a line
    #
    # In this case the
    #    
    # x = 1
    """
fredrikekre commented 8 months ago

Thanks, will make a new release.