sight icon indicating copy to clipboard operation
sight copied to clipboard

Long lines do not wrap properly

Open JonnoFTW opened this issue 9 years ago • 9 comments

I am trying to view a .tex file with very long lines, but the <pre> element does not split these long lines despite it having element style:

word-wrap: break-word;
white-space: pre-wrap;

Adding !important to these rules makes the line wrap, but there is no padding at the start of the newline, so it goes below the line number margin:

http://puu.sh/j5Gbj/4b64065969.png

JonnoFTW avatar Jul 20 '15 05:07 JonnoFTW

Have you got an URL I can reproduce this with?

tsenart avatar Jul 21 '15 15:07 tsenart

@tsenart https://raw.githubusercontent.com/JonnoFTW/UA-AID/master/tex/proposal.tex

JonnoFTW avatar Jul 22 '15 04:07 JonnoFTW

@JonnoFTW: Have you got any fix in mind?

tsenart avatar Aug 08 '16 20:08 tsenart

I don't know sorry, my CSS skills aren't that good.

JonnoFTW avatar Aug 09 '16 01:08 JonnoFTW

It seems like a commonly used method for dealing with this is making the "code area" a <table> with two columns per line/row - one for line numbers (containing a ::before akin to how .line does already), and one for actual code. This way, when the code wraps, the line-number-cell extends it's height, and it remains aligned accordingly.

<table>
<tr><td class="line"></td><td>(line 1)</td></tr>
<tr><td class="line"></td><td>(line 2)</td></tr>
</table>
pre table {
    border-spacing: 0;
    border-collapse: collapse;
}
pre td.line {
    width: 1%;
    white-space: nowrap;
    text-align: right;
    min-width: 2em;
}

GitHub uses a similar approach for displaying code in repositories.

YellowAfterlife avatar Oct 10 '16 12:10 YellowAfterlife

@YellowAfterlife: Would you draft a PR?

tsenart avatar Oct 10 '16 13:10 tsenart

I'll try tomorrow. Been a little while since I've last poked with actual Chrome extensions (as opposed to making userscripts).

YellowAfterlife avatar Oct 10 '16 16:10 YellowAfterlife

@tsenart This wasn't particularly "tomorrow", but here: https://github.com/tsenart/sight/pull/88

YellowAfterlife avatar Nov 05 '16 12:11 YellowAfterlife

@YellowAfterlife: I'll take a look at your PR tomorrow.

tsenart avatar Nov 09 '16 22:11 tsenart