MichaelHatherly / CommonMark.jl

A CommonMark-compliant Markdown parser for Julia.
Other
87 stars 11 forks source link

HypertextLiteral.jl + CommonMark.jl = 🤯 #31

Closed fonsp closed 1 month ago

fonsp commented 2 years ago

I made a combination of HypertextLiteral.jl by @clarkevans and CommonMark.jl, and I think it is really cool!!

DEMO NOTEBOOK

Screenshots ![Schermafbeelding 2021-12-16 om 13 17 09](https://user-images.githubusercontent.com/6933510/146370539-3c6245f7-c171-45d7-928d-083212569de8.png) ![Schermafbeelding 2021-12-16 om 13 15 48](https://user-images.githubusercontent.com/6933510/146370562-6636c73b-61a1-40d8-93c2-b631ba95af98.png)

Features

The list of features is really simple to explain: it is everything that CommonMark gives, plus everything that HypertextLiteral gives! This includes:

Implementation

Also cool: the code is extremely short!

macro md(expr)
    cm_parser = CommonMark.Parser()
    quote
        result = @htl($expr)
        htl_output = repr(MIME"text/html"(), result)

        $(cm_parser)(htl_output)
    end
end

It is essentially the @htl macro for HypertextLiteral.jl, but the result is passed through a CommonMark parser. This works, because:


Let me know what you think! Perhaps it can be added to this package as a new macro, or we can make a new package.

MichaelHatherly commented 2 years ago

That's awesome. I'm quite surprised that commonmark's HTML handling is actually sufficient to parse htl_output correctly.

MichaelHatherly commented 2 years ago

Regarding including it here, I'd like to remove deps where possible since the eventual end goal is a standard lib. Might be a PlutoUI macro, though whether @md is actually "UI" is debatable I guess...

fonsp commented 2 years ago

That makes sense! I really hope it becomes a stdlib!

I like the idea of including it in PlutoUI. Let's continue testing it to see if there are any unforseen problems, and then release it!

fonsp commented 2 years ago

We will discuss this at the weekly pluto developers call in 1 hour: https://julialang.org/community/#events @MichaelHatherly @jeremiahpslewis feel free to join if you have time!

MichaelHatherly commented 2 years ago

https://github.com/MichaelHatherly/CommonMark.jl/blob/master/src/extensions/interpolation.jl#L121-L152 is the set of extensions that get used in cm"" which is probably what you'd actually want to use in the "real" @mdl macro. It's an internal method so probably don't use it directly, we could export a better named version of that one perhaps.

fonsp commented 2 years ago

Thanks for the pointers! I will add those

fonsp commented 2 years ago

FYI I made https://github.com/JuliaPluto/MarkdownLiteral.jl ! I am still wondering what the best name would be, my favourites are:

MichaelHatherly commented 2 years ago

Could go with @mdx since the syntax supported is kind of like https://mdxjs.com/ though not quite.

lukeburns commented 2 years ago

This is great, so much easier to interpolate in latex expressions!

MichaelHatherly commented 1 month ago

I'll close this issue now since there isn't much more needed here.