Convert Single Line HTML tags to Multiline?


#1

The goal is to be able to select a single line HTML tag like:

<input type="email" id="email" name="email" data-blah="some data">

hit a key-combo and have it converted to

<input 
	type="email"
	id="email"
	name="email"
	data-blah="some data"
>

I experimented with my rudimentary regex skills and searched for an existing package but no joy.

Simply replacing " " with \n is actually pretty close to what I’m after (the closing > on its own line is a nice to have) but the main problem is it doesn’t preserve existing indentation – if the selected tag starts at the third tab stop, the new lines would ideally start at the fourth tab stop.

Can anyone point me toward a package or some regex that would help achieve this?


#2

Install the beautify package (Atom Beautify), select your code, then click Beautify.