fb55 / fb55/readabilitySAX

Take into account text in divs

Open
#47 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
249
Forks
35
Avg merge
1d 7h
Merged PRs (30d)
1

Description

It's very useful for some sites to handle this case:

<div class="content">
  Some long text...
  <a href="...">Link</a>
  ...
</div>

Competitors do:
https://github.com/mozilla/readability/blob/master/Readability.js#L677-L688
https://github.com/luin/readability/blob/master/src/helpers.js#L108-L119

I think it must be optional. Something like

    if(tagName === "p" || tagName === "pre" || tagName === "td");
    else if(tagName === "div"){
        var done = false;
        //check if div should be converted to a p
        for(i = 0, j = divToPElements.length; i < j; i++){
            if(divToPElements[i] in elem.info.tagCount){
                done = true;
                break;
            }
        }

        if(done && this._settings.strayText){
            for(i = 0, j = elem.children.length; i < j; i++) {
                var child = elem.children[i];
                if(typeof child !== 'string')
                    continue;
                var textLength = child.trim().length;
                if(textLength > 24 && elem.parent){
                    elem.isCandidate = elem.parent.isCandidate = true;
                    if(re_commas.test(child)) var commas = child.split(re_commas).length - 1;
                    var addScore = 1 + commas + Math.min( Math.floor( textLength / 100 ), 3);
                    elem.tagScore += addScore;
                    elem.parent.tagScore += addScore / 2;
                }
            }
        }

        if(done)
            return;

        elem.name = "p";
    }
    else return;

What do you think about it?

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Compare the proposed behavior with the referenced Readability.js and helpers.js sections, then locate readabilitySAX’s current div and tag-processing entry points and its settings handling. Done means stray text in eligible divs can be considered as content behind an optional setting, while the existing behavior remains unchanged when that setting is disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
content
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.