Class PreLanguageRewriter
java.lang.Object
org.codehaus.groovy.tools.groovydoc.PreLanguageRewriter
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.
- Since:
- 6.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidrewriteDirectory(File dir, String preLanguage) Walksdirrecursively and appliesrewriteTags(java.lang.String, java.lang.String)to every.htmlfile in place.static StringrewriteTags(String html, String preLanguage) Returnshtmlwith<pre>blocks rewritten so Prism can highlight them.
-
Method Details
-
rewriteTags
Returnshtmlwith<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, or with a class that doesn't mentionlanguage-*— are left untouched.
preLanguageisnullor empty. - Bare
-
rewriteDirectory
Walksdirrecursively and appliesrewriteTags(java.lang.String, java.lang.String)to every.htmlfile in place. A no-op whenpreLanguageisnullor empty.
-