Repository navigation
Conversation
Syntax highlighters such as Pygments (linenos="table") and the Crayon/Urvanov WordPress plugin lay out code as a one-row table with line numbers in the first cell and the code in the second. Replace such tables by a code element when the first cell only holds consecutive line numbers matching the number of code lines. Fixes adbar#1187
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1187
Syntax highlighters that show line numbers (Pygments
linenos="table"in Sphinx, MkDocs and Hugo, Crayon / Urvanov on WordPress) lay out code as a one-row table: line numbers in the first cell, code in the second. Trafilatura kept the table, so the code ended up in a table cell, on one line in markdown and txt output.In
convert_tags(), a table with one row and two cells is replaced by a<code>element when the first cell only holds consecutive line numbers and their count matches the lines of code in the second cell (the lines of its<pre>, else its innermost block elements). The check does not rely on class names; data and layout tables do not match it.Tests:
test_line_numbered_code_tablesintests/unit_tests.py, throughextract(), covers Pygments, Crayon, a single line and two data tables. The three code cases fail without the change.Checks, rebased on master (15c105a): pytest, mypy,
ruff check,ruff format --checkandtests/eval_gate.pypass, gate scores unchanged.Processing time,
python tests/evaluate.py --small, two runs each (time difference relative to the baseline extractor):Scores are identical, the difference is within run-to-run noise.
AI disclosure: the fix and tests were written with Claude Code (Opus 5.5); I reviewed and tested them.