Text content depends on whitespace in source HTML

Open
#779 3 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
web-dev

Research direction

Start by reproducing the issue with the JavaScript example in the linked CodeSandbox test.js and inspect the Readability parse path that produces article.textContent. Done means adjacent list-item text from minified HTML retains spacing, while the existing example continues to work.

Written by the indexing model from the issue text.

Description

has-website-testcase

When using Readability with minified HTML, without whitespace (or newlines) between tags,
generated text content are merged into single line, without any spacing between:

For example:

const { JSDOM } = require("jsdom");
const { Readability } = require("@mozilla/readability");
const DEFAULT_HTML =
  "<ol><li><span>Getting started: make sure you have your PR assets ready</span></li><li><span>Create your pitch email and press release</span></li><li><span>Pitch your story to journalists</span></li><li><span>Post campaign activities</span></li></ol>";
const jsdom = new JSDOM(DEFAULT_HTML, { url: "https://google.com" });
const article = new Readability(jsdom.window.document).parse();
console.info(article.textContent);

Will generate single line of text Getting started: make sure you have your PR assets readyCreate your pitch email and press releasePitch your story to journalistsPost campaign activities

which is wrong - words are glued together, generating things like readyCreate

Here is the test environment for this: https://codesandbox.io/p/sandbox/readability-test-3tu4im?file=%2Ftest.js

Dominant language
JavaScript
Stars
11.5k
Forks
732
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mozilla/readability

All issues in mozilla/readability

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.