Skip to content

HtmlFormatter: filename doesn't work well with linenos=table #1757

@Cartroo

Description

@Cartroo

When using HtmlFormatter with both the linenos=table and filename=testfile options, you get some output like that shown below. The problem is that the filename being output within the <td> for the code throws off the line number alignment.

<table class="highlighttable">
  <tr>
    <td class="linenos">
      <div class="linenodiv">
        <pre>...</pre>
      </div>
    </td>
    <td class="code">
      <div class="highlight">
        <span class="filename">testfile</span>
        <pre>...</pre>
      </div>
    </td>
  </tr>
</table>

I suggest that this is unlikely to be useful to anyone, since it will invariably throw off the line numbering alignment. Hence, in the special case of someone using linenos=table and specifying a filename I would suggest that another table row is output as a caption:

<table class="highlighttable">
  <tr>
    <td colspan="2" class="filename">testfile</td>
  </tr><tr>
    <td class="linenos">
      <div class="linenodiv">
        <pre>...</pre>
      </div>
    </td>
    <td class="code">
      <div class="highlight">
        <pre>...</pre>
      </div>
    </td>
  </tr>
</table>

I can look at entering a pull request to implement this, but I wanted to get some feedback on whether this would be acceptable first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    changelog-updateItems which need to get mentioned in the changelog

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions