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}) only receives the class on its opening
tag, to avoid nested <code><code>. Any <pre> with an
existing attribute — class, id, or other — is left
untouched.
| 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. |
Walks dir recursively and applies rewriteTags to
every .html file in place. A no-op when preLanguage
is null or empty.
Returns html with <pre> blocks rewritten so Prism can
highlight them. Three cases:
<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).<pre> with an existing <code>
descendant, or with a class that doesn't mention
language-* — are left untouched.preLanguage is null or empty.