-
-
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
Non-unique HTML id
attribute values in source-line references of code-blocks
#4031
Comments
I'd like to get thoughts on this from @dbaynard, who added these features in If href's are not allowed on the divs, then probably we shouldn't have them. But I think the intent was to allow you to click on a line and then copy a link to it from the top bar of the browser. Since skylighting is independent of pandoc, we'd have to figure out how to get the unique identifiers in there. |
Not only are they not allowed,
Looking into the referenced pull, I see this:
I think the idea was to replace the wrapping <div class="sourceLine" id="1" data-line-number="1">
<!-- some code -->
</div> Would become this: <a class="sourceLine" id="1" href="#1" data-line-number="1">
<!-- some code -->
</a> In that case, having an |
This is needed because a web page may contain several code samples, and we need to make sure that the ids on lines are unique. See jgm/pandoc#4031.
The "clicking the line number, and only the line number" is because links for the full line were disabled in css. From the code, I believe the multiple Would it be possible to use the |
Also the changes seem reasonable. Please excuse the oversight. |
@jgm - Thanks for the fix. I tested it using the nightly builds. I just wanted to point out that the I would suggest adding the prefix only to the <div class="sourceLine" id="cb3-1" data-line-number="1">
<!-- some code -->
</div> Thanks! |
Pandoc's new
sourceLine
references in code-blocks (since 2.0) are using repeating HTMLid
attributes, which makes referencing some source-lines in a page that contains multiple code-blocks impossible (and it's also invalid HTML).The problem
Exmaple input:
Output:
In this case, and if the code is hosted on
http://thepage.com/
, visitinghttp://thepage.com/#1
link will always reference the first line of the first block, and never the first line of the second block.Another problem with this format is that IDs starting with a non-alphabet character (
[a-zA-Z]
) are not valid prior to HTML 5, and may not work on older browsers/renderers with no HTML 5 support. (I mention this since I see Pandoc having bothhtml
andhtml5
output formats).Another point: Is there a reason there are
href
properties insourceLine
s? Because it has no effect here, and referencing source lines will work withid
s alone, and withouthref
s (and it's also invalid HTML to havehref
s indiv
s).Suggested solution
As a solution, I suggest prepending a block number to the ID (as in
id="block1-line1"
,id="block2-line1"
), which will also make the IDs more unique and understandable, and solves the problem of HTML 5 compatibility.Format ideas:
block1-line1
b1-l1
(less understandable)line1-1
(as inline<block>-<line>
)code-1.1
I would also suggest removing the
href
attributes fromsourceLine
s.Expected output (issue-irrelevant lines trimmed):
More info
All this was tested using Pandoc 2.0.1 in a Windows 10 machine.
Sorry if this should go in jgm/skylighting. I thought about reporting this issue there, but thought maybe it's more relevant here since this is a document-level issue, not code-block-level issue. I hope I'm not wrong.
Thanks!
The text was updated successfully, but these errors were encountered: