HTML5 Code - Language Class

The HTML5 <code> element has an optional attribute class = "language-" to determine the language of the code snippet. Example from specification:

 <pre><code class="language-pascal">var i: Integer; begin i := 1; end.</code></pre> 

Is there a list of languages ​​to be used? Just thinking that otherwise, there will probably be many different spellings or interpretations of languages, for example. VB6 vs visual basic 6 etc.

+6
source share
1 answer

In the WHATWGs HTML Living Standard specification, the specification actually recommends prefixing the value of class attributes on <code> elements with " language-* ":

From HTML Living Standard: Text-Level Semantics - Code Element

There is no formal way to indicate a language denoted by computer code. Authors who want to mark code elements with the language used, for example. so that syntax highlighting scripts can use the correct rules, they can use a class attribute, for example. adding a class with the prefix "language-" to the element.

(However, I would suggest that this prefix does not have real practical value - this will depend on whether real-world sites accept the agreement and whether third-party tools detect and actually implement this prefix.)

+3
source

Source: https://habr.com/ru/post/905448/


All Articles