Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/MarkdownLiteral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ Result:
![](https://user-images.githubusercontent.com/6933510/146623300-316e5a17-2daf-43ed-b70c-6c33278faf32.png)
"""
macro markdown(expr)
cm_parser = _make_cm_parser()
quote
result = $(esc(Expr(:macrocall, getfield(HypertextLiteral, Symbol("@htl")), __source__, expr)))
CMParsedRenderer(contents = result, parser = $cm_parser)
end
end

macro mdx_str(expr::String)
cm_parser = _make_cm_parser()
quote
result = $(esc(Expr(:macrocall, getfield(HypertextLiteral, Symbol("@htl_str")), __source__, expr)))
CMParsedRenderer(contents = result, parser = $cm_parser)
end
end

function _make_cm_parser()
cm_parser = CommonMark.Parser()
CommonMark.enable!(cm_parser, [
CommonMark.AdmonitionRule(),
Expand All @@ -111,10 +127,7 @@ macro markdown(expr)
CommonMark.TableRule(),
CommonMark.TypographyRule(),
])
quote
result = $(esc(Expr(:macrocall, getfield(HypertextLiteral, Symbol("@htl")), __source__, expr)))
CMParsedRenderer(contents = result, parser = $cm_parser)
end
return cm_parser
end

Base.@kwdef struct CMParsedRenderer
Expand Down