Skip to content

Incorrect textContent Output for <pre><code> Blocks #1827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zuisong opened this issue May 28, 2025 · 0 comments
Open

Incorrect textContent Output for <pre><code> Blocks #1827

zuisong opened this issue May 28, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@zuisong
Copy link
Contributor

zuisong commented May 28, 2025

Description

When using happy-dom to parse HTML containing a <pre><code> block, the output of document.body.textContent is duplicated and incorrect. The expected output should match the original content inside the <code> tag, but the actual output contains repeated and misplaced lines.

Steps to Reproduce

  1. Run the following code:

    import { Window } from "happy-dom";
    
    const w = new Window();
    const document = w.document;
    document.body.innerHTML = `<pre v-pre data-lang="svgbob"><code class="lang-svgbob">                  .-,(  ),-.
       ___  _      .-(          )-.
      [___]|=| -->(                )      __________
      /::/ |_|     '-(          ).-' --->[_...__... ]
                      '-.( ).-'
                              \      ____   __
                               '--->|    | |==|
                                    |____| |  |
                                    /::::/ |__|</code></pre>`;
    console.log(document.body.textContent);
  2. Observe the output.

Actual Output

                  .-,(  ),-.
   ___  _      .-(          )-.
  [___]|=|                   .-,(  ),-.
   ___  _      .-(          )-.
  [___]|=| -->(                )      __________
  /::/ |_|     '-(          ).-' -(                )      __________
  /::/ |_|     '-(          ).-' --->[_...__... ]
                  '-.( ).-'
                                ____   __
                           '-[_...__... ]
                  '-.( ).-'
                                ____   __
                           '--->|    | |==|
                                |____| |  |
                                /::::/ |__|

Expected Output

                  .-,(  ),-.
   ___  _      .-(          )-.
  [___]|=| -->(                )      __________
  /::/ |_|     '-(          ).-' --->[_...__... ]
                  '-.( ).-'
                          \      ____   __
                           '--->|    | |==|
                                |____| |  |
                                /::::/ |__|

Screenshots

Image

Environment

  • happy-dom version: 17.5.6
  • Node.js version: 23.11.0
  • OS: macOS
@zuisong zuisong added the bug Something isn't working label May 28, 2025
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

No branches or pull requests

1 participant