#17942·misskey

Detect HTML code blocks with syntax highlighting and convert them to MFM

Author: fghrshCreated Sep 12, 2026Updated Sep 14, 2026
Labels✨Feature🖍MFM🌌Federation

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:

xml
<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

  1. Publish a note from another ActivityPub server with the following HTML in its content field:

    xml
    <pre><code class="language-javascript">console.log(1);</code></pre>
  2. Ensure the note does not provide _misskey_content or a source with mediaType: "text/x.misskeymarkdown", so Misskey uses HTML-to-MFM conversion.

  3. Receive or fetch the note on Misskey.

  4. Observe that the <code> markup appears literally and the content is not rendered as a code block.

  5. Repeat with the class attribute removed and compare the result.

Frontend Environment

markdown
* Server URL: wxw.cat

Backend Environment (for server admin)

markdown
* Misskey: 2026.7.0

Do you want to address this bug yourself?

  • Yes, I will patch the bug myself and send a pull request