-
Notifications
You must be signed in to change notification settings - Fork 873
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
Issues with keeping some HTML tags in Turndown's markdown output. #241
Comments
Hi @drBunsen To keep elements that already have markdown/commonmark equivalents, you will need to use var turndownService = new TurndownService()
turndownService.addRule('keep', {
filter: ['h1', 'img'],
replacement: function (content, node) {
return node.outerHTML
}
)
md = turndownService.turndown(html) or to have the the turndownService.addRule('keep', {
filter: ['h1', 'img'],
replacement: function (content, node) {
return node.isBlock ? '\n\n' + node.outerHTML + '\n\n' : node.outerHTML
}
) The To go into some more detail as to why this is the case: there are essentially three arrays of rules:
Given that there might be conflicts between these rules, there had to be a defined precedence, so it was decided that the above would be the order. This order was also influenced by how the code architecture developed over time. I think it might be possible now to change this order to something like:
But I might wait for some more feedback before doing so P.S. Glad to hear you like the name! Funnily enough I have another project called bunsn! |
Thank you. I appreciate the helpful example and also the explanation. Keep up the good work! |
Hello,
Thanks for this great project. I am interested in converting some HTML to Markdown where I wish to preserve img and h1 tags as HTML in the resulting Markdown. Here's a minimal working example of what I'm trying to do:
The above example outputs:
From reading the docs, my understanding is that keep will ignore specified tags and NOT convert them to markdown. How can I get Turndown to output the following..
p.s. Turndown is a GREAT name for the project!
The text was updated successfully, but these errors were encountered: