简体   繁体   中英

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 eg

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>'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM