Skip to content

Commit

Permalink
Markdown: support parse(::AbstractString)
Browse files Browse the repository at this point in the history
`Markdown.parse` is documented to accept `AbstractString` but it was
implemented by calling `IOBuffer` on the string argument.  `IOBuffer`,
however, is documented only for `String` arguments.

This commit changes the current `parse(::AbstractString)` to
`parse(::String)` and implements `parse(::AbstractString)` by converting
the argument to `String`.

Now, even `LazyString`s can be parsed to Markdown representation.

Fixes #55732
  • Loading branch information
barucden committed Sep 14, 2024
1 parent 2ee6551 commit 4dae792
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stdlib/Markdown/src/Markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const MARKDOWN_FACES = [

__init__() = foreach(addface!, MARKDOWN_FACES)

parse(markdown::AbstractString; flavor = julia) = parse(IOBuffer(markdown), flavor = flavor)
parse(markdown::String; flavor = julia) = parse(IOBuffer(markdown), flavor = flavor)
parse(markdown::AbstractString; flavor = julia) = parse(String(markdown), flavor = flavor)
parse_file(file::AbstractString; flavor = julia) = parse(read(file, String), flavor = flavor)

function mdexpr(s, flavor = :julia)
Expand Down
4 changes: 4 additions & 0 deletions stdlib/Markdown/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1308,3 +1308,7 @@ end
# https://github.com/JuliaLang/julia/issues/37757
@test insert_hlines(nothing) === nothing
end

@testset "Lazy Strings" begin
@test Markdown.parse(lazy"foo") == Markdown.parse("foo")
end

0 comments on commit 4dae792

Please sign in to comment.