npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

scholarly-parse

v0.2.1

Published

Parse scholarly papers (JATS, Grobid TEI, arXiv HTML, publisher HTML, PDF) into one document model and Markdown.

Downloads

705

Readme

Version License npm TypeScript Node


What it does

scholarly-parse reads a paper in any of five formats — JATS XML from PubMed Central, Europe PMC, and publisher feeds; TEI from Grobid; LaTeXML HTML from arXiv; publisher article pages; and PDF — into one ScholarlyDocument, and renders it as Markdown.

Install

bun add scholarly-parse
# or
npm install scholarly-parse

The JATS and TEI parsers need nothing more. The others load an optional peer on first use, and throw with the install command when it is missing:

| Format | Also install | |:---|:---| | scholarly-parse/latexml, scholarly-parse/html | linkedom | | scholarly-parse/pdf | unpdf |

Runs on Bun, Node ≥22, and Cloudflare Workers. ESM only.

Usage

import { toMarkdown } from 'scholarly-parse';
import { parseJats } from 'scholarly-parse/jats';

const result = parseJats(xml);
if (result.ok) console.log(toMarkdown(result.document));
else console.error(result.error.reason, result.error.message);

When the format isn't known, parse detects it from the payload and loads that parser. It is async, since the HTML and PDF parsers are:

import { parse } from 'scholarly-parse';

const result = await parse(bytes, { baseUrl: url });
if (!result.ok && result.error.reason === 'blocked') {
  // a captcha or access-denied page arrived instead of the paper
}

toSections flattens the document into sections with their heading paths and sizes, for serving a long paper a piece at a time. Figures and tables outside any section, the footnotes, and the references come last, one entry each, and each entry's id renders it alone through toMarkdown(document, { sections: [id] }):

import { toSections } from 'scholarly-parse';

for (const { path, chars, markdown } of toSections(document)) {
  console.log(path.join(' › '), chars);
}

API

| Import | Exports | |:---|:---| | scholarly-parse | detect, parse, toMarkdown, toText, toSections, and the model types | | scholarly-parse/jats | parseJats, jatsInlineToMarkdown | | scholarly-parse/tei | parseTei | | scholarly-parse/latexml | parseLatexml | | scholarly-parse/html | parseHtml | | scholarly-parse/pdf | parsePdf |

Every parser returns { ok: true, document } or { ok: false, error: { reason, message } }, where reason is malformed, wrong-format, empty, blocked, or too-large. Each takes a maxInputBytes budget; parseLatexml and parseHtml take the page's baseUrl to resolve links (for arXiv, https://arxiv.org/html/<id> without a trailing slash, the only form its image paths resolve against), and parsePdf reading budgets counted across the document: maxPages (default 300), maxTextItems (500,000), maxTextChars (4,000,000), and maxOperators (10,000,000). A PDF that reaches one parses as far as it was read, with a truncated-input warning. parseJats and parseTei are synchronous; the rest are async.

parsePdf and parse also take a signal: once it is aborted (AbortSignal.timeout(ms), a request's cancellation), reading stops at the next page boundary and keeps what was read, warned truncated-input. pdf.js reads a page without yielding, so for a hard time or memory bound on untrusted PDFs, run parsePdf in a worker or process you can terminate.

Formats

| Subpath | Reads | Quality | |:---|:---|:---| | /jats | JATS 1.x as PubMed Central, Europe PMC, bioRxiv, and publisher feeds serve it | structured | | /tei | Grobid TEI, including the HTML-wrapped form OpenAlex serves | structured | | /latexml | arXiv HTML and ar5iv renders | structured | | /html | Publisher and preprint-server article pages | partial | | /pdf | PDFs with a text layer, structure read from typography | partial, or flat when no headings are found |

Document model

A ScholarlyDocument holds metadata (title, authors, venue, identifiers, license, and related works such as the article a correction corrects or the notice retracting it), abstracts by kind, body and back section trees of typed blocks (paragraph, list, table, figure, formula, code, quote, box, supplement), floats, references, footnotes, and diagnostics: the quality level, coded warnings, and source elements no handler covered. docs/design.md outlines it and records the decisions behind it; src/model/document.ts is the source of truth.

Project structure

| Path | Purpose | |:---|:---| | src/model/ | The document model and the ParseResult type | | src/formats/ | One parser per format | | src/detect.ts, src/parse.ts | Format detection, and parse for any format | | src/render/ | Markdown, plain text, section list | | src/html/, src/xml/ | The shared DOM and XML readers, HTML tables, MathML to TeX | | corpus/ | Openly licensed real documents the parsers are tested against | | tests/ | Unit tests and the corpus suite | | docs/design.md | Scope, API, model, and decisions |

Development

bun install
bun run devcheck

Rules for working in the repo are in CLAUDE.md. Bugs and requests go through issues — see CONTRIBUTING.

License

Apache-2.0. Corpus documents keep their own licenses — see corpus/ATTRIBUTION.md.