6

I would like to find a way to format HTML in VScode, such as fro example, if I have a long div like this one:

<div class="signal-item-icon checkbox-signal signal-icon" [class.selected]="signal.isSelectedCheckSign" (click)="$event.stopPropagation(); onSelectOneShadowSignal(signal);">

I want it to be displayed like this when I do ctrl+shift+i:

<div class="signal-item-icon checkbox-signal signal-icon" 
     [class.selected]="signal.isSelectedCheckSign" 
     (click)="$event.stopPropagation(); 
     onSelectOneShadowSignal(signal);">

Do you if it is possible? Is there an extension VScode that exists for this kind of implementation?

Thank you !

3 Answers 3

5

You can also use it with combination of html.format.wrapLineLength.

"html.format.wrapLineLength": 80,
"html.format.wrapAttributes": "auto",

In this case, attributes starts wrapping when line length exceeds 80. It's useful when you have many attributes and it will fill the empty spaces on the right.

Sign up to request clarification or add additional context in comments.

Comments

4

Setting the VSCode preference html.format.wrapAttributes to force will accomplish the formatting from your example.

Comments

1

I think a better solution would be to use the VSCode html.format.wrapAttributes option of force-aligned. This doesn't blur the line between the next nested object and your attributes of your parent. (In most cases).

force

<form attribute1="value" 
  attribute2="othervalue">
  <div></div>
</form>

force-aligned

<form attribute1="value" 
      attribute2="othervalue">
  <div></div>
</form>

In my opinion, the first option makes it harder to find the div inside the form. And I've seen it cause many developers headaches when this happens.

<form attribute1="value">
  attribute2="othervalue"
  <div></div>
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.