I'm using Python implementation of Markdown with codehilite
and lineos
option. It produces a code like this:
<table class="codehilitetable">
<tr>
<td class="linenos">
<div class="linenodiv">
<pre>1
2</pre>
</div>
</td>
<td class="code"><div class="codehilite"><pre>
<span class="k">def</span>
<span class="nf">func</span>
<span class="p">(</span>
<span class="n">n</span>
<span class="p">):</span>
<span class="k">return</span>
<span class="n">n</span>
<span class="o">**</span>
<span class="mi">2</span>
<span class="o">+</span>
<span class="mi">3</span>
<span class="o">*</span>
<span class="n">n</span>
<span class="o">+</span>
<span class="mi">1</span>
</pre></div></td>
</tr>
</table>
This is a table with one row and two cells; first cell is for line numbers and second is cell is for actual code. The contents of each cell are inside a div
and pre
element and span
elements are used for syntax coloring.
I would like to display a horizontal scrollbar in case a line of code is too long, but I'm having problems, because it's a table.
Ideally I'd want the scrollbar just on the code cell (td.code
), but this only works if set width of the table to 100%, which makes both cells long 50%. I want the line-number cell (td.linenos
) to be just as long as it's required for the actual line-numbers to be shown.
Here's my current CSS:
pre, code { overflow:auto; }
table.codehilitetable { table-layout: fixed; white-space: nowrap; width:100%; }
If this is not possible, then I'd like to have a scrollbar on the whole row (tr
). But the above code doesn't work on table rows.