Skip to content

fix(jats): keep the text of <preformat> and <code> blocks - #5283

Merged
PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
MaiAditya:fix/jats-preformat
Nov 11, 2026
Merged

PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
MaiAditya:fix/jats-preformat

Conversation

@MaiAditya

Copy link
Copy Markdown
Contributor

<preformat> and <code> hold verbatim text such as code or console output. The walker only emits text from <p> elements, so a block that is a direct child of a section was dropped, and one inside a paragraph was merged into the paragraph text without its line breaks.

These blocks are now added as code items, with their line breaks and indentation, and the paragraph text before them is flushed first, the same way disp-formula is handled. A <code> block's language attribute sets the code language (via detect_code_language, as in the HTML backend). <preformat> has no language attribute, so its language is only detected from the content.

_walk_linear gets # noqa: C901: the new branch takes it to complexity 31, and html_backend._walk_nodes and md_backend._iterate_elements carry the same marker. Unchanged from main and out of scope: a block directly in a <list-item> (a known gap noted in the code), or inside a <fig>.

Issue resolved by this Pull Request:
Resolves #5282

Checklist:

  • Documentation has been updated, if necessary. (not needed, no API change)
  • Examples have been added, if necessary. (not needed)
  • Tests have been added, if necessary.

Review evidence:

  • test_jats_preformat_is_code_block in tests/test_backend_jats.py covers a <preformat> in a section, a <preformat> inside a paragraph and a <code> in a section, and asserts the order of text and code items. test_jats_code_block_keeps_its_language checks language="python". All four fail on main.
  • Reference data: no file in tests/data/jats has <preformat> or <code>, so no groundtruth changed.
  • uv run pytest tests/test_backend_jats.py tests/test_backend_jats_sub_articles.py tests/test_backend_jats_table_footnotes.py -q: 142 passed
  • prek run --files <changed files>: all hooks passed or skipped
  • Not run: the full test suite.

<preformat> and <code> hold verbatim text such as code or console
output. The walker only emits text from <p> elements, so a block that is
a direct child of a section was dropped, and one inside a paragraph was
merged into the paragraph text without its line breaks.

Add the text of these blocks as a code item, with its line breaks and
indentation, and flush the paragraph text that comes before it. The
language of a <code> block comes from its language attribute.

Signed-off-by: Aditya Gupta <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @MaiAditya, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working jats issue related to JATS XML backend xml issue related to supported schema-specific XML formats labels Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 1b9f2ca36a. The analysis read the diff only. It did not run code from this pull request.

This PR extracts <preformat> and <code> elements as code items in the JATS backend. It preserves line breaks and detects code language.

Topic labels added: bug, jats, xml.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#5244 open changes the same code related: PR 5244 modifies heading labels and titles in the JATS backend, while this PR adds support for <preformat> and <code> blocks.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at 1b9f2ca36a. It read the code and did not run it.

I found no defect that must stop the merge. <preformat> and <code> become code items in the right order. For a block inside a <p>, the text before it is flushed and the tail text after it is kept. The <code language=...> hint reaches detect_code_language, which accepts a hint argument.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Nov 10, 2026
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/xml/jats_backend.py 90.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@PeterStaar-IBM
PeterStaar-IBM merged commit 328b69d into docling-project:main Nov 11, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working jats issue related to JATS XML backend xml issue related to supported schema-specific XML formats

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JATS: text of <preformat> and <code> blocks is dropped

2 participants