Skip to content

Code syntax highlighting javascript (code-prettify) is executed twice #18010

@stoyanK7

Description

@stoyanK7

From #17887 (comment)

Context

Currently, the website uses JavaScript to provide syntax highlighting. This is done via the code-prettify library. The highlighting is provided on runtime (when you open the page in the browser.

The prettifier comes from the Apache Maven Fludio Skin plugin that we use. You can see it in the plugin's GitHub repository here - src/main/resources/js/prettify.js

Problem

The prettifier is executed twice:

  1. Once in the Maven Fluido Skin src/main/resources/fluido.js script
  2. And then again by this line in checkstyle.js

Proof that the execution happens twice

You can actually see that on the website (for example at https://checkstyle.org/writingjavadocchecks.html). If you inspect one of the code blocks, you will see that for each token, there is a <span> within a <span>:

<code class="language-java">
  <span class="pln">
    <span class="pln">
      java
    </span>
  </span>
  ...
</code>

But if we remove prettyPrint(); from checkstyle.js, then we get:

<code class="language-java">
  <span class="pln">java</span>
  ...
</code>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions