Blog

The Quote Counter Counts Punctuation, Not People

· NanoParse team

quote_density arrives with every parse, inside the litmus object, as three integers: attributed_quotes, attribution_verbs, per_1k_words. The name suggests a reading of who was quoted. The function reads quotation marks, and it reads them from the markdown that came back — not from the page that was fetched.

That distinction decides how the field can be used, so this post takes it apart: the function printed from the deployed source, 41 fixtures that isolate one rule each, 18 real pages measured through POST /admin/parse, and one place where the delivered text and the denominator the field divides by are not the same string. Price is unchanged and lives in one file: $0.002 per successful parse, refused reads settle nothing.

The field as served

Two payloads from the 2026-11-19 run, copied out of the responses:

en.wikipedia.org/wiki/Quotation   (5,197 words)
{"attributed_quotes": 96, "attribution_verbs": 54, "per_1k_words": 18.5}

www.rfc-editor.org/rfc/rfc9110.html   (66,479 words)
{"attributed_quotes": 333, "attribution_verbs": 24, "per_1k_words": 5}

A page about quotation marks, written in prose that quotes people, scores 18.5 pairs per thousand words with 54 attribution verbs. An HTTP specification scores 5.0 with 333 pairs — three and a half times the count at a quarter of the density, because the pairs are quoted grammar, not quoted people. Both numbers are correct. Neither is a verdict on sourcing, and the field does not claim to be one.

The function, printed from the deployed source

Twenty-two lines, sliced out of worker/worker/src/intel.ts by declaration and run under node --experimental-strip-types for every fixture and recomputation below. The slice is blob 7b3eca00, source sha256 d773ba97…, unchanged since the live deploy.

const md = String(markdown || "");
const clean = md
  .replace(/```[\s\S]*?```/g, "")
  .replace(/^\s{4,}.*$/gm, "");

