-
Notifications
You must be signed in to change notification settings - Fork 888
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
Broken Image conversion on compressed <figure> tag #466
Comments
Quick workaround for now: let markdown = turndownService.turndown(html)
if (html.match(/<figure.*?<\/figure>/gs)) {
markdown = markdown
.replace(/\[\s*\n*\s*!/gs, '[!')
.replace(/\)\s*\n*\s*]/gs, ')]')
} |
Another edge case is
Updated the workaround to support blockquote and tooltips (title property) let markdown = turndownService.turndown(html)
// fix for: https://github.com/mixmark-io/turndown/issues/466
if (html.match(/<figure.*?<\/figure>/gs)) {
markdown = markdown
// revmoe newlines and whitespaces from images
.replace(/\[\s*\n*\s*!/gs, '[!')
.replace(/\)\s*\n*\s*]/gs, ')]')
// remove tooltip from images
.replace(/(!\[.*?\]\(.*?)( ".*?")(\))/gs, '$1$3')
}
// if figure is inside a blockquote do a similar fix to the above
if (html.match(/<blockquote.*?<figure.*?<\/figure>.*?<\/blockquote>/gs)) {
markdown = markdown.replace(
/>\s*\[\s*\n*\s*>\s*\n*>\s*!\[(.*?\))\s*\n*>\s*\n*>\s*]/gs,
'> [![$1]',
)
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First off, thank you so much for making this excellent library. It has been pretty much flawless 💜.
Found a bug when dealing with images from from Substack specifically.
The HTML is compressed and uses the
<figure>
tag.It works fine if the HTML has white spacing, but as soon as that whitespace is removed it fails.
Codesandbox Example
It adds new lines, breaking the image markdown formatting.
The text was updated successfully, but these errors were encountered: