Skip to content

Commit

Permalink
Added @mdx_str version to address issue JuliaPluto#5.
Browse files Browse the repository at this point in the history
  • Loading branch information
snoeyink committed Jun 23, 2022
1 parent f5707f5 commit 06c372c
Showing 1 changed file with 17 additions and 4 deletions.
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

0 comments on commit 06c372c

Please sign in to comment.