Repository navigation
Cache url: HTML pages as readable text, so quotes through links and bold text match - #103
Conversation
Inline tags (a, b, em, span, ...) are unwrapped in place, block-level tags and <br> start a new line, a table row becomes one line with its cells joined by " | ", <pre> keeps its whitespace, and entities are unescaped. Non-content elements and comments are dropped exactly as sanitize_html drops them, through a shared helper. Unlike HTMLExtractor, nothing is narrowed to <article>/<main> and no <p>-only shortcut is taken, so every text node of the sanitized markup survives, contiguous. A property test checks that over the HTML fixtures. Not yet used; URLSource switches to it next (#102). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since #92, URLSource cached sanitized body markup, so a quote could only match text inside a single text node: any sentence that ran through a link, bold or emphasis failed even when copied exactly from the page (the Flint press release, Wikipedia lead sentences, ZFIN's license line), and a whole page sat on one unreadable line. URLSource now flattens HTML with html_to_text, still after reading the citation_title from the raw page. URL_SOURCE_CACHE_VERSION goes to 2 so version 1 entries are re-fetched; an unreachable page keeps its old entry. The two sanitize tests that asserted markup survives are replaced by one asserting the readable-text shape; everything they dropped is still dropped. Fixes #102 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
validate-urls.md describes what an HTML page becomes in the cache (inline tags unwrapped, one line per block and per table row, cells separated by " | ", <pre> kept, nothing narrowed to the article). troubleshooting.md records url_source_version 2 and warns that the refresh rewrites every cached HTML page and re-fetches it, so a page that has since changed can stop supporting a quote (#102). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude finished @caufieldjh's task in 1m 13s —— View job Review of PR #103: cache
|
The tr branch read only direct td/th children, so a row's stray text was lost, and so was every cell of an older layout that wraps them, as in <tr><form><td>. The sanitized markup kept that text, so this broke the invariant that every quote matching today still matches. _row_cells now walks the whole row, descending into wrappers that hold cells and keeping anything else as a part of its own. Addresses review on #103 (item 1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
get_text() ignores <br>, so <pre>a<br>b</pre> came out as "ab" and a quote of "a b" could not match. _pre_text reads the block's strings itself, with each <br> as a line break, and leaves the tree untouched. Addresses review on #103 (item 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_flatten took one Python frame per level of nesting, so a page nested past the recursion limit raised RecursionError out of URLSource.fetch. Parsing such a page works, so only the walk was at fault. _lines now keeps its own stack, with a marker for the end of each block. Output on the HTML fixtures is byte-identical. Only a table nested in a table cell still recurses. Addresses review on #103 (item 4). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The docstring promised only non-blank lines, but a <pre> block's lines are kept as written, blank ones included, since its whitespace is part of its text. That is intended; the docstring now says so and a test pins it. Addresses review on #103 (item 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reader seeing td/th in TEXT_BREAK_TAGS and in the tr path could take one for dead code. Both are live: the tr path joins a row's cells, and a cell outside any <tr> still gets a line of its own. Addresses review on #103 (code quality, first note). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses review on #103 (code quality, second note). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The whole inner table folds into the outer cell's line, its cells separated by " | " and its rows by a space, so nothing is lost and a quote across it still matches once normalization drops the pipes. Addresses review on #103 (test coverage, third gap). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every cached HTML page is rewritten by the version 2 refresh, and that diff would bury any content change made alongside it. The migration note now says to run validation on an otherwise unchanged checkout right after upgrading and commit the rewritten cache files by themselves. Addresses review on #103 (open questions, migration note). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude finished @caufieldjh's task in 47s —— View job Re-review of PR #103 after the latest push
I couldn't run tests in this job, because Overall: every item from the last review is fixed, each in its own commit and each with a test. I see no blocking problems, so this looks ready to merge from my side. Earlier review items
Remaining notes (none blocking)
Code quality, performance, security
Test coverageCoverage now includes every edge case I raised, alongside the property test over the fixtures. One optional addition: a test for a |
Fixes #102.
Since #92,
URLSourcecached sanitized markup. A quote could only match text inside a single text node, so a sentence that ran through a link, bold or emphasis failed even when copied exactly. Examples: the Flint press release, Wikipedia lead sentences, ZFIN's license line. A whole page also sat on one unreadable line.Commits (best reviewed one at a time)
html_to_text(etl/extract/html.py). It flattens a whole page:<br>start a new line;|;<pre>keeps its whitespace, and entities are unescaped;sanitize_htmldrops them, through a shared helper.As the bot comment on url: pages: a quote that runs through a link or bold text fails; cache readable text instead of markup #102 suggested, it does not reuse
HTMLExtractor. That extractor keeps only<p>text when a page has any, and narrows to<article>/<main>; either would lose text that matches today.URLSourceuses it, andURL_SOURCE_CACHE_VERSIONgoes 1 → 2. The title is still read from the raw page'scitation_titlefirst. Two old tests asserted that markup survives; they are replaced by one that checks the readable-text shape.Docs:
validate-urls.mdandtroubleshooting.md, including a migration note.The invariant
"Every quote that matches today still matches." A property test checks this over the HTML fixtures (PLOS, DSpace, IRIS) and two synthetic pages: every text node of the old sanitized markup, normalized, appears in the normalized flattened text.
Open questions from #102
|. Normalization drops punctuation, so a quote copied from a rendered row with spaces between cells still matches. There's a test for this.Verification
This press release was produced by the City of Flint.now givesValid: True. The cache entry is 107 lines with no markup.test_pmid_network(2) andtest_html_fulltext_acceptance(1). They pass when rerun alone, and the same files also fail onmainon this machine (5 and 1 failures), from network and local-server timeouts.🤖 Generated with Claude Code