baleezo / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

Add line numbers as DOM attribute #163

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I had a need to include just the line numbers as a DOM attribute, so made a 
small tweak to the prettify.js file.

Insert before line 1040, where the LI is added:
li.setAttribute('data-lineNum', i);

This will change the output from:
<li class="L2">[wrapped content]</li>

To:
<li class="L2" data-linenum="2">[wrapped content]</li>

Not sure if this is the proper place to post this, but thought I'd share.

Original issue reported on code.google.com by mattcr...@gmail.com on 18 Jul 2011 at 7:55

GoogleCodeExporter commented 8 years ago
Thanks.  Since prettify is supposed to be embeddable, I don't think there's any 
way I could add that to the trunk version without violating the HTML 5 mandate

> These attributes are not intended for use by software that is independent of 
the site that uses the attributes.

from 
http://www.w3.org/TR/html5/elements.html#embedding-custom-non-visible-data-with-
the-data-attributes

Original comment by mikesamuel@gmail.com on 19 Jul 2011 at 3:59

GoogleCodeExporter commented 8 years ago
Interesting. I wasn't aware of that section. Thanks for the explanation and 
link.

That being said, how is putting the line number as a data attribute different 
than putting L0 - L9 as a class? I realize the class has nothing to do with the 
HTML5 mandate (data-* attributes specifically), but still. Just curious.

Thanks again.

Original comment by mattcr...@gmail.com on 20 Jul 2011 at 8:43

GoogleCodeExporter commented 8 years ago
There is no explicit prohibition in the HTML 5 spec that specifies how software 
independent of the site may specify classes.  Instead, the HTML 5 spec actually 
recommends their use for carrying site-independent semantic info : 
http://dev.w3.org/html5/spec-author-view/the-code-element.html says "e.g. so 
that syntax highlighting scripts can use the right rules, may do so by adding a 
class prefixed with "language-" to the element."

There may also be a backwards compatibility issue.
Presumably any software that includes google-code-prettify is already 
comfortable with its use of classes, but adding data-* attributes might break 
sites that rely on the spec quote above and use data-* for site-dependent info.

Original comment by mikesamuel@gmail.com on 21 Jul 2011 at 8:09