W3C home > Mailing lists > Public > public-html-comments@w3.org > March 2015

Re: <code> element and scripting languages

From: Michael A. Peters <mpeters@domblogger.net>
Date: Fri, 13 Mar 2015 17:43:43 -0700
Message-ID: <5503843F.5000203@domblogger.net>
To: public-html-comments@w3.org

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 

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 

I would prefer not to re-purpose the lang attribute for this.
Received on Saturday, 14 March 2015 00:44:09 UTC

This archive was generated by hypermail 2.3.1 : Saturday, 14 March 2015 00:44:10 UTC