cmark-gfm-hs
cmark-gfm-hs copied to clipboard
Any way to make library safer?
I was trying to write a test generator that generated some random markdown. I decided to start with the Node
type since it seemed easier than generating valid markdown text first and parsing it. I found that if you construct an apparently invalid markdown: Node Nothing PARAGRAPH [Node Nothing DOCUMENT mempty]
, running nodeToHtml
against it results in a SIGSEGV
and crashes the entire program.
- Is there any possible way this can be reified into the library so that any rendering function that could segfault could instead return an
Either
? - I don't know much about the markdown standard but is there a way to make invalid nodes inexpressable in the types?
If you want something safer and more Haskelly I'd recommend my pure Haskell commonmark library (commonmark on Hackage; commonmark-extensions will give you GitHub extensions).
jgm/commonmark-hs on GitHub
Since writing that I haven't had much use for the cmark wrapper, so I'm not personally inclined to put much time into it.
I would be inclined to follow @jgm's lead here! :)
That said, my guess is that there's probably a simple fix possible for the issue noted here. I just don't have time to look into it now.
I just threw together this library, which aims to have a more correct-by-construction AST that's easy to transform (which isn't very easy in commonmark
: https://github.com/jgm/commonmark-hs/pull/103). It'll still fail when rendering an ill-formatted AST, but it should be good enough for my use-case.
https://github.com/brandonchinn178/cmark-gfm-simple