Stream: beginners

Topic: Markdown parser and transformer


view this post on Zulip Jonas Schell (Mar 12 2024 at 22:26):

I want to sneak Roc into the company I work for. Starting with some small scripts for non-critical tasks.
I want to start with a Markdown manipulation script that reads a Markdown file and replaces a section of it with some new content.
Naturally the question came up, what is the state of Markdown in Roc? Do we have any packages that I'm not aware of? I searched the Zulip history and found some attempts by @Luke Boswell , but nothing concrete. I would be grateful if someone could point out something that would be valuable for someone who is about to write a Markdown parser (to do something that is already being done by a regex). :D

view this post on Zulip Jonas Schell (Mar 12 2024 at 22:28):

I was thinking of parsing the markdown into an AST to manipulate it and then rendering it back to markdown.

view this post on Zulip Richard Feldman (Mar 12 2024 at 22:46):

that's awesome! :smiley:

view this post on Zulip Richard Feldman (Mar 12 2024 at 22:48):

I don't know if anyone's written a full markdown parser in pure Roc, but there are several in Elm - e.g. this, this, or the one I think is probably the most battle-tested - and the latter two are written using elm/parser, which someone has ported to Roc (although I'm not sure how battle-tested that port is!)

view this post on Zulip Jonas Schell (Mar 12 2024 at 23:02):

Thanks for sharing!

view this post on Zulip Jonas Schell (Mar 12 2024 at 23:04):

Would lukewilliamboswell/roc-parser be a good fit to use instead of ported elm/parser? :thinking:

view this post on Zulip Jonas Schell (Mar 12 2024 at 23:08):

I don't know much about parsers, so I'm wondering if there's something that disqualifies it from the start.

view this post on Zulip Richard Feldman (Mar 12 2024 at 23:46):

oh I just suggested that because it might make porting easier

view this post on Zulip Richard Feldman (Mar 12 2024 at 23:46):

I'd expect either one to work fine!

view this post on Zulip Luke Boswell (Mar 12 2024 at 23:56):

How much functionality do you need with markdown? Could you do without embedded html? If so I could probably put a Markdown module together pretty quickly, or help you with that using roc-parser.

view this post on Zulip Luke Boswell (Mar 12 2024 at 23:57):

There has been a start made on xml parsing, but it still needs more love before it could parse html.

view this post on Zulip Luke Boswell (Mar 12 2024 at 23:58):

Or at least just parse the html into a single HmtlNode or something and leave it untouched.

view this post on Zulip Jonas Schell (Mar 13 2024 at 19:45):

Thank you for your help. Using html would be cool, but I think your single HtmlNode approach would work for now. :thumbs_up:

view this post on Zulip Jonas Schell (Mar 13 2024 at 19:48):

I would probably start by looking at Dillon's markdown implementation in elm and try to go from there.

view this post on Zulip Jonas Schell (Mar 13 2024 at 19:50):

I'll then share my first steps with you, and if you have time to take a look, I'd love to hear your feedback :)


Last updated: Jul 06 2025 at 12:14 UTC