Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8275788

Create code element with suitable attributes for code snippets

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 18
    • None
    • tools
    • b23
    • generic
    • generic

      The HTML5 specification does not contain a normative rule for formatting code snippets but it suggests the usage of `<pre>` elements with nested `<code>` elements and the use of a `class="language-xxx"` attribute on the latter to describe the language of the snippet.

      https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-code-element
      https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element

      This also happens to be the format expected by popular syntax coloring tools such as Prism and highlight.js.

      https://prismjs.com/index.html#basic-usage
      https://highlightjs.org/usage/

      JEP 413 describes a `lang` attribute for snippets that defines the language of the snippet. This attribute is currently ignored. It should be used to create a class attribute as described above.

      In a related note, JEP 413 also describes an `id` attribute to identify the snippet in the generated documentation. This attribute is also currently ignored, it should be used to create an `id` attribute in an element containing the snippet.

            hannesw Hannes Wallnoefer
            hannesw Hannes Wallnoefer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: