Skip to content

Commit

Permalink
made Markdown flavors julia, common and github public
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias314 committed Dec 13, 2024
1 parent b1e910e commit 57f4425
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions stdlib/Markdown/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ custom flavour of Markdown can be used, but this should generally be unnecessary
Markdown.MD
Markdown.@md_str
Markdown.@doc_str
Markdown.common
Markdown.github
Markdown.julia
Markdown.parse
Markdown.html
Markdown.latex
Expand Down
7 changes: 7 additions & 0 deletions stdlib/Markdown/src/Common/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ abstract type MarkdownElement end
include("block.jl")
include("inline.jl")

"""
const Markdown.common
A constant indicating the CommonMark flavor of Markdown.
See also [`Markdown.parse`](@ref), [`Markdown.github`](@ref), [`Markdown.julia`](@ref).
"""
@flavor common [list, indentcode, blockquote, admonition, footnote, hashheader, horizontalrule,
paragraph,

Expand Down
7 changes: 7 additions & 0 deletions stdlib/Markdown/src/GitHub/GitHub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ function github_paragraph(stream::IO, md::MD)
return true
end

"""
const Markdown.github
A constant indicating the GitHub flavor of Markdown.
See also [`Markdown.parse`](@ref), [`Markdown.common`](@ref), [`Markdown.julia`](@ref).
"""
@flavor github [list, indentcode, blockquote, admonition, footnote, fencedcode, hashheader,
github_table, github_paragraph,

Expand Down
7 changes: 7 additions & 0 deletions stdlib/Markdown/src/Julia/Julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

include("interp.jl")

"""
const Markdown.julia
A constant indicating Julia's flavor of Markdown.
See also [`Markdown.parse`](@ref), [`Markdown.common`](@ref), [`Markdown.github`](@ref).
"""
@flavor julia [blocktex, blockinterp, hashheader, list, indentcode, fencedcode,
blockquote, admonition, footnote, github_table, horizontalrule, setextheader, paragraph,

Expand Down
11 changes: 7 additions & 4 deletions stdlib/Markdown/src/Markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ include("render/terminal/render.jl")

export @md_str, @doc_str

public MD, parse
public MD, parse, common, github, julia

const MARKDOWN_FACES = [
:markdown_header => Face(weight=:bold),
Expand All @@ -61,11 +61,14 @@ __init__() = foreach(addface!, MARKDOWN_FACES)
parse(markdown::String; flavor = julia) = parse(IOBuffer(markdown), flavor = flavor)

"""
Markdown.parse(markdown::AbstractString) -> MD
Markdown.parse(markdown::AbstractString; flavor = Markdown.julia) -> MD
Parse `markdown` as Julia-flavored Markdown text and return the corresponding `MD` object.
Parse `markdown` as Markdown and return the corresponding `MD` object.
The optional argument `flavor` indicates the Markdown flavor that is used.
It can be `julia` (default), `common` or `github`.
See also [`@md_str`](@ref).
See also [`@md_str`](@ref),
[`Markdown.common`](@ref), [`Markdown.github`](@ref), [`Markdown.julia`](@ref).
"""
parse(markdown::AbstractString; flavor = julia) = parse(String(markdown), flavor = flavor)

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Markdown/src/parse/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const flavors = Dict{Symbol, Config}()

macro flavor(name, features)
quote
const $(esc(name)) = config($(mapany(esc,features.args)...))
Core.@__doc__ const $(esc(name)) = config($(mapany(esc,features.args)...))
flavors[$(Expr(:quote, name))] = $(esc(name))
end
end
8 changes: 6 additions & 2 deletions stdlib/Markdown/src/parse/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ _parse(stream::IO, block::MD; breaking = false) =
_parse(stream, block, config(block), breaking = breaking)

"""
parse(stream::IO) -> MD
parse(stream::IO; flavor = Markdown.julia) -> MD
Parse the content of `stream` as Julia-flavored Markdown text and return the corresponding `MD` object.
Parse the content of `stream` as Markdown text and return the corresponding `MD` object.
The optional argument `flavor` indicates the Markdown flavor that is used.
It can be `julia` (default), `common` or `github`.
See also [`Markdown.common`](@ref), [`Markdown.github`](@ref), [`Markdown.julia`](@ref).
"""
function parse(stream::IO; flavor = julia)
isa(flavor, Symbol) && (flavor = flavors[flavor])
Expand Down

0 comments on commit 57f4425

Please sign in to comment.