Skip to content

Improve space normalization when pretty-printing #1798

Closed

Description

@jhy

When pretty-printing, newlines and trailing spaces could be better handled.

Two cases as examples:

<div>
·Text
</div>

(with · representing a space), is currently emitted as:

<div>
··Text·
</div>

As the textnode value is "·Text\n", and then when pre-printing, that gets indented (now two leading spaces but should only be one if the indent level is set to one); and then the trailing newline gets normalized to a space.

Similarly,

<div>
 <p>One
 <p>Two
</div>

Gets emitted as

<div>
 <p>One·</p>
 <p>Two·</p>
</div>

As the trailing newline in the textnode is normalized to a space, when it could actually be trimmed (as it is the last text in a block tag and therefore not important whitespace for text flow).

This would fix the underlying issue found in #1663.

Activity

  1. added this to the 1.15.2 milestone on Jun 24, 2022
  2. self-assigned this
    on Jun 24, 2022
  3. added
    improvement
    on Jun 24, 2022
  4. added a commit that references this issue on May 27, 2024
    fc41ec9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

improvement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions