Skip to content
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

Multiple newlines added between empty textarea and "unformatted" inline elements #1534

Closed
amandabot opened this issue Sep 4, 2018 · 4 comments

Comments

@amandabot
Copy link

Description

If an inline tag is included in the unformatted settings, newlines are added between empty tags. textarea elements are affected by this regardless of presence in the unformatted array. The newlines double each time as well.

As a work-around, if there is text, comments, or no space between the tags, this does not happen.

Input

The code looked like this before beautification:

<textarea></textarea>
<textarea>
</textarea>

<strong></strong>
<strong>
</strong>

<span></span>
<span>
</span>

Expected Output

The code should have looked like this after beautification:

<textarea></textarea>
<textarea>
</textarea>

<strong></strong>
<strong>
</strong>

<span></span>
<span>
</span>

Actual Output

The code actually looked like this after beautification:
Example without unformatted section in settings:

<textarea></textarea>
<textarea>

</textarea>

<strong></strong>
<strong>
</strong>

<span></span>
<span>
</span>

Example with unformatted section in settings:

<textarea></textarea>
<textarea>

</textarea>

<strong></strong>
<strong>

</strong>

<span></span>
<span>

</span>

Steps to Reproduce

Tested on JS Beautify site

Environment

OS: windows

Settings

Example without unformatted:

{
  "indent_size": "4",
  "indent_char": " ",
  "max_preserve_newlines": "5",
  "preserve_newlines": true,
  "keep_array_indentation": false,
  "break_chained_methods": false,
  "indent_scripts": "normal",
  "brace_style": "collapse",
  "space_before_conditional": true,
  "unescape_strings": false,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "0",
  "indent_inner_html": false,
  "comma_first": false,
  "e4x": false
}

Example with unformatted:

{
  "indent_size": "4",
  "indent_char": " ",
  "max_preserve_newlines": "5",
  "preserve_newlines": true,
  "keep_array_indentation": false,
  "break_chained_methods": false,
  "indent_scripts": "normal",
  "brace_style": "collapse",
  "space_before_conditional": true,
  "unescape_strings": false,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "0",
  "indent_inner_html": false,
  "comma_first": false,
  "e4x": false,
  "unformatted": [
    "strong",
    "textarea",
    "span"
  ]
}
@bitwiseman
Copy link
Member

bitwiseman commented Sep 4, 2018

@AmandaFoster
What about if the inline tag is not included in the unformatted list?

textarea tags are included in the content_unformatted list. So, the interaction seems to be with unformatted and either of the other two lists.

This is an issue because editors that provide unformatted are common, but many do not provide inline yet. So, this will appear in all of those.

Implementation note:
One solution would be to only let elements be in one of these three lists - either by silently removing the other lists internally, logging a warning when this happens, or by throwing an exception and simply refusing to beautify when these settings conflict. The first or second are preferable options.

@amandabot
Copy link
Author

amandabot commented Sep 5, 2018

The particular use-case I ran into was with textarea in an Angular application, but I think it's applicable to any textarea regardless of context as it doesn't require anything between the tags. I knew it was in that unformatted list and figured they might be connected.

I see what you mean now about the inline, unformatted, and content_unformatted. Is there overlap between inline and unformatted and how they are applied? Also, what priority does each list have in terms of how the element is formatted?

I think a warning would make sense if an element in one list would be overridden by its presence in another, especially if it would be removed internally. The last option might be drastic, but it may be more likely to catch your attention than a logged warning or trying to figure out why the code formatted a certain way.

@bitwiseman
Copy link
Member

@AmandaFoster Thanks, I went ahead and fixed this bug without doing filtering. An element can be in all three lists without unexpected side effect now.

Note: in the default settings, all elements that were unformatted in 1.7.5 have moved to inline or content_unformatted in 1.8.0 - unformatted was used to mitigate the lack of proper inline behavior. I would strongly suggest making your unformatted list empty and see how that looks.

Thanks again for reporting this issue!

@amandabot
Copy link
Author

Will do. Thanks for the quick turn around.

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

No branches or pull requests

2 participants