Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@diamondyuan/readability

mozilla8Apache-2.00.1.0

A standalone version of the readability library used for Firefox Reader View.

readme

Readability.js

Build Status

A standalone version of the readability library used for Firefox Reader View. Any changes to Readability.js itself should be reviewed by an appropriate Firefox/toolkit peer, such as @gijsk, since these changes will be automatically merged to mozilla-central.

Contributing

For outstanding issues, see the issue list in this repo, as well as this bug list.

To test local changes to Readability.js, you can use the automated tests. There's a node script to help you create new ones.

Please make sure to run eslint against any proposed changes when creating a pull request.

Usage

To parse a document, you must create a new Readability object from a document object, and then call parse(). Here's an example:

var article = new Readability(document).parse();

This article object will contain the following properties:

  • title: article title
  • content: HTML string of processed article content
  • length: length of an article, in characters
  • excerpt: article description, or short excerpt from the content
  • byline: author metadata
  • dir: content direction

If you're using Readability on the web, you will likely be able to use a document reference from elsewhere (e.g. fetched via XMLHttpRequest, in a same-origin <iframe> you have access to, etc.).

Otherwise, you would need to construct such an object using a DOM parser such as jsdom. While this repository contains a parser of its own (JSDOMParser), that is restricted to reading XML-compatible markup and therefore we do not recommend it for general use.

If you're using jsdom to create a DOM object, you should ensure that the page doesn't run (page) scripts (avoid fetching remote resources etc.) as well as passing it the page's URI as the url property of the options object you pass the JSDOM constructor.

Optional

Readability's parse() works by modifying the DOM. This removes some elements in the web page. You could avoid this by passing the clone of the document object while creating a Readability object.

var documentClone = document.cloneNode(true); 
var article = new Readability(documentClone).parse();

Tests

Please run eslint as a first check that your changes adhere to our style guidelines.

To run the test suite:

$ mocha test/test-*.js

To run a specific test page by its name:

$ mocha test/test-*.js -g 001

To run the test suite in TDD mode:

$ mocha test/test-*.js -w

Combo time:

$ mocha test/test-*.js -w -g 001

Benchmarks

Benchmarks for all test pages:

$ npm run perf

Reference benchmark:

$ npm run perf-reference

License

Copyright (c) 2010 Arc90 Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

changelog

Changelog

Notable changes to readability will be documented in this file.

The format is based on Keep a Changelog, and this project attempts to adhere to Semantic Versioning.

For the purposes of Semantic Versioning, the readability output object for a given input document is not considered a stable API. That is, minor version increments may change this output. Patch version increments will only do so in ways that are strict improvements (e.g. from empty strings or exceptions to something more reasonable).

[Unreleased]

[0.6.0] - 2025-03-03

[0.5.0] - 2023-12-15

[0.4.4] - 2023-03-31

[0.4.3] - 2023-03-22

[0.4.2] - 2022-02-09

[0.4.1] - 2021-01-13

Added

  • Typescript type definition file (.d.ts).

[0.4.0] - 2020-12-23

Added

Changed

[0.3.0] - 2020-08-05

The first version that was published on NPM.

Previously, we did not consistently version anything, nor did we publish to NPM.

At some point, we may wish to expand this changelog into the past.