Skip to content

Close self-closing non-void HTML tags in Markdown parsing - #1087

Merged
slachiewicz merged 1 commit into
masterfrom
xdoc-selfclosing-raw-html
Sep 3, 2026
Merged

slachiewicz merged 1 commit into
masterfrom
xdoc-selfclosing-raw-html

Conversation

@slachiewicz

Copy link
Copy Markdown
Member

Closes self-closing non-void HTML tags (e.g. <object .../>) before Jsoup re-serializes flexmark's raw-HTML passthrough, so they no longer swallow the content that follows as unclosed-tag fallback children.

Fixes #1086

Verified: mvn test on doxia-module-markdown → all green (new test fails without the fix, passes with it).

This change was created with AI assistance.

HTML5 has no self-closing syntax outside void elements, so a raw
<object .../> in a Markdown source was left unclosed, nesting all
following content as its (hidden, fallback-only) children.

Fixes #1086
@slachiewicz slachiewicz added the bug Something isn't working label Aug 24, 2026
@slachiewicz
slachiewicz marked this pull request as ready for review August 24, 2026 11:26
@slachiewicz
slachiewicz requested review from kwin and michael-o August 24, 2026 11:34
@michael-o

Copy link
Copy Markdown
Member

Does this cover the case if the tag spans multiple lines? Which can happen...

@slachiewicz
slachiewicz marked this pull request as draft August 30, 2026 21:22
@slachiewicz
slachiewicz marked this pull request as ready for review September 3, 2026 12:07
@slachiewicz

Copy link
Copy Markdown
Member Author

Yes. Verified by running the pattern rather than reading it:

input result
<object type="image/svg+xml" data="x.svg"/> closed
<object + newline + type="…" + newline + data="x.svg"/> closed
<object data="a + newline + b"/> (newline inside a quoted value) closed
<br/>, and <img + newlines + src="a.png"/> left alone, correctly
<object data="a"/><object data="b"/> both closed

Multi-line works because the pattern contains no ., so DOTALL never comes into it. The
attribute group is built from "[^"]*", '[^']*' and [^"'/>], and in Java all three match a
newline, as does the \s* before />.

Code blocks are safe for a separate reason worth recording: flexmark escapes their content, so
&lt;object/&gt; never matches and a literal example in a fenced block is not rewritten.

Testing it did turn up one case it misses, though — an unquoted attribute value containing a
slash:

<object data=x/y.svg/>   ->   unchanged

/ is excluded from every branch of the attribute group, so the match can never reach the
trailing />. HTML permits unquoted attribute values and flexmark passes raw HTML through
verbatim, so that input still hits the original bug. Narrower than the multi-line case you asked
about, but it is the real hole. Happy to either handle it or record it as a known limitation with
a test — your call which.

This comment was created with AI assistance.

@slachiewicz
slachiewicz merged commit ca7722b into master Sep 3, 2026
24 of 27 checks passed
@slachiewicz
slachiewicz deleted the xdoc-selfclosing-raw-html branch September 3, 2026 16:12
@github-actions github-actions Bot added this to the 2.2.0 milestone Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown parser leaves self-closing non-void HTML tags unclosed, swallowing following content

2 participants