Repository navigation
fix(jats): keep the text of <preformat> and <code> blocks - #5283
Conversation
<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]>
|
✅ DCO Check Passed Thanks @MaiAditya, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit This PR extracts Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 1 related pull request(s) in the same code
The |
There was a problem hiding this comment.
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.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
<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-formulais handled. A<code>block'slanguageattribute sets the code language (viadetect_code_language, as in the HTML backend).<preformat>has no language attribute, so its language is only detected from the content._walk_lineargets# noqa: C901: the new branch takes it to complexity 31, andhtml_backend._walk_nodesandmd_backend._iterate_elementscarry the same marker. Unchanged frommainand 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:
Review evidence:
test_jats_preformat_is_code_blockintests/test_backend_jats.pycovers 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_languagecheckslanguage="python". All four fail onmain.tests/data/jatshas<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 passedprek run --files <changed files>: all hooks passed or skipped