From bce8f0441edae17d31abc7e7e7541659d4658704 Mon Sep 17 00:00:00 2001 From: Denis Barucic Date: Fri, 20 Sep 2024 22:23:06 +0200 Subject: [PATCH] Markdown: support `parse(::AbstractString)` (#55747) `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 --- stdlib/Markdown/src/Markdown.jl | 3 ++- stdlib/Markdown/test/runtests.jl | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/Markdown/src/Markdown.jl b/stdlib/Markdown/src/Markdown.jl index 1832e3a6a6956..0d45d9e534df2 100644 --- a/stdlib/Markdown/src/Markdown.jl +++ b/stdlib/Markdown/src/Markdown.jl @@ -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) diff --git a/stdlib/Markdown/test/runtests.jl b/stdlib/Markdown/test/runtests.jl index ffdb735f3b7cd..35608f75b2426 100644 --- a/stdlib/Markdown/test/runtests.jl +++ b/stdlib/Markdown/test/runtests.jl @@ -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