Skip to content

Unexpected code block rendering when pasting raw HTML without backticks #931

@YutoOgiso

Description

@YutoOgiso

Initial checklist

Affected package

[email protected]

Steps to reproduce

Steps to reproduce

When passing raw HTML (not wrapped in a code block) to React Markdown without any properties set, part of it is incorrectly rendered as a code block.

Please open the v0 app.

v0 app to reproduce the behavior of react-markdown

https://v0.app/chat/markdown-preview-app-dOrDi7YXj29?ref=6BRKSK

input text

Do not include triple backticks when pasting

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>サンプルページ</title>
  <style>
    body {
      font-family: Arial, Helvetica, sans-serif;
      line-height: 1.6;
      margin: 0;
      padding: 0 16px;
      background-color: #f9f9f9;
      color: #333;
    }
    header {
      background-color: #4a90e2;
      color: white;
      padding: 24px 0;
      text-align: center;
      margin-bottom: 16px;
    }
    nav {
      margin: 16px 0;
      display: flex;
      gap: 12px;
    }
    nav a {
      text-decoration: none;
      color: #333;
      padding: 8px 12px;
      border-radius: 4px;
      background: #fff;
      border: 1px solid #ddd;
    }
    nav a:hover {
      background: #f0f0f0;
    }
    main {
      max-width: 800px;
      margin: 0 auto;
      background: #fff;
      padding: 20px;
      border-radius: 6px;
      box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }
    footer {
      text-align: center;
      color: #777;
      padding: 20px 0;
      margin-top: 20px;
    }
    .hero {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 20px;
      align-items: center;
    }
    .hero img {
      max-width: 100%;
      border-radius: 6px;
    }
    @media (max-width: 700px) {
      .hero {
        grid-template-columns: 1fr;
      }
    }
  </style>
</head>
<body>
  <header>
    <h1>ようこそ、サンプル HTML ページへ</h1>
    <p>このページは基本的な HTML の構造を示すだけのサンプルです。</p>
  </header>

  <nav aria-label="ナビゲーション">
    <a href="#section1">セクション1</a>
    <a href="#section2">セクション2</a>
    <a href="#section3">セクション3</a>
  </nav>

  <main>
    <section id="section1" class="hero">
      <div>
        <h2>セクション1</h2>
        <p>これはサンプルの段落です。HTML の要素を組み合わせてページを作成します。</p>
        <ul>
          <li>リスト項目1</li>
          <li>リスト項目2</li>
          <li>リスト項目3</li>
        </ul>
      </div>
      <div>
        <img src="https://via.placeholder.com/350x200" alt="ダミー画像" />
      </div>
    </section>

    <section id="section2">
      <h2>セクション2</h2>
      <p>リンクの例:</p>
      <p>
        ダミーリンク: <a href="https://example.com" target="_blank" rel="noopener">https://example.com</a>
      </p>
      <p>テーブルは後で追加することもできます。</p>
    </section>

    <section id="section3">
      <h2>セクション3</h2>
      <p>フォームの例は以下のようになります。実際には送信は行いません。</p>

      <form action="#" method="post" aria-label="サンプルフォーム">
        <label for="name">名前:</label><br />
        <input type="text" id="name" name="name" placeholder="例: 太郎" /><br /><br />
        
        <label for="email">メールアドレス:</label><br />
        <input type="email" id="email" name="email" placeholder="[email protected]" /><br /><br />
        
        <input type="submit" value="送信" />
      </form>
    </section>
  </main>

  <footer>
    <p>&copy; 2025 サンプルサイト</p>
  </footer>
</body>
</html>

Actual behavior

HTML that is not wrapped in a code block is not displayed as-is.

Expected behavior

HTML that is not wrapped in a code block should be output as-is, without being converted into a code block.

Runtime

[email protected]

Package manager

[email protected]

Operating system

macOS

Build and bundle tools

Next.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    👎 phase/noPost cannot or will not be acted on🙋 no/questionThis does not need any changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions