Re: [whatwg] Using @type on code to specify the computer language

2015-05-16 Thread Nils Dagsson Moskopp
Taylor Hunt taylorcharlesh...@gmail.com writes:

 Hello,

 I was wondering about the best way of indicating a code element's
 contained computer language for syntax highlighting. The
 specifications are quite clear that using @lang for that is abuse, so
 many existing implementations use a data-lang attribute, class name,
 or something similar.

 I was curious if repurposing the type attribute onto code elements
 for this purpose would be a good idea. The script and style
 elements already use it to indicate what language they contain, so
 there would seem to be precedent. (An argument against this would be
 input already overloading type's meaning, but that ship may have
 sailed.) Including non-standard languages within these tags with a
 differentiating value for type is widely-practiced, such as for HTML
 templating, or more exotic implementations like in-browser
 interpreters or thegrid.io's use of style type=text/gss.

 Using code[type] would have the advantage of an existing vocabulary
 for unambiguously indicating a code language, through MIME types. It
 also works today, and should have no problems in older browsers.

This proposal would also have the benefit of making it possible to
automate generation of the type attribute contents using file(1) or
magic(5), which makes it easy to annotate code elements automagically.

 The most obvious benefit would be syntax highlighting, but there could
 be other use-cases: more intelligent enunciation by speech
 synthesizers, for example.

It would also make it easier to search for source code examples in a
specific language among a large corpus of content. I would love this!

-- 
Nils Dagsson Moskopp // erlehmann
http://dieweltistgarnichtso.net


Re: [whatwg] Using @type on code to specify the computer language

2015-05-09 Thread Andrea Rendine
Long ago I proposed an attribute for code language because I was
unhappy with all the class=language-whatever thing. I proposed @lang
because I thought there could be an issue with speech synthesis and
languages, but it was effectively pointed out that such attribute does
not fit this case.

+1 for @type, it is widely consistent to use that for MIME types. But
I guess that it will bring nowhere (as usual) unless vendors show any
interest for this issue.


Re: [whatwg] Using @type on code to specify the computer language

2015-05-09 Thread Mathias Bynens
There is a de facto standard here that is already supported by most
syntax highlighting libraries, based on this part of the spec:
https://html.spec.whatwg.org/multipage/semantics.html#the-code-element

“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.”

I’d prefer following that pattern over inventing a new one.


Re: [whatwg] Using @type on code to specify the computer language

2015-05-09 Thread Andrea Rendine
Mathias, mind that while libraries support using the @class attribute,
there's no standard between them about whether to use a prefix before
the language or if a prefix is necessary at all.
Besides, @class has no semantic value. It's true that the spec
suggests using semantic class names (instead of layout-inspired, I
mean), but there's no real meaning for that.

2015-05-09 14:48 GMT+02:00 Mathias Bynens mathi...@opera.com:
 There is a de facto standard here that is already supported by most
 syntax highlighting libraries, based on this part of the spec:
 https://html.spec.whatwg.org/multipage/semantics.html#the-code-element

 “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.”

 I’d prefer following that pattern over inventing a new one.