Add code-lang attribute to code element #10580
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
What problem are you trying to solve?
In @edent's recent blog post about the
code
element he mentions that there could be a gap in the HTML spec for defining the programming language of code in a code block.For example, I would like to mark up the following code snippet to show that it is Rust code:
The existing lang global attribute is not suitable for this, as it's supposed to be used for human languages, not programming.
What solutions exist today?
According to the current HTML spec
But,
The problem with this is that naming classes with a "language-" prefix is not used by browsers, and as the spec mentions, it's mainly for the benefit of third party styling libraries.
Schema.org has a microdata type for SoftwareSourceCode, but this is overly verbose and again, not used by browsers (or styling libraries).
How would you solve it?
I would propose adding a 'code-lang' attribute to the code element, with this example syntax along similar lines suggested by @edent:
The language codes could be standardised on the pygments language short code list, or another standard coding language identifier? Language version would be specified with a semi colon.
Anything else?
Ideally this (might?) allow browsers to read programming languages in code blocks and add syntax highlighting to the default user agent stylesheet, but I recognise that's a very ambitious outcome for this proposal.
The text was updated successfully, but these errors were encountered: