Package: org.codehaus.groovy.tools.groovydoc

## [Java] Class PreLanguageRewriter

- org.codehaus.groovy.tools.groovydoc.PreLanguageRewriter

-     public final class PreLanguageRewriter
      extends Object

  Post-process pass that retrofits syntax-highlighting classes onto bare `<pre>` blocks in generated HTML. Used by both the Ant Groovydoc task and the `groovydoc` CLI so their outputs stay identical.

  Bare `<pre>...</pre>` blocks — openings with no attributes at all — are rewritten to `<pre class="language-xxx"><code>...</code></pre>` so Prism's highlighter picks them up (Prism only walks `<code>` descendants of language-classed elements). A `<pre>` whose body already contains a `<code>` element (e.g. the canonical form emitted by `{@snippet}`, or the uppercase `<CODE>` historically emitted by `{@code ...}`) only receives the class on its opening tag, to avoid nested `<code><CODE>` / `<code><code>`. Any `<pre>` with an existing attribute — `class`, `id`, or other — is left untouched.

  Since:
    6.0.0

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static void` | `rewriteDirectory(File dir, String preLanguage)` Walks `dir` recursively and applies rewriteTags to every `.html` file in place.
    `` | `public static String` | `rewriteTags(String html, String preLanguage)` Returns `html` with `<pre>` blocks rewritten so Prism can highlight them.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### public static void rewriteDirectory(File dir, String preLanguage)

      Walks `dir` recursively and applies rewriteTags to every `.html` file in place. A no-op when `preLanguage` is `null` or empty.

    - #### public static String rewriteTags(String html, String preLanguage)

      Returns `html` with `<pre>` blocks rewritten so Prism can highlight them. Three cases:

      - Bare `<pre>body</pre>` with no attributes becomes `<pre class="language-xxx"><code>body</code></pre>`.
      - `<pre class="...language-...">body</pre>` that lacks an inner `<code>` gets its body wrapped in `<code>` (Prism walks `<code>` descendants, so a language-classed `<pre>` without a `<code>` child is skipped by the highlighter).
      - All other cases — `<pre>` with an existing `<code>` descendant (any letter case; GROOVY-12095), or with a class that doesn't mention `language-*` — are left untouched.
      No-op when `preLanguage` is `null` or empty.