A standalone version of the readability library used for Firefox Reader View.
npm install @mizchi/readabilityWIP
- [x] Main Content Extraction
- [x] Pure JS Impl (NO DOM API for Cloudflare)
- [ ] Pass original tests
- [ ] Custom Parser (now only supports htmlparser2)
- [x] Accessibility
- [x] Markdown Serializer
- [x] Navigation Detection
- [x] Document Structure Analysis
- [x] Test Coverage Support
``bash`
$ npm install -g @mizchi/readability
`bash`
$ readability https://example.com/articleOutputs extracted content as markdown
`bash
$ readability --help
Usage: @mizchi/readability [options]
Options:
-t, --threshold
-h, --help Show this help message
-f, --format
-o, --out
# Progressive Analysis Options
--analyze-structure Analyze page structure without extracting content
--extract-nav Extract navigation information only
--extract-content Extract main content only
--with-context Include context when extracting content
--full-analysis Perform complete page analysis
# Navigation Options
--nav-only Extract navigation information (legacy)
--nav-type
--nav-location
# Document Mode Options
--doc-mode Extract documentation structure
`
`bashExtract content as markdown
$ readability https://example.com/article
$3
-
md (default): Markdown format
- html: HTML format
- doc: Documentation structure with navigation
- ai-summary: AI-optimized summary with metadata
- ai-structured: Structured format for AI processingreadability-mcp
`json
{
"mcpServers": {
"readability": {
"command": "npx",
"args": ["-y", "@mizchi/readability", "--mcp"]
}
}
}
`Prompt
`
Given a URL, use read_url_content_as_markdown and summary contents
`Development
$3
`bash
Run tests with coverage
npm run test:coverageRun all tests with coverage (including excluded tests)
npm run test:coverage:allView coverage report in browser
open coverage/index.html
`Current coverage thresholds:
- Lines: 50%
- Functions: 60%
- Branches: 75%
- Statements: 50%
How to use
`bash
npm install --save @mizchi/readability
`$3
`ts
import { extract, toMarkdown } from "@mizchi/readability";const url = "https://zenn.dev/mizchi/articles/ts-using-sampling-logger";
const html = await fetch(url).then((res) => res.text());
const extracted = extract(html, {
charThreshold: 100,
});
const parsed = toMarkdown(extracted.root);
console.log(parsed);
`$3
`ts
import { extractAriaTree, ariaTreeToString } from "@mizchi/readability";
const html = await fetch("https://zenn.dev").then((res) => res.text());
const tree = extractAriaTree(html);
const str = ariaTreeToString(tree);
console.log(str);
`---
Readability.js
A standalone version of the readability library used for
Firefox Reader View.
Installation
Readability is available on npm:
`bash
npm install @mozilla/readability
`You can then
require() it, or for web-based projects, load the
Readability.js script from your webpage.Basic usage
To parse a document, you must create a new
Readability object from a DOM
document object, and then call the parse() method. Here's an
example:`javascript
var article = new Readability(document).parse();
`If you use Readability in a web browser, you will likely be able to use a
document reference from elsewhere (e.g. fetched via XMLHttpRequest, in a
same-origin