This package finds the article in a web page and converts it to Markdown. It
is used by the Readstack parser service. This file is for coding agents. CLAUDE.md is a
symlink to it. For the public API, see README.md.
- Keep changes tightly scoped. Do not add unrelated refactors, abstractions, optimizations, or features.
- Read the nearest test before changing behavior. Update existing tests that the change breaks or makes wrong.
- The public API is the exports of
src/index.ts. Everything else is internal. Changing an export is a breaking change for the parser service. - Use the terms in Parser detection terms in code and comments.
- Write commit messages as Conventional Commits with the types
feat,fix,perf,docs,style,refactor,test,build,ci,choreorrevert. The type decides the release: a breaking change publishes a major version,feata minor,fixandperfa patch, and other types nothing.
Before committing, format, lint and typecheck the changed files and run the
tests. The scripts are in package.json (test, typecheck, lint, chk,
fmt, build). For a targeted check, run the tool on the file:
pnpm exec prettier --check path/to/file
pnpm exec oxlint path/to/file
pnpm exec vitest run path/to/testTests are *.test.ts files beside the code, with Vitest globals. Snapshots
live in __snapshots__/ beside each test.
Add new tests only when they protect behavior that matters and that existing tests do not already cover. Ask before adding one, except for detection fixtures (see Default article detection).
Fixture pages in src/parsers/fixtures/ are real third-party pages. Keep them
as they are and covered by src/parsers/fixtures/NOTICE.md.
src/parsers/registry.ts tries parsers in order and returns the first
success:
- site-specific parsers whose
canParse(url)matches (currentlyBbcUkParser, which removes bbc.co.uk byline, metadata, and link blocks before default detection); DefaultParser;ReadabilityParser(Mozilla Readability), the last resort.
Every parser extends BaseParser, which purifies the HTML, extracts Open Graph
metadata, runs PreProcessHtml, calls the parser's extract(), calculates
reading time (src/util/readingTime.ts), and converts the result to Markdown.
DefaultParser measures content patterns instead of trusting a site's
semantic HTML. Candidate acceptance rules are the options object in
DefaultParser.ts.
- Find article elements (paragraphs, headings, lists, images, tables, code blocks).
- Walk past single-child wrappers to find possible containers.
- Keep candidates that pass the acceptance rules (
DefaultParser.ts, with helpers insrc/findArticle/candidates.ts). - Choose or build the article container with
findArticleContentContainer(src/findArticle/resolve.ts). Its comments document each check in order. - Remove a repeated leading heading and navigation-heavy lists
(
src/findArticle/filter.ts). - Convert to Markdown.
When changing detection, add a fixture under src/parsers/fixtures/ and a
test, and check snapshot changes in __snapshots__/.
Candidate: A possible article content Container. Avoid: contender
Container: The DOM element returned for filtering.
Parent, child, sibling: DOM relationships.
Paragraph text, article text: Text that belongs to the article. Avoid: prose
Article elements: The elements counted by candidate checks: paragraphs, headings, lists, images, tables, and code blocks. Avoid: anchor
- Use short, plain-language comments, lowercase unless grammar or a proper noun requires otherwise.
- Explain surprising intent or constraints, not the next line of code.
- Update comments when the related control flow changes.