Skip to content

Commit c6421d8

Browse files
committed
Match bibliography containers by whole class token, not substring
Review follow-up. [class*="references"] also matched an inline citation marker (xref-references) or a wrapper such as body-with-references, so it could silently delete the very body text #121 restores. Only exact bibliography class tokens on block containers, plus the doc-bibliography role, are dropped now; an unlisted layout keeps its bibliography text rather than risking the article's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC
1 parent 85f15f7 commit c6421d8

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎src/linkml_reference_validator/etl/extract/html.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@
4949
#: Bibliography containers inside an article region. A cited paper's title is
5050
#: not evidence for the citing article, so their text is never extracted:
5151
#: PLOS ``ol.references``, PMC ``section.ref-list``, Springer
52-
#: ``ol.c-article-references``, and the DPUB-ARIA ``doc-bibliography`` role.
52+
#: ``ol.c-article-references``, Wiley ``section.article-section__references``,
53+
#: and the DPUB-ARIA ``doc-bibliography`` role. Whole class tokens on block
54+
#: containers only: a substring match would also delete an inline citation
55+
#: marker or a wrapper such as ``body-with-references`` around the whole
56+
#: body. A layout not listed here keeps its bibliography text; extend the list
57+
#: as publishers are seen, never with a substring.
5358
BIBLIOGRAPHY_SELECTOR = (
54-
'[class*="ref-list" i], [class*="references" i], [class*="bibliograph" i], '
59+
":is(section, div, ol, ul, aside)"
60+
":is(.ref-list, .references, .c-article-references,"
61+
" .article-section__references, .bibliography), "
5562
'[role="doc-bibliography"]'
5663
)
5764

‎tests/test_html_scope_text.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,19 @@ def test_verified_stamp_tolerates_a_yaml_comment():
188188
assert ReferenceFetcher._is_verified_html_body(
189189
"---\nhtml_full_text_version: 1 # migrated\n---\nBody."
190190
)
191+
192+
193+
def test_classes_that_merely_mention_references_keep_their_text():
194+
"""Only whole bibliography class tokens on a container are dropped.
195+
196+
A substring match would delete an inline citation marker, or a wrapper
197+
around the whole body, without a trace.
198+
"""
199+
for markup, kept in (
200+
('<p>See <a class="xref-references">[1]</a> here.</p>', "[1]"),
201+
('<div class="body-with-references"><p>Whole body text.</p></div>', "Whole body text."),
202+
('<div class="pref-list"><p>Preference text.</p></div>', "Preference text."),
203+
('<span class="references">inline span text</span>', "inline span text"),
204+
):
205+
text = HTMLExtractor().extract(f"<article>{markup}</article>".encode()) or ""
206+
assert kept in text, markup

0 commit comments

Comments
 (0)