Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to make library safer? #19

Open
MichaelXavier opened this issue Sep 1, 2021 · 4 comments
Open

Any way to make library safer? #19

MichaelXavier opened this issue Sep 1, 2021 · 4 comments

Comments

@MichaelXavier
Copy link

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.

  1. 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?
  2. I don't know much about the markdown standard but is there a way to make invalid nodes inexpressable in the types?
@jgm
Copy link

jgm commented Sep 1, 2021

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.

@kivikakk
Copy link
Owner

kivikakk commented Sep 1, 2021

I would be inclined to follow @jgm's lead here! :)

@jgm
Copy link

jgm commented Sep 2, 2021

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.

@brandonchinn178
Copy link

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: jgm/commonmark-hs#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants