Skip to content

Improve text content formatting in experimental formatter #1331

@JessicaJHee

Description

@JessicaJHee

Currently the experimental formatter will normalize the space before and after the entire text content by default. Here is the current behavior:
Before formatting:

<a>
  Content
  <b>
    Content2
    Content3
  </b>
</a>

After formatting:

<a> Content <b> Content2
    Content3
  </b>
</a>

For reference, in IJ, if there is an line break in the text, the text will be indented. If there is no line break, it will remove the spaces between the text and element tag.
Before formatting:

<a>         Content       test
    <b>
        Content2
                   Content3
    </b>
</a>

After formatting:

<a>Content test
    <b>
        Content2
        Content3
    </b>
</a>

There is an option in IJ to keep line breaks in text (true by default), when this is set to false, the content lines are joined. (note that it will not snap the text content to the same line as the 'b' tag if there is a line break present)
After formatting with keep line breaks in text set to false:

<a>Content
    <b>
        Content2 Content3
    </b>
</a>

Referencing the way it works IJ, my suggestions are to:

  1. mimic how the text content formatting is done by default in the same way as IJ where it will respect any existing line breaks and indent the text if needed. It will also normalize the spaces between text in the same line.
  2. keep the joinContentLines setting but change it so that it will keep the new line between the element tag and text if there exists one.

Metadata

Metadata

Assignees

Labels

formattingThis issue or enhancement is related to formatting support

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions