From eaad96acddb903cebc6b09b24368dfeb3b01d6a8 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 6 May 2022 12:29:08 +0800 Subject: [PATCH] Return parsed dom back to backend --- packages/api/src/readability.d.ts | 4 +--- packages/api/src/utils/parser.ts | 7 +++---- packages/readabilityjs/Readability.js | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/api/src/readability.d.ts b/packages/api/src/readability.d.ts index d6a0128ee..54f8846ec 100644 --- a/packages/api/src/readability.d.ts +++ b/packages/api/src/readability.d.ts @@ -5,8 +5,6 @@ // TypeScript Version: 2.2 declare module '@omnivore/readability' { - import { DOMWindow } from 'jsdom' - /** * A standalone version of the readability library used for Firefox Reader View. * @@ -165,7 +163,7 @@ declare module '@omnivore/readability' { previewImage?: string /** Article published date */ publishedDate?: Date - window?: DOMWindow + dom?: Element } } diff --git a/packages/api/src/utils/parser.ts b/packages/api/src/utils/parser.ts index 6680e2dd8..2472988b2 100644 --- a/packages/api/src/utils/parser.ts +++ b/packages/api/src/utils/parser.ts @@ -254,9 +254,8 @@ export const parsePreparedContent = async ( // Format code blocks // TODO: we probably want to move this type of thing // to the handlers, and have some concept of postHandle - if (article?.window) { - // const cWindow = new JSDOM(article?.content).window - article.window.document.querySelectorAll('code').forEach((e) => { + if (article?.dom) { + article.dom.querySelectorAll('code').forEach((e) => { console.log(e.textContent) if (e.textContent) { const att = hljs.highlightAuto(e.textContent) @@ -271,7 +270,7 @@ export const parsePreparedContent = async ( e.replaceWith(code) } }) - article.content = article.window.document.body.outerHTML + article.content = article.dom.outerHTML } const newWindow = new JSDOM('').window diff --git a/packages/readabilityjs/Readability.js b/packages/readabilityjs/Readability.js index 999f85cec..d1bce8bdb 100644 --- a/packages/readabilityjs/Readability.js +++ b/packages/readabilityjs/Readability.js @@ -2899,7 +2899,7 @@ Readability.prototype = { siteIcon: metadata.siteIcon, previewImage: metadata.previewImage, publishedDate: metadata.publishedDate || publishedAt || this._articlePublishedDate, - window: articleContent, + dom: articleContent, }; } };