-
Notifications
You must be signed in to change notification settings - Fork 26
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
Convert tables to markdown #9
Conversation
Hi, BTW, already published your previous PR with version 1.1, it's already accessible in maven central |
Take your time. If you have any questions or comments please let me know. I have added most of the test cases from https://github.com/mixmark-io/turndown-plugin-gfm/blob/master/test/index.html. So you can see what the result of the html to markdown is. |
@furstenheim can you please look into this PR? |
addRule("br", new Rule("br", (content, element) -> {return options.br + "\n";})); | ||
addRule("br", new Rule("br", (content, element) -> { | ||
// If the br tag is in a table keep the br tag. Otherwise, the table will not work in markdown. | ||
if (element.parentNode() != null && Arrays.asList("td", "th").contains(element.parentNode().nodeName().toLowerCase())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a bit sketchy. It works at only one level, right? Both up and down
var alignMap = Map.of("left", ":--", "right", "--:", "center", ":-:"); | ||
|
||
if (isHeadingRow(element)) { | ||
for (var i = 0; i < element.childNodes().size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this brittle? Can't you have an html comment as a child, for example?
@@ -761,5 +761,65 @@ | |||
}, | |||
"input": "\n<pre><code>\nCode\n\n</code></pre>\n ", | |||
"output": "```\n\nCode\n\n```" | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some tests here where the content inside the table has other htmls, also comments, and things like that?
I understand that the code is just from the other library, but it looks slightly brittle as it is right now |
Sorry, I close this pull request for now. Maybe when I have time I will look in to it again. |
With this merge request it possible to convert tables to markdown. As inspiration I used https://github.com/mixmark-io/turndown-plugin-gfm/blob/master/src/tables.js.
This pull request will fix #5
So this html:
will be converted to:
And in github this will showed as:
A nice thing of the java
org.jsoup:jsoup
library is that tables without a tbody or thead can also be converted, because jsoup add tbody if none is present. This isn't working/supported by the turndown-plugin-gfm library.