You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I have been trying for a while to do a conversion on a string that can contain some user text, which might well contain some html which I would like to convert to being markdown. This is the way I have setup to do this:
This is what I was expecting to be returned though:
* asdf
* asdf
* asdf
Apologies if I am missing something quite obvious here. It looks like the Parser is returning a Node that, on the surface, looks correct - I suspect I might be doing something wrong here or doing something that is not supported. I can get the example usage of MarkdownRenderer provided in the docs working as it should do but the way I am doing it above is slightly different from the example. I don't see an obvious reason why it shouldn't work though?
The reason for this is that commonmark-java's Parser is a Markdown parser, not an HTML parser. Markdown allows some HTML to be embedded, but when rendered back to HTML or Markdown, it's mostly just passed through. There is no actual semantic meaning to that HTML for the parser/renderer.
If your input is always HTML, you will want to use a HTML parser, and then convert from the HTML representation (ul, li etc) to the commonmark-java representation such as BulletList, ListItem, etc. Then rendering that using MarkdownRenderer will work as you expect.
Uh oh!
There was an error while loading. Please reload this page.
Hi!
I have been trying for a while to do a conversion on a string that can contain some user text, which might well contain some html which I would like to convert to being markdown. This is the way I have setup to do this:
A simple example of
stringToConvert
is:The returned string from the
renderer.render(document)
is:This is what I was expecting to be returned though:
Apologies if I am missing something quite obvious here. It looks like the Parser is returning a Node that, on the surface, looks correct - I suspect I might be doing something wrong here or doing something that is not supported. I can get the example usage of MarkdownRenderer provided in the docs working as it should do but the way I am doing it above is slightly different from the example. I don't see an obvious reason why it shouldn't work though?
(Also see what the reference implementation does: https://spec.commonmark.org/dingus/)
The text was updated successfully, but these errors were encountered: