Skip to content
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

Pass the url option to the JSDOM constructor to get images and relative links fixed #106

Open
facundoolano opened this issue Aug 17, 2023 · 1 comment

Comments

@facundoolano
Copy link

I've noticed that the content parsed by this library keeps relative urls for images, which prevents them to be rendered independently. (See for example the images in this url).

As per the mozilla/readability repo:

Remember to pass the page's URI as the url option in the JSDOM constructor (as shown in the example above), so that Readability can convert relative URLs for images, hyperlinks etc. to their absolute counterparts.

Alternatively, the JSDOM.fromURL function can be used, which already does that job. I confirmed with this basic script that the content comes with fixed images in that case:

#!/usr/bin/env node

const { JSDOM } = require("jsdom");
const { Readability } = require('@mozilla/readability');

const url = process.argv[2];

JSDOM.fromURL(url).then(function (dom) {
  let reader = new Readability(dom.window.document);
  let article = reader.parse();
  console.log(article.content);
});
@jemrobinson
Copy link
Member

jemrobinson commented Aug 18, 2023

Hi @facundoolano. No-one is currently actively working on this project, but if you're interested in making a PR that would close this issue I'm happy to review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants