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

Clarify parser and render options in docs #88

Closed
gjtorikian opened this issue Oct 25, 2015 · 2 comments
Closed

Clarify parser and render options in docs #88

gjtorikian opened this issue Oct 25, 2015 · 2 comments

Comments

@gjtorikian
Copy link

An interesting issue came up on the Ruby wrapper for libcmark.

It looks like, in order to render a string into a document, and that document into HTML, you must pass the rendering options twice, like this:

doc = CommonMarker.render_doc(markdown, [:smart, :hardbreaks])
doc.to_html([:smart, :hardbreaks])

As far as I can see, there's no way for render_doc to store the render options on the cmark_node document itself. And there's no way for that same node to call to_html—it must be handled by a different cmark_render_html method.

Is that correct? And if so, is that design intentional? I could piece something together for the Ruby wrapper to work around this, but I thought it might make sense to apply the change at the C level.

@jgm
Copy link
Member

jgm commented Oct 25, 2015

Some of the options are render options, others are parsing
options. There are no options that are used in both phases.

Parsing: NORMALIZE, VALIDATE_UTF8, SMART

Rendering: SOURCEPOS, SAFE, HARDBREAKS

This could be clearer from the cmark.3 man page, because
currently the options are under a heading "Rendering."
Originally we only had writer options.

I don't want to store render options in the parse tree,
since the same parsed AST might be rendered in different
ways. But maybe it would make sense to more clearly
distinguish between reader and writer options, either in
cmark, or in the ruby wrapper, or both places.

+++ Garen Torikian [Oct 25 15 13:21 ]:

An interesting issue came up on the [1]Ruby wrapper for libcmark.

It looks like, in order to render a string into a document, and that
document into HTML, you must pass the rendering options twice, like
this:

doc = CommonMarker.render_doc(markdown, [:smart, :hardbreaks])
assert_equal result, doc.to_html([:smart, :hardbreaks])

As far as I can see, there's no way for render_doc to store the render
options on the cmark_node document itself. And there's no way for that
same node to call to_html—it must be handled by a different
cmark_render_html method.

Is that correct? And if so, is that design intentional? I could piece
something together for the Ruby wrapper to work around this, but I
thought it might make sense to apply the change at the C level.


Reply to this email directly or [2]view it on GitHub.

References

  1. Mix and match options gjtorikian/commonmarker#18
  2. Clarify parser and render options in docs #88

@gjtorikian
Copy link
Author

That makes sense. I'll change the title to reflect that this might be better fixed by a change in the docs.

@gjtorikian gjtorikian changed the title Duplicating options for parse *and* render? Clarify parser and render options in docs Oct 26, 2015
@jgm jgm closed this as completed in 56cd911 Dec 23, 2015
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

2 participants