Skip to content

Improve space normalization when pretty-printing #1798

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

improvementAn improvement / new feature idea

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions