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

Create code element with suitable attributes for code snippets

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 18
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b23
    • CPU:
      generic
    • OS:
      generic

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: