Skip to content

Document how Markdown code blocks reach the Sink - #1076

Merged
slachiewicz merged 1 commit into
apache:masterfrom
slachiewicz:markdown-code-block-docs
Aug 8, 2026
Merged

slachiewicz merged 1 commit into
apache:masterfrom
slachiewicz:markdown-code-block-docs

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

Part of #876 (DOXIA-762), which asks for the Markdown side of code highlighting to be written down somewhere. The module page currently says nothing about code blocks at all.

Two things here.

The module page gains a "Code blocks" section. Verified against the current parser rather than inferred:

Markdown inline event class rendered
```java language-java <pre><code class="language-java">
``` with no info string nohighlight nocode <pre><code class="nohighlight nocode">
indented block nohighlight nocode <pre><code class="nohighlight nocode">

The first row is asserted by fencedCodeBlockSinkEvent in the module's own tests. I confirmed the indented case by dumping the events for code.md, since only the fenced case was covered. The two odd class names come from FENCED_CODE_NO_LANGUAGE_CLASS and are the opt-out markers for highlight.js and code-prettify, which is worth stating since they look arbitrary otherwise.

The MarkdownHtmlParser javadoc is corrected. It currently says:

PRE elements need to be "source" because the Xhtml5Sink will surround the corresponding verbatim() Sink event with a DIV element with class="source", which is how most Maven Skin (incl. Fluido) recognize a block of code

That is no longer what happens, and the module's own test comment says as much: "instead of using a decoration tag on the verbatim event an additional inline event is used". The verbatim event carries no attributes; the nested inline event carries the semantics and the language. Leaving the old description in place is worse than having none, since it points at a mechanism that is not there.

The replacement also records why Markdown differs from APT and XDoc, where +-- and <source> put the source decoration on the verbatim event: Markdown has a language to convey as well, and the inline event already carries it, so the decoration would add nothing.

On its own this does not cover all of #876. The APT half is apache/maven-doxia-site#70, and whether the four parsers should converge on one representation is a separate question I have deliberately not touched here.

The module page said nothing about code blocks, and the parser javadoc
described an approach the code no longer takes: it claimed PRE elements
are marked as "source" so the sink wraps them in a div the skins
recognise. They are not. A code block emits a plain verbatim event with
an inline event inside it carrying the code semantics and, for a fenced
block, the language as a class.

That is a deliberate difference from the APT and XDoc modules, which put
the source decoration on the verbatim event itself, so say what Markdown
does instead, and why, in both places.
@slachiewicz slachiewicz added the documentation Improvements or additions to documentation label Aug 8, 2026
@slachiewicz
slachiewicz merged commit d39dc2b into apache:master Aug 8, 2026
11 checks passed
@github-actions github-actions Bot added this to the 2.1.1 milestone Aug 8, 2026
@slachiewicz
slachiewicz deleted the markdown-code-block-docs branch September 7, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant