-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Use of <a> in source code highlighting is challenging #4386
Comments
This is challenging because many css templates set a:hover (instead of
the technically correct a:link:hover, a:visited:hover), meaning that
every syntax highlighted line gets an underline (or other special
treatment)
Do you have suggestions for an alternative?
By the way, this relates to the jgm/skylighting package. We've
had a number of CSS changes, and there are a lot of
constraints. Pinging @dbaynard
|
|
It was for line numbers; I do like your solution (r-lib/pkgdown@34a83e8) and would be keen to integrate upstream. However, I don't think that would fix your problem, as the samples in the linked issue don't appear to be using the css generated by skylighting (as output by pandoc) — is that correct? |
What do you mean by "line numbers link to the code line"? It's my understanding that |
Yes, It might actually be possible to wrap the lines in a <a class="sourceLine" id="cb1-1" data-line-number="1"></a><span class="sourceLine">…</span> The reason for the changes was that despite a 'line of code' being a meaningful concept in documents that might be produced by And please excuse me; I had to rush off and didn't hit send the other day (though it did give me the time to think up the potential solution). |
Ah got it, thanks for the explanation and the fix idea! |
Great - let me know what's most helpful, then. |
Your proposed solution of "empty" |
So the reason for the empty |
Yes. Though there's no point bothering with the But… I was hoping it would be possible to generate the line numbers dynamically, in the browser. That way it's possible to update the line numbers in generated html without having to recompile the source. Indeed that's what the 'data-line-number' business was originally about. I've actually just figured out a way to do it using css counters instead, generating This could be done in a way to reduce line noise, by moving all but the <span class="sourceLine" id="cb1-1" data-line-number="1"><a href="#cb1-1"></a>…</span>
Edit: I'll just PR to skylighting when I've made the changes. |
Nobody seems to have raised further issues with this, and it is needed somewhat urgently to avoid regressions on jgm/skylighting#32. I'll fix at the weekend. |
I've been unable to make the time to do this — I'll aim to do it this week. It's really the regression testing that takes the time; the changes are already described in this issue. |
@dbaynard may we have an update about this issue? For now, I am trying to use a custom CSS to customize the styling of Thank you. |
Yes, I had to prioritise other work over pandoc. I apologise for the delay. I'll put it in the to do list for next weekend; meanwhile anybody else is welcome to PR. |
Just to say; I'm not sure when I'll get around to this. I can help if anybody else wishes to contribute. |
i see some mention of the rationale for the |
@patrickhlauke they only become clickable if in
|
I will, shortly (next week). Thanks for your patience! |
Is there any way to simply disable the |
@dbaynard - it seems you haven't found time to do this? I can make this change myself. |
Yes, please make the change. I have not found the time (phd thesis woes, very long story… though now thankfully coming to an end). Thanks for your patience. |
Should the span with class |
I can change the HTML, but I may need help figuring out how to change the CSS so everything looks as it did before... |
I can also help out (also with CSS), but I haven't followed the discussion closely... |
I can now actually schedule time to do this (this weekend)! As I understand it, the html should look like this. <code style="counter-reset: source-line n">
<span class="sourceLine" id="cb1-1" data-line-number="1"><a href="#cb1-1"></a>…</span>
</code> where the The css needs to generate the pseudo element on the pre.numberSource > code a:first-child::before {
counter-increment: source-line;
content: counter(source-line);
} (Edit: the above has been fixed; it used to say The tricky part is testing it; I've used something ad-hoc, before, but it might be worth going with a more robust option (e.g. https://www.browserstack.com/open-source). And it needs to be run through epubcheck, too. |
|
@dbaynard Generally, this seems like a good approach. But it seems we can now simplify the generated HTML a bit. Apologies if these points were already discussed. Potentially, they might also break some users' scripts/custom css?
|
(on mobile, I'll edit formatting later)
We can do this.
It is. Forgive me, I think I used the wrong name in my example (pandoc/skylighting use different terms, I believe).
Probably. That also pre-dated the id. I believe the CSS counters will work on all platforms where the data attribute would work. Having the attribute makes it easy to target single lines by number, though I don't think it's anything that could not be achieved with the id and
Each |
The original, default, print CSS was quite broken — it used tables for line numbers, and it was impossible to supply a solution after pandoc processing as skylighting output didn't demarcate lines of code. Unfortunately, the solution I picked had a few issues. I don't think there was that much more to the discussion! |
Sounds good, I suppose there could also be changes made to skylighting (which pandoc uses)... but maybe @jgm prefers to not change too many things due to backwards-compatibility... |
I've made the PR (all the changes are in skylighting). I've made many small commits so it should be straightforward (for me) to remove any backwards-incompatible changes. |
Is there a performance penalty to using |
Wrap html source lines with `<span>`, not `<a>`. Fixes jgm/pandoc#4386. Also fixes #33 (and therefore fixes jgm/pandoc#4278). As it stands, it doesn't seem to work in epub. I suspect there are changes that need to go in data/epub.css (as per #32).
Yeah, targeting
Also we have the following weird thing in the output: div.sourceCode
{ }
@media screen {
code.sourceCode > span > a:first-child::before { text-decoration: underline; }
} Why would you want the line numbers be underlined? |
Ach I knew I'd forgotten something… I'll PR later today. Thanks!
This matched previous behaviour. I suppose it suggests they are links (hence why it's for screen only)? The |
I'm uncertain about the underlining on line numbers. It looks cluttered, but it is nice to have a visual indication that it's a link. It should be possible for users to disable this with their own CSS, right? |
yes... |
Most browsers already give you a visual indication of a link on hover (cursor changes). |
@mb21 see jgm/skylighting#73 for the |
Also, it would be good to test compatibility with a real CSS example; @mb21 is there one you could recommend? |
Maybe @hadley and @aubertc can test/give feedback on the new source-code line-numbering HTML/CSS output of the nightly release? |
I've just made jgm/skylighting#75 to indicate wrapped lines, in print css. @mb21 I'd be grateful if you'd take a look. |
@mb21 I just tried with the hash-8507d98a1 version, and it works just fine. Same code as in this issue, Microsoft Edge 41.16299.1004.0. Thanks a lot! |
fwiw i'll just observe that @hadley ' s comment that " this will work if you set, say, a background color, but it won't work if you also set the it's quite frustrating that you can't remove the link tags being generated; i.e that they are only generated with for example, hakyll - https://github.com/jaspervdj/hakyll/blob/master/web/css/syntax.css - sets but is terrible from a UX point of view, because it means you can no longer nicely select and copy lines! so one is left only with the option of over-riding all the styles for links in code (that one doesn't even want turned on in the first place!) -- edit: and, the fact that it places a line number on the line as the title is odd; it would be great if that could be an option to disable. |
e.g.
yields
This is challenging because many css templates set
a:hover
(instead of the technically correcta:link:hover
,a:visited:hover
), meaning that every syntax highlighted line gets an underline (or other special treatment)The text was updated successfully, but these errors were encountered: