-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap source lines and re-implement line numbers #14
Conversation
- Note, line links and custom start number no longer work
Can you comment on browser support? Can we rely on these features being available in browsers? |
The basic approach looks pretty clean; I guess my worries are (a) breaking existing templates that hard-code CSS (maybe acceptable, since it's better not to hard-code highlighting CSS, and going forward we have a way to define custom styles), and (b) browser support. |
I notice that with line numbers, there is also much more space between lines. Can this be fixed so that toggling line numbers doesn't change the line spacing? |
I'll check the browser support shortly, and have a think about existing css. As for the line spacing, it has to be set to avoid the numbers collapsing. I can set them both to the same, though do note it's set using min-height so long lines will break correctly. What do you think? Actually, we could add an option to wrap the lines or not so both behaviours are available, when not using line numbers. How does that sound? |
According to caniuse everything is supported with good coverage. I suspect screen readers don't read the numbers (I don't know how to test this) but the previous way of adding line numbers using a table likely suffered a similar problem. I'd also like to use clay for the (limited) css generation here as it's currently quite ad-hoc (and easy to introduce bugs) — I'll raise a separate issue. That would ensure the correct browser prefixes are supplied. Adding an option with both behaviours means touching the definition of FormatOptions. I can do it, but it might not be worthwhile — your call. |
+++ dbaynard [Aug 28 17 00:52 ]:
Adding an option with both behaviours means touching the definition of
FormatOptions. I can do it, but it might not be worthwhile — your call.
What do you mean, both behaviors? The old one-row table +
your new way?
I'd rather just drop support for the old method, if we make
this change. But I do plan to bump the version to 0.4 this,
since this is a change that might bite people if they don't
update their code, templates, etc. Thus, a change to
FormatOptions wouldn't be out of the question.
|
c4ed9fa
to
79f4262
Compare
+++ dbaynard [Aug 27 17 08:43 ]:
collapsing. I can set them both to the same, though do note it's set
using min-height so long lines will break correctly. What do you think?
I think using min-height in both cases is fine. But the
current min-height with line numbers seems a little too
high.
Actually, we could add an option to wrap the lines or not so booth
behaviors are available, when not using line numbers. How does that
sound?
Isn't wrapping controlled by a global CSS property? Sorry,
I'm not following this, maybe you could explain in a bit
more detail what you have in mind.
|
+++ dbaynard [Aug 28 17 00:52 ]:
I'd also like to use [2]clay for the (limited) css generation here as
it's currently quite ad-hoc (and easy to introduce bugs) — I'll raise a
separate issue. That would ensure the correct browser prefixes are
supplied.
I guess I'm okay with using clay, if it avoids bugs; it's
another dependency, but at least it doesn't bring in new
transitive dependencies.
|
79f4262
to
7a9a405
Compare
7a9a405
to
b9ee4d0
Compare
By 'both behaviours' I mean wrapping each line of output in a div, or not: the act of wrapping breaks any css which relies on When each line of displayed code is wrapped in an element it is possible to style it using css, but the element must be added during html generation by skylighting. The change would be adding a new command line option restoring the non-wrapping behaviour (I'd prefer the default to be wrapped). It appears this could be implemented quite succinctly, but I'd be happy to bump the version without adding what would be a legacy option to the API. It is the presence of line numbers that is controlled by css, although in order to handle setting the starting line numbers, all the line numbers must be produced by skylighting. Eventually (when |
I made the suggested changes, including a min-height of 1.25 em (if it isn't set there are display issues with blank lines). Again, sensible defaults. Please excuse the force push; I'm trying to keep the commits easy to follow, for my own sake as much as anything. Also I have not yet tested these changes with pandoc. I'm building pandoc with this version of skylighting, and I'll check pandoc's tests. |
What if we just used |
The problem isn't the css in this package; the problem is that users may have their own css which uses the I suspect this is a minor problem, though, as few users are likely to override the syntax highlighting, it will be obvious from the output that there's been some change, and the fix is just once find/replace operation away. Actually, using |
Right, I wasn't thinking it would help with existing uses of
'code > span', more just that it simplifies the CSS we need
to include to make the highlighting work (and as you say,
it may make things more future-proof). But there may be
a significant performance difference? I really have no
idea.
|
I'm changing it to I'm getting some test failures from pandoc's test suite, though I think the cause is my setup (I'm not certain I've bootstrapped the syntax files correctly in my local pandoc repository). I'd like to confirm whether the failures need fixing here because they are regressions, or fixing in pandoc's test suite because they are a change in the api. Once I've done that, I'd consider the code ready for consideration. |
I think the pandoc test failures are to do with me not bootstrapping skylighting correctly. They occur when I try to use local git commits to provide the skylighting dependency (stack doesn't like skylighting's build pattern, it seems).
|
I've fixed the bootstrapping in my pandoc build, and I can no confirm the downstream pandoc issues correspond to the intended changes. I've fixed these failing pandoc tests to correspond to the changes introduced by this PR, in jgm/pandoc#3905 As a result, I'm satisfied with this PR. In pandoc, the copy-paste now works better than with tables. It is now possible to copy a whole document, including numbered lines of source code, and the line numbers will not be copied. If the numbers are wanted this can be changed by a user, in css. |
I should add, I've investigated the failing travis build, but I have no idea why it failed. I can compile fine with GHC 8.0.2. |
It's probably an out of time/memory issue. I've been seeing
this recently.
+++ dbaynard [Sep 09 17 07:31 ]:
… I should add, I've investigated the failing travis build, but I have no
idea why it failed. I can compile fine with GHC 8.0.2.
—
You are receiving this because you commented.
Reply to this email directly, [1]view it on GitHub, or [2]mute the
thread.
References
1. #14 (comment)
2. https://github.com/notifications/unsubscribe-auth/AAAL5HaKiOZ8oAnmLabm2a-sqS4OC7v2ks5sgqFAgaJpZM4PDx74
|
Great, I've merged this! |
Looks like taking out the enclosing div fixes this. |
I think the explanation is that with the bare pre we have overlapping margins with the preceding p. (See https://www.w3.org/TR/CSS21/box.html#collapsing-margins). Putting the pre in a div defeats the margin-collapsing feature, so we get the margin for the p AND the margin for the pre. Keeping the surrounding div but adding |
I suspect it's an interaction between the spans wrapping the code identifiers and the new top level div. Should be a simple fix; I can take a look tomorrow. I presume the code producing that fragment is the obvious? Does the issue appear with inline code, too? |
I already put out a release removing the outermost div.
That seems to work well.
As I noted, I think it has to do with margin collapsing.
(You can see this quite clearly in Safari's inspector.)
+++ dbaynard [Oct 26 17 16:42 ]:
… I suspect it's an interaction between the spans wrapping the code
identifiers and the new top level div. Should be a simple fix; I can
take a look tomorrow. I presume the code producing that fragment is the
obvious?
|
Hi I just kind of got bitten by this (no big deal! 😄), and I'm curious about it. In the intro above @dbaynard says
Where should this css (display: inline-block) appear? For instance, the following input:
when output with
So the div in question (which I'm guessing is Maybe recent changes to skylighting haven't made it into pandoc yet (I'm using pandoc 2.0.1.1)? In my own case, I just had to add a rule to my stylesheet:
...and all was well with the world. |
The css should appear inline in head; these changes haven't touched that behavior, as far as I am aware. But yes, you are correct that the comment about inline-block refers to Given this is the skylighting tracker, though, is the output correct when just the code is converted using skylighting? |
Ah, OK, thanks. (I've just spotted that pandoc now seems to have an explicit I'm afraid I don't have a standalone skylight to test with; I grew (very) tired of haskell's stack / cabal and ripped the whole lot out some time ago; sorry I can't be more help with that. I'll make any further enquiries in the pandoc tracker. |
Fixes #13. Would be good to get into pandoc 2.0. From the changelog:
div
withdisplay
set toinline-block
.The
div
s make per-line processing easier. They cannot be set asdisplay: block
as that introduces extra new lines when copying and pasting.The line numbers are always produced, as
data-line-number
attributes, andcss to display them as
::before
elements are always produced. The option toswitch on line numbering only toggles a class; this means it is possible to toggle
line numbering without re-running skylighting.
linkAnchors
option is set, wrap with ana
element rather than adiv
,set so that clicking the line number (and only the line number) will jump to that
line.
The new output with no line numbers
and with line numbers
The code matches all features of the previous, table base code, with one exception: previously, copying code from a printed pdf didn't pick up the line markers, but now it does. However, I have judged the changes are worth it, as copying from a pdf also gets line breaks wrong so is inherently imperfect.