ReadabilityLib 0.6.0-beta
See the version list below for details.
dotnet add package ReadabilityLib --version 0.6.0-beta
NuGet\Install-Package ReadabilityLib -Version 0.6.0-beta
<PackageReference Include="ReadabilityLib" Version="0.6.0-beta" />
paket add ReadabilityLib --version 0.6.0-beta
#r "nuget: ReadabilityLib, 0.6.0-beta"
// Install ReadabilityLib as a Cake Addin #addin nuget:?package=ReadabilityLib&version=0.6.0-beta&prerelease // Install ReadabilityLib as a Cake Tool #tool nuget:?package=ReadabilityLib&version=0.6.0-beta&prerelease
Readability
A C# port of standalone version of the readability library used for Firefox Reader View.
Installation
Readability is available on Nuget:
dotnet add package Readability
You can then using Readability;
it.
Basic usage
To parse a document, you must create a new DocumentReader
object from a Brackets document object, and then call the Parse()
method. Here's an example:
var article = new DocumentReader(document).Parse();
API Reference
new DocumentReader(document, options)
The options
object accepts a number of properties, all optional:
maxElemsToParse
(number, default0
i.e. no limit): the maximum number of elements to parse.nbTopCandidates
(number, default5
): the number of top candidates to consider when analysing how tight the competition is among candidates.charThreshold
(number, default500
): the number of characters an article must have in order to return a result.classesToPreserve
(array): a set of classes to preserve on HTML elements when thekeepClasses
options is set tofalse
.keepClasses
(boolean, defaultfalse
): whether to preserve all classes on HTML elements. When set tofalse
only classes specified in theclassesToPreserve
array are kept.disableJSONLD
(boolean, defaultfalse
): when extracting page metadata, Readability gives precedence to Schema.org fields specified in the JSON-LD format. Set this option totrue
to skip JSON-LD parsing.serializer
(function, defaultel => el.innerHTML
) controls how thecontent
property returned by theparse()
method is produced from the root DOM element. It may be useful to specify theserializer
as the identity function (el => el
) to obtain a DOM element instead of a string forcontent
if you plan to process it further.allowedVideoRegex
(RegExp, defaultundefined
): a regular expression that matches video URLs that should be allowed to be included in the article content. Ifundefined
, the default regex is applied.
Parse()
Returns an object containing the following properties:
title
: article title;content
: HTML string of processed article content;textContent
: text content of the article, with all the HTML tags removed;length
: length of an article, in characters;excerpt
: article description, or short excerpt from the content;byline
: author metadata;dir
: content direction;siteName
: name of the site;lang
: content language;publishedTime
: published time;
The parse()
method works by modifying the DOM. This removes some elements in the web page, which may be undesirable. You can avoid this by passing the clone of the document
object to the Readability
constructor:
var documentClone = document.Clone();
var article = new DocumentReader(documentClone).Parse();
IsProbablyReaderable(document, options)
A quick-and-dirty way of figuring out if it's plausible that the contents of a given document are suitable for processing with Readability. It is likely to produce both false positives and false negatives. The reason it exists is to avoid bogging down a time-sensitive process (like loading and showing the user a webpage) with the complex logic in the core of Readability. Improvements to its logic (while not deteriorating its performance) are very welcome.
The options
object accepts a number of properties, all optional:
minContentLength
(number, default140
): the minimum node content length used to decide if the document is readerable;minScore
(number, default20
): the minimum cumulated 'score' used to determine if the document is readerable;visibilityChecker
(function, defaultisNodeVisible
): the function used to determine if a node is visible;
The function returns a boolean corresponding to whether or not we suspect Readability.parse()
will succeed at returning an article object. Here's an example:
/*
Only instantiate Readability if we suspect
the `parse()` method will produce a meaningful result.
*/
if (isProbablyReaderable(document)) {
let article = new Readability(document).parse();
}
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.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Brackets (>= 0.6.2)
- FuzzyCompare (>= 0.2.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.6.1-beta | 59 | 10/10/2024 |
0.6.0-beta | 50 | 10/7/2024 |
0.5.0-beta | 70 | 4/3/2024 |