Detect HTML code blocks with syntax highlighting and convert them to MFM
Summary
Federated HTML code blocks are rendered as literal HTML when the inner <code> element has attributes, such as class="language-javascript".
The HTML-to-MFM conversion recognizes an attribute-free <code> wrapper but fails when attributes are present. This breaks code block formatting and prevents the language information from reaching syntax highlighting.
Expected Behavior
- Convert
<pre><code>into a code block regardless of unrelated attributes. - Preserve the code content, indentation, and line breaks.
- Recognize
language-*classes and retain the language identifier for the existing syntax highlighter. - Ignore unrelated classes without affecting code block rendering.
Actual Behavior
Given this HTML:
<pre><code class="language-javascript">console.log(1);</code></pre>The conversion produces literal text instead of a fenced code block:
<code class="language-javascript">console.log(1);</code>Removing the class attribute allows the same content to become a code block. Other attributes, such as title, also trigger the problem.
Steps to Reproduce
Publish a note from another ActivityPub server with the following HTML in its
contentfield:<pre><code class="language-javascript">console.log(1);</code></pre>Ensure the note does not provide
_misskey_contentor asourcewithmediaType: "text/x.misskeymarkdown", so Misskey uses HTML-to-MFM conversion.Receive or fetch the note on Misskey.
Observe that the
<code>markup appears literally and the content is not rendered as a code block.Repeat with the
classattribute removed and compare the result.
Frontend Environment
* Server URL: wxw.catBackend Environment (for server admin)
* Misskey: 2026.7.0Do you want to address this bug yourself?
- Yes, I will patch the bug myself and send a pull request
Source: misskey-dev/misskey