Repository navigation
fix(code): skip Pygments linenos inline line-number spans (#526) - #537
Open
samiarif02 wants to merge 1 commit into
Open
samiarif02 wants to merge 1 commit into
samiarif02 wants to merge 1 commit into
Conversation
Sphinx / Read the Docs render Pygments `:linenos:` as inline <span class="linenos">N</span> spans. The code extractor only skipped `span.lineno` (labml.ai's class), so `linenos` fell through to the generic `span[class*="line"]` rule and each line number landed on its own line in the extracted code. Match `span.linenos` alongside `span.lineno`. Fixes kepano#526
This branch has not been deployed
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.
Problem
Sphinx / Read the Docs render Pygments
:linenos:code blocks with the line numbers as inline spans directly in the code:The code extractor skips
span.lineno(singular — labml.ai's class, added in #223), but notlinenos. So the number falls through to the generic line rule,span[class*="line"]matcheslinenosand appends a newline, and each line number ends up on its own line in the extracted code:Reproducible on the sphinx_rtd_theme demo page ("Emphasized lines with line numbers"). Reported in #526.
Fix
Skip
span.linenosalongsidespan.lineno:Tests
Added
tests/pygments-linenos.test.tswith a Sphinx:linenos:block; it fails onmain(the digits1/2/3survive as their own lines) and passes with the fix.vitest runis green except the pre-existingwebsite/*suites that need the@lezer/*packages and fail the same way onmain.