From bcc0c5ce3e653739813611de3c6c230697e79587 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Wed, 21 Feb 2024 13:33:16 -0500 Subject: [PATCH] Remove iframe non-empty hack (fixed in turndown) --- src/translator.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/translator.js b/src/translator.js index 85557d2..3166474 100644 --- a/src/translator.js +++ b/src/translator.js @@ -9,6 +9,7 @@ function initTurndownService() { }); turndownService.use(turndownPluginGfm.tables); + turndownService.keep(['iframe']); // preserve embedded tweets turndownService.addRule('tweet', { @@ -44,11 +45,13 @@ function initTurndownService() { } }); - // preserve iframes (common for embedded audio/video) + // iframe boolean attributes do not need to be set to empty string turndownService.addRule('iframe', { filter: 'iframe', replacement: (content, node) => { - const html = node.outerHTML.replace('allowfullscreen=""', 'allowfullscreen'); + const html = node.outerHTML + .replace('allowfullscreen=""', 'allowfullscreen') + .replace('allowpaymentrequest=""', 'allowpaymentrequest'); return '\n\n' + html + '\n\n'; } }); @@ -70,11 +73,6 @@ function getPostContent(post, turndownService, config) { content = content.replace(/(]*src=").*?([^/"]+\.(?:gif|jpe?g|png))("[^>]*>)/gi, '$1images/$2$3'); } - // this is a hack to make