const straight = (clean.match(/"[^"\n]{3,}"/g) || []).length;
const curly = (clean.match(/“[^”\n]{3,}”/g) || []).length;
const attributedQuotes = straight + curly;

const verbs = (clean.match(/\b(?:said|says|according to|told|stated|reported|claimed|noted|added|wrote|explained|argued)\b/gi) || []).length;

const wordCount = md.split(/\s+/).filter(w => w.length > 0).length;

The ratio is the quote count multiplied by ten thousand, divided by the word count and rounded to one decimal place: one pair on a 100-word page prints as 100, and two on a 3,000-word page prints as 6.7. That line is the only part of the function that uses the word count, and the word count is the only part computed from md before the two replace calls — a detail that matters in the fifth section.

Six properties are visible before any test runs.

The quote counter looks for pairs of characters with at least three characters between them and no newline inside. Both straight and curly double-quote families are matched, in separate passes, so a pair that opens curly and closes straight matches neither.

Single quotation marks are not in either pattern. Text inside them is invisible to the counter.

Fenced code is removed before the count, and so is any line indented four spaces or more. Nothing else is stripped: inline code, tables, headings and link syntax all stay in the string the patterns read.

The verb list is eleven phrases matched case-insensitively at word boundaries. There is no check that the verb is near a quotation, or that a quotation is near a verb.

Attribution is never verified. A quoted sentence with no verb counts; a verb with no quotation counts; an attribution verb inside a URL counts.

The denominator is the raw markdown word count, including the code blocks and indented lines that the numerator just removed.

Forty-one fixtures, one rule each

Each fixture is a minimal markdown string built to exercise exactly one branch. The columns are the deployed function's output: pairs, verbs, pairs per thousand words, and the word count the ratio divides by.

fixture                                q   v     /1k words
none                                   0   0       0     8
one_straight_quote                     1   1     200     5
two_chars_between                      0   0       0     3
three_chars_between                    1   0   333.3     3
empty_quotes                           0   0       0     4
newline_inside_quotes                  0   0       0     6
curly_double                           1   0     250     4
curly_three_chars                      1   0   333.3     3
mixed_open_curly_close_straight        0   0       0     4
single_straight_not_counted            0   0       0     4
single_curly_not_counted               0   0       0     4
straight_inside_curly                  1   1   166.7     6
fenced_code_excluded                   0   0       0     9
fenced_code_any_language               0   0       0    10
indented_four_spaces_excluded          0   0       0     7
indent_three_at_document_start         1   1     200     5
indent_three_after_blank_line          0   0       0     6
indent_one_after_blank_line            1   1   166.7     6
indent_three_after_single_newline      1   1   166.7     6
indent_three_after_two_blank_lines     0   0       0     6
indent_two_after_two_blank_lines       0   0       0     6
indent_four_mid_document               0   0       0     8
indent_three_after_two_words           1   1     125     8
inline_code_counts                     1   0   166.7     6
verb_case_insensitive                  0   1       0     5
verb_according_to                      0   1       0     6
verb_according_split                   0   0       0     6
verb_noted_as_adjective                0   2       0     6
verb_added_as_adjective                0   1       0     5
verb_inside_word_ignored               0   0       0     4
verb_suffix_ignored                    0   0       0     4
verb_in_url                            0   1       0     4
verb_in_slug                           0   1       0     3
verb_told_inside_quote                 1   2   142.9     7
nested_straight_quotes                 2   1     400     5
three_marks_one_pair                   1   0   142.9     7
adjacent_pairs                         2   0    2000     1
quote_spanning_sentence                1   0     125     8
words_include_code_block               1   0    18.2    55
empty_markdown                         0   0       0     0
whitespace_only                        0   0       0     0
41/41 matched

Eight rows are worth reading twice, because each contradicts a guess a reader would make from the field's name.

Six of them are about what the counter cannot see. A pair of single quotation marks returns zero, straight or curly. A pair that opens with a curly mark and closes with a straight one returns zero, because the two families are matched by two separate patterns and neither pattern allows the other family's character. A pair split across a newline returns zero. And a page whose text is mostly quotation marks still returns zero from the verb side, since the verb list is a fixed eleven phrases.

nested_straight_quotes is the pairing rule made visible. The input is a quoted sentence containing a quoted word; the output is two pairs, because the pattern consumes the shortest span it can and then looks for the next opening mark. Five quotation marks produce two pairs and one leftover.

adjacent_pairs shows the ratio's ceiling behaviour: two pairs in a one-word document print 2,000 per thousand words. The per-1,000 form is a density, and density on a short document is arithmetic, not evidence.

words_include_code_block is the asymmetry that affects real pages. One pair sits in prose and 49 words sit inside a fenced block, which the numerator removes and the denominator keeps. The pair is real; the ratio is diluted by text the counter declined to read.

inline_code_counts is the mirror image: a quotation inside inline code is counted, because only fenced blocks and four-space indents are stripped.

The indent rule is one greedy pattern across line boundaries

Two rows in the table look contradictory and are not. A line indented three spaces at the start of a document is read; the same line after a blank line is deleted.

The stripper is an anchored four-or-more-whitespace pattern with the multiline flag, and \s in JavaScript matches newlines. When a blank line precedes an indented line, the pattern starts matching at the blank line, spends one newline plus the indent, and then consumes the entire content line. Two newlines plus two spaces of indent is enough to delete the line. So the four-space rule is really a four-whitespace-character rule that can borrow from the empty line above it.

For a publisher's page run through a markdown converter, that is mostly harmless: prose paragraphs are not indented. For an agent that re-runs this function over its own text, it is a trap, because a three-space indent under a blank line — the ordinary way a model writes a nested list — silently drops the line from both counts.

Eighteen pages, measured

Twenty-four URLs went through POST /admin/parse on 2026-11-19. Eighteen completed. Six were refused with a named reason and no charge, listed at the end. Admin parses bypass quota and payment, so the run cost nothing and touched no free bucket.

page                                                  words    q   v    /1k
www.rfc-editor.org/rfc/rfc9110.html                   66479  333  24      5
en.wikipedia.org/wiki/Shakespeare%27s_sonnets          7259   90  10   12.4
simonwillison.net/                                     6473   24  10    3.7
en.wikipedia.org/wiki/Quotation                        5197   96  54   18.5
en.wikipedia.org/wiki/Web_scraping                     4157   60   2   14.5
docs.python.org/3/library/json.html                    3852   43  11   11.2
stripe.com/pricing                                     3792    0   0      0
kubernetes.io/docs/concepts/overview/                  1510    1   1    0.7
www.bbc.com/news                                       1221    7   8    5.8
en.wikiquote.org/wiki/Main_Page                        1140    3   0    2.6
news.ycombinator.com                                    944    0   2      0
arxiv.org/abs/1706.03762                                698    0   0      0
developer.mozilla.org/en-US/docs/Web/API/Fetch_API      470    0   0      0
nasa.gov                                                437    0   0      0
www.whitehouse.gov/briefing-room/                       195    2   0   10.6
www.federalregister.gov/                                175    2   0   11.8
example.com                                             135    0   0      0
www.justice.gov/opa/pr                                  104    0   0      0
TOTAL 18 pages                                       104238  661 122

104,238 delivered words carry 661 pairs and 122 verbs. Most of the pairs — 579 of 661 — sit on three Wikipedia articles and the HTTP specification. Six of the eighteen pages returned zero on both counts, which is the honest shape of a punctuation counter on a web made of marketing pages and documentation.

Four rows carry the argument.

The rate is a property of the genre, not of the reporting. RFC 9110 holds 333 pairs — mostly quoted grammar and header values — against 24 verbs. Wikipedia's Quotation article holds 96 pairs against 54 verbs. The first is a specification quoting syntax; the second is prose quoting people. Read alone, the pair count ranks the specification three and a half times higher. Read as a pair, the story inverts, which is why the field returns both numbers.

The pair count can be made of code. docs.python.org/3/library/json.html returns 43 pairs at 11.2 per thousand words. Every one of them is a JSON literal from an example — "foo", "json": "obj", "streaming API" — sitting on plain lines that the converter did not fence. The delivered body holds 51 such pairs; 43 survive the stripping. A documentation page about a data format is a quotation-dense page by this counter, and correctly so: the counter measures quotation marks, and a JSON example is made of them.

Verbs live in link titles. The Hacker News front page returns zero pairs and two verbs. Both verbs are inside links: a headline ending IEA says and another reading Someone reported java4shell bug. The counter reads a page of links and reports two attributions, which is precisely what the markdown contains.

A four-digit word count is not a document. Two rows sit under 200 words and still land in the top six densities in the run. www.federalregister.gov/ returned 175 words at 11.8 pairs per thousand, with 2 pairs and no verbs. That page is not an article: its title is Federal Register :: Request Access, and its page_status says {"is_error_page": false, "kind": null, "confidence": "high"}. The parse completed, the signals agree the content is a document, and the content is an access request. No field in the payload calls that a failure.

The same page is the clearest case for reading the triple together. A 175-word page at 11.8 per thousand looks like dense reporting until the word count is beside it.

The denominator is the body, not the delivered page

Re-running the deployed function over the delivered markdown reproduced the served triple exactly on 14 of 18 pages. On four, the pair count and the verb count matched and per_1k_words was off by 0.1 to 0.4. That is not drift; it is a different string.

page                                   q   served  from_delivered  title line
en.wikipedia.org/wiki/Web_scraping    60     14.5            14.4  # Web scraping - Wikipedia
www.bbc.com/news                       7      5.8             5.7  # BBC News - Breaking news, …
www.federalregister.gov/               2     11.8            11.4  # Federal Register :: Request Access
www.whitehouse.gov/briefing-room/      2     10.6            10.3  # News – The White House

The worker extracts from the body and assembles the response as a title line followed by that body. The signals are computed before the title is prepended, and the denominator is the body's word count. So the delivered markdown is a few tokens longer than the text the ratio was computed over.

Dropping the first line before recomputing makes all eighteen exact:

delivered markdown as-is: 14/18 exact
first line dropped:      18/18 exact

Two consequences, both small and both worth knowing. The published ratio is very slightly understated — the title's words are missing from the denominator. And a client that recomputes the field from the markdown it received will disagree with the server by a tenth on roughly one page in five. For a gating rule, compare against the served value; for a reproduction, strip the first line first. The discrepancy is largest on short pages, where six words are a larger share of the denominator.

What arrives against what the page said

A last measurement, and the one with the most caveats. Every completed page was fetched again with a plain HTTP client, its tags stripped and its entities decoded, and the same quote pattern was run over the publisher's full document text.

page                                   delivered  full_text  words
www.rfc-editor.org/rfc/rfc9110.html          333        685  66479
en.wikipedia.org/wiki/Quotation               96        144   5197
simonwillison.net/                            24         45   6473
www.federalregister.gov/                       2         14    175
en.wikipedia.org/wiki/Web_scraping            60         61   4157
en.wikiquote.org/wiki/Main_Page                3          2   1140
news.ycombinator.com                           0          0    944
nasa.gov                                       0          0    437

Treat the right-hand column as an upper bound, not a loss figure. The full text includes navigation, footers, cookie copy and sidebar teasers that the extractor is supposed to discard, and this probe counts the whole document. On RFC 9110 the gap is large because the full page carries its table of contents and index; the delivered specification body keeps 333 pairs of its own.

One row is a different shape and worth stating plainly. The delivered text of Wikiquote's front page contains one curly open mark, one curly close and four straight marks across 1,140 words. A page whose entire purpose is to present quotations arrives with almost none of them, because the quotations are laid out in table cells and the conversion does not preserve them. The field reports 3 pairs. It is not wrong about the text it was given; the text is not the page.

Reading the pair

Used as a pair, the two counts narrow a set. Used alone, either one misleads. A gate that branches on both, on a completed job:

def reporting_signal(job):
    q = job["litmus"]["quote_density"]
    quotes, verbs = q["attributed_quotes"], q["attribution_verbs"]

    if quotes == 0 and verbs == 0:
        return "neither"          # marketing page, docs, or a failed extraction
    if quotes >= 5 and verbs >= 3 and quotes / max(verbs, 1) < 4:
        return "reporting"        # quotes and speakers move together
    if quotes >= 5 and verbs <= 1:
        return "typography"       # grammar, code samples, titles, terms in quotes
    if verbs >= 3 and quotes <= 2:
        return "paraphrase"       # speech reported, not quoted
    return "weak"                 # too little of either to say

The two middle branches are the ones the eighteen pages fill. Wikipedia's Quotation article lands in reporting at 96 to 54. RFC 9110 lands in typography at 333 to 24, which is the right answer for a specification quoting syntax. The BBC news index lands in paraphrase at 7 to 8, which is what an index of headlines looks like. docs.python.org lands in typography at 43 to 11, which is the right answer for a page of JSON examples and the wrong answer for a page of sourced prose — which is why the last section exists.

What the field does not do

It does not read who was quoted. It does not check that a verb and a quotation are near each other, that a quotation is attributed in the sentence it appears in, or that the person named exists. It does not distinguish a quotation of a company's statement from a quotation of a string constant. It counts characters on lines it was given.

The six refusals from the same run show the other half of the contract — a page that cannot be read comes back named and uncharged, not as a zero-filled signal object:

www.npr.org/                        blocked  consent_wall:markup
www.theguardian.com/international   blocked  consent_wall:markup
www.sec.gov/news/pressreleases      blocked  consent_wall:markup
apnews.com/                         blocked  cloudflare_challenge
paulgraham.com/greatwork.html       content_insufficient  0 words
www.gutenberg.org/…/pg74-images     content_insufficient  31 words, truncated

Three consent walls, one bot check, two pages that returned a shell instead of prose. No signal object, no charge, and a reason a caller can branch on. The field described in this post only exists for pages that actually arrived.

Reproducing this

The function is sliced from intel.ts by declaration, never retyped; the slice records its blob and source hash. Every number above comes from the scripts in the run directory:

python3 build_fns.py                            # slice computeQuoteDensity
node --experimental-strip-types fixtures.mjs    # 41 fixtures -> results.json
python3 probe_real.py                           # 24 URLs through /admin/parse -> real/
python3 recompute.py                            # independent recount + page text
node --experimental-strip-types verify_offset.mjs  # title offset: 14/18 then 18/18
python3 rollup.py                               # every table printed above

The 41 fixtures, all 18 payloads, the six refusals, the page-text counts and the scripts are committed beside this post. Two scope notes: the run used the admin path, so it consumed no free tier, and every value describes the deployed function as of 2026-11-19 — a later version can change any rule above without changing this page.

The endpoint is https://nanoparse.app, $0.002 per successful parse, no account and no API key, with the same surface served over MCP at https://nanoparse.app/mcp. The earlier survey of all six metadata groups is https://nanoparse.app/blog/2026-10-19-page-you-asked-for, and the neighbouring deep dives read one field apiece: https://nanoparse.app/blog/2026-11-16-citations-count, https://nanoparse.app/blog/2026-11-13-canonical-and-fetch and https://nanoparse.app/blog/2026-11-10-page-status-default.

← All posts NanoParse home