Skip to content

Keep inline formatting (italic, bold, sub, sup) in the export - #300

Merged
thesanogoeffect merged 2 commits into
mainfrom
claude/project-thread-ddvt1r
Dec 1, 2026
Merged

thesanogoeffect merged 2 commits into
mainfrom
claude/project-thread-ddvt1r

Conversation

@thesanogoeffect

@thesanogoeffect thesanogoeffect commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Keeps italics, bold, subscripts and superscripts in the export (schema 12.6, additive).

What changes

  • text[].formatted now carries the row's text marked up with <i>, <b>, <sub>, <sup> whenever the row has any inline formatting. Only &, < and > are escaped, so stripping the tags and unescaping gives text back exactly. text stays plain, so eq[], url[] and xref[] offsets are untouched.
  • New metadata.title_formatted and metadata.abstract_formatted, same markup, omitted when there is nothing to mark.
  • Italic or bold covering a whole paragraph or title (bold titles, italic abstracts) is treated as typeface and left out.
  • Schema 12.5 -> 12.6. Strict and reader JSON schemas regenerated; tests that used "12.6" as the hypothetical next minor now use "12.7".

Where the formatting comes from

Route Source
PDF text layer (native-text pass and text-layer backend) pypdfium2 font name / flags / weight / italic angle per glyph; sub/sup from size and baseline against the neighbouring full-size glyph (bibr/ocr/char_styles.py). About 20-35 ms per page.
OCR LaTeX ^{}/_{} and \textit-style commands, Markdown **/*, HTML tags in the model output (bibr/ocr/markup_styles.py), run through the same late cleaning as the text.
JATS <italic>, <bold>, <sup>, <sub>, MathML msup/msub/msubsup and one-letter mi (bibr/input/inline_styles.py).
HTML / ePub i em var cite b strong sup sub + MathML.
DOCX run-level bold/italic (direct or character style) and vertAlign.

Each parser records a styled source per paragraph/region/caption/title. At export, StyleAligner (bibr/utils/inline_markup.py) aligns each final, cleaned sentence onto that source and transfers per-character styles; a row whose source aligns on less than 60% of its characters gets no formatted value rather than a wrong one.

Testing

  • tests/test_inline_formatting.py (44 tests): markup round-trip, alignment edge cases, a generated PDF with italic/bold/raised text through both text-layer routes, OCR markers, and JATS/HTML/DOCX parsers through to the export.
  • Full suite passes locally; ruff, ruff format, strict-core mypy and the public-tree check pass.
  • Checked by hand on real born-digital PDFs and the JATS fixture PMC4383902 (6 formatted rows, all round-trip). Not yet run through bibr chew end to end on a GPU machine.

Not part of 0.9.3; meant for the release after it.


Generated by Claude Code

text[].formatted, metadata.title_formatted and metadata.abstract_formatted
carry an HTML-subset markup (<i>, <b>, <sub>, <sup>; only & < > escaped)
whose plain form equals the plain field, so eq/url/xref offsets are
unchanged. Formatting is read from the PDF text layer (font and baseline
per glyph), OCR output (LaTeX, Markdown and HTML marks), JATS, HTML/ePub
and DOCX, and aligned onto the final sentence text at export.

Export schema 12.5 -> 12.6 (additive).
@thesanogoeffect thesanogoeffect self-assigned this Nov 30, 2026
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.34951% with 108 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.00%. Comparing base (197447e) to head (d66f343).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #300      +/-   ##
==========================================
- Coverage   91.03%   91.00%   -0.04%     
==========================================
  Files         345      349       +4     
  Lines       74575    75493     +918     
  Branches    13933    14130     +197     
==========================================
+ Hits        67892    68704     +812     
- Misses       4115     4176      +61     
- Partials     2568     2613      +45     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Adds supplement, subject, contributor, review and review_text, plus metadata.article_type, affiliation.ror and funding.funder_doi, to export schema 12.6, as metacheck's publisher-XML reader keeps them. All are omitted when there is nothing to write, so bibr's own exports are unchanged and a 12.5 export is still a valid 12.6 reader input.
@thesanogoeffect
thesanogoeffect merged commit bc99570 into main Dec 1, 2026
2 checks passed
@thesanogoeffect
thesanogoeffect deleted the claude/project-thread-ddvt1r branch December 1, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant