Skip to content

HTML Minifier collapses meaningful whitespace inside <pre> and <textarea> #355

Description

@baixiangcpp

Summary

HTML Minifier removes meaningful whitespace inside elements whose text content is whitespace-sensitive. This changes the rendered/content value instead of only removing formatting between tags.

Reproduction

  1. Open https://byteflow.tools/en/html-minifier.
  2. Paste:
<pre>  a   b
  c  </pre>
<textarea> x  y </textarea>
<div>  spaced text  </div>
  1. Click Minify.

Actual output

<pre> a b c </pre><textarea> x y </textarea><div> spaced text </div>

The two spaces, repeated spaces, and newline inside <pre> are lost. The repeated space inside <textarea> is also lost.

Expected output

Whitespace inside <pre> and <textarea> should be preserved, while whitespace between tags may be minified. For example:

<pre>  a   b
  c  </pre><textarea> x  y </textarea><div> spaced text </div>

Impact

Minifying markup containing code samples, preformatted text, or user-editable textarea content changes the content semantics and can corrupt the displayed or submitted value. The page documentation also says to preserve semantics in <pre>, <code>, and inline text.

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions