jonnie
jonnie

Reputation: 12680

Auto format an array of strings containing HTML with indentation in PhpStorm/WebStorm

We write our code for our HTML templates in strings. For readability and maintenance we do it as an array of strings e.g.

template: [
     '<div>',
     'some content here',
     '</div>'
].join('');

Is there anyway I can get PhpStorm/WebStorm to recognise this and format accordingly to keep indentation, even if it means I have to write some regex or function to do the formatting.

What happens now is when the editor formats the code it removes indentation which is a real pain.

Also can we get PhpStorm/WebStorm to recognise that you are in an array and when you hit enter in a string instead of getting

'<div>' +
'</div>'

you could get

'<div>',
'</div>'

Upvotes: 1

Views: 483

Answers (1)

Drew Landgrave
Drew Landgrave

Reputation: 1625

Alt+Enter then choose Edit Html Fragment. You can use the autoformatter here and Any changes there will propagate to the string.

Upvotes: 0

Related Questions