From d427f081c0a79870a0f5103bc67f7781964abf39 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Mon, 12 Nov 2018 17:10:05 -0500 Subject: [PATCH] Preserve iframes, tweak regex to preserve case --- index.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 34eebb9..88e247b 100644 --- a/index.js +++ b/index.js @@ -157,6 +157,21 @@ function initTurndownService() { replacement: (content, node) => '\n\n' + node.outerHTML + '\n\n' }); + // preserve iframes (common for embedded audio/video) + // other solutions via blankRule() and keep() did not work for me + // that's why getPostContent() adds a "." to make ', ''); + return '\n\n' + html + '\n\n'; + } + }); + + return turndownService; } @@ -189,10 +204,13 @@ function getPostDate(post) { function getPostContent(post, turndownService) { let content = post.encoded[0].trim(); + // this is for a workaround/hack in initTurndownService() + content = content.replace(/<\/iframe>/gi, '.$&'); + if (argv.addcontentimages) { // writeImageFile() will save all content images to a relative /images folder // so update references in post content to match - content = content.replace(/]*)src=".*?([^\/"]+\.(?:gif|jpg|png))"([^>]*)>/gi, ''); + content = content.replace(/(]*src=").*?([^\/"]+\.(?:gif|jpg|png))("[^>]*>)/gi, '$1images/$2$3'); } content = turndownService.turndown(content)