diff --git a/stdlib/Markdown/docs/src/index.md b/stdlib/Markdown/docs/src/index.md index 44f2f2dbfd6881..47ec8cc793b4c3 100644 --- a/stdlib/Markdown/docs/src/index.md +++ b/stdlib/Markdown/docs/src/index.md @@ -398,3 +398,11 @@ complex features (such as references) without cluttering the basic syntax. In principle, the Markdown parser itself can also be arbitrarily extended by packages, or an entirely custom flavour of Markdown can be used, but this should generally be unnecessary. + +## [Markdown String Literals](@id stdlib-markdown-literals) + +Markdown strings can be constructed using the string literal syntax `md"..."`. + +```@docs +Markdown.@md_str +``` diff --git a/stdlib/Markdown/src/Markdown.jl b/stdlib/Markdown/src/Markdown.jl index 781fcbdafddc84..50dcec199031df 100644 --- a/stdlib/Markdown/src/Markdown.jl +++ b/stdlib/Markdown/src/Markdown.jl @@ -40,6 +40,18 @@ function docexpr(source::LineNumberNode, mod::Module, s, flavor = :julia) :($doc_str($(mdexpr(s, flavor)), $(QuoteNode(source)), $mod)) end +""" + macro md_str(s) + +Parse the given string as Markdown text and return a corresponding `Markdown.MD` object. + +# Example +```jldoctest +julia> Markdown.html(md"# Hello, world!") +"

Hello, world!

\\n" + +``` +""" macro md_str(s, t...) mdexpr(s, t...) end