On 03/13/2015 11:19 AM, Andrea Rendine wrote:
I came up the idea I am going to write after reading these lines:
/"There is no formal way to indicate the language of computer code being
marked up. //Authors who wish to mark code elements with the language
used, e.g. so that syntax highlighting scripts can use the right rules,
can use the class attribute, e.g. by adding a class prefixed with
"language-" to the element.
(http://www.w3.org/html/wg/drafts/html/master/semantics.html#the-code-element)"/
I don't think this is the best way to recognize code snippets. @class
attribute is not meant to convey any semantic meaning.
I can't speak as to what is the best way to do it, but I currently use
data-code to indicate which programming language.
I use it with the code tag and with the pre tag.
I gather I'm not suppose to put code snippets in a pre tag in HTML5, but
I use PHP DOMDocument and it screws up the formatting on output if I use
the code tag for a block of code with intentional line breaks and white
space, but DOMDocument understands to leave white space etc. alone in
pre. I think part of the problem is HTML5 is a lazy spec without an
actual specified DTD that can instruct tools on things like that.
Anyway right now I apply syntax highlighting server side based on my
custom data-code tag but I agree there should be a formal way to do it,
both for the translation issue mentioned and for client side syntax
highlighting.
With respect to translating a web page, I would think anything in a code
tag should be ignored by language translation and would consider it a
bug if it didn't.
But I would be in favor of a new specific attribute that could be used
with the code tag to indicate what programming language the code snippet
contains.
I would prefer not to re-purpose the lang attribute for this.