Skip to content

Pygments inline line numbers leak into code block text #222

@MaxWolf-01

Description

@MaxWolf-01

Pygments' inline line number spans (<span class="lineno">) are not stripped during code extraction, so line numbers appear concatenated with code content.

Example

https://nn.labml.ai/graphs/gat/index.html

<div class="highlight"><pre><span class="lineno">28</span><span></span><span class="kn">import</span> <span class="nn">torch</span>
<span class="lineno">29</span><span class="kn">from</span> <span class="nn">torch</span> <span class="kn">import</span> <span class="n">nn</span></pre></div>

Expected:

```
import torch
from torch import nn
```

Actual:

```
28
import torch
29
from torch import nn
```

Root cause

extractStructuredText in elements/code.ts skips several line number formats (span.lnt for Chroma, .react-syntax-highlighter-line-number, .rouge-gutter) but not Pygments' span.lineno.

Fix direction

Add a skip for span.lineno, same pattern as the existing span.lnt skip:

if (element.matches('span.lineno')) {
    return '';
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions