Integrated: 8299080: Wrong default value of snippet lang attribute
Pavel Rappo
prappo at openjdk.org
Wed Jul 17 12:22:56 UTC 2024
On Mon, 1 Jul 2024 13:33:28 GMT, Pavel Rappo <prappo at openjdk.org> wrote:
> Please review this bugfix to the way the language of a snippet is determined and processed.
>
> The language of a snippet affects the form of snippet markup and enables external syntax highlighting, such as that provided by prism.js. The language of a snippet is [determined](https://docs.oracle.com/en/java/javase/22/docs/specs/javadoc/doc-comment-spec.html#snippet) as follows:
>
>> A snippet may specify a `lang` attribute, which identifies the kind of content in the snippet. For an inline snippet, the default value is `java`. For an external snippet, the default value is derived from the extension of the name of the file containing the snippet's content.
>
> There are two issues that this PR fixes. The first issue is a specification issue. The spec says nothing about the language of a hybrid snippet, which has features of both an inline and external snippets. It makes sense to specify that in the absence of the `lang` attribute, the language of a hybrid snippet is derived from the file extension. Put differently, when determining the language, a hybrid snippet behaves like an external snippet, not like an inline snippet.
>
> The second issue is an implementation issue. If the `lang` attribute or the file extension is `java` or `properties`, then the form of markup corresponds to that language and the HTML construct modelling the snippet is attributed with `class=language-java` or `class=language-properties` respectively. This is expected. However, if the `lang` attribute or the file extension is neither of those, or the `lang` attribute is default, then the form of markup is assumed to be that of `java`, but the HTML construct modelling the snippet is not attributed, which means that the language is not passed through to the 3rd party syntax highlighters.
>
> Stepping out of this PR for a moment, there is clearly a conflation between the language of a snippet and the form of snippet markup. Those are linked and controlled by a single knob. That and the design whereby every snippet in an unsupported language can use markup for the Java language was purposeful: it was considered simple and practical.
>
> This PR proposes that the language of a snippet is determined and processed as follows:
>
> 1. If the `lang` attribute is present, then its value is the language; if that value is empty, then the language is undefined
> 2. Otherwise,
> 1. If the snippet is inline, then the language is `java`
> 2. Otherwise (i.e. the snippet is external or hybrid), the language is determined as...
This pull request has now been integrated.
Changeset: 6df7acbc
Author: Pavel Rappo <prappo at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/6df7acbc74922d297852044596045a8b32636423
Stats: 202 lines in 6 files changed: 132 ins; 28 del; 42 mod
8299080: Wrong default value of snippet lang attribute
Reviewed-by: jjg
-------------
PR: https://git.openjdk.org/jdk/pull/19971
More information about the javadoc-dev
mailing list