Convert a CSS selector to HTML A CSS selector is made up of five elements: 


The element type (tag name)
The id of the element
The classes of the element
The attributes of the element
Operators to chain these element selectors


This challenge will only involve the first four--also taking into account operators would make more than one element be generated and that's a bit too complex for this challenge. Maybe a future one. ;)

Input: A CSS selector, not including any operators. The element type will always be present, but the rest of the portions may not be.

Output: An html element representing the selector.

Examples:

In: div
Out: &lt;div&gt;&lt;/div&gt;

In: div[with-data="cool-data"][foo]
Out: &lt;div with-data="cool-data" foo&gt;&lt;/div&gt;

In: span.nice.tidy.cool
Out: &lt;span class="nice tidy cool"&gt;&lt;/span&gt;

In: button#great-button.fancy[data-effect="greatness"]
Out: &lt;button id="great-button" class="fancy" data-effect="greatness"&gt;&lt;/button&gt;

In: custom-element#secret[secret-attribute="secret value!!"]
Out: &lt;custom-element id="secret" secret-attribute="secret value!!"&gt;&lt;/custom-element&gt;

In: element#id.class1.class2[attribute1][foo="bar"]
Out: &lt;element id="id" class="class1 class2" attribute1 foo="bar"&gt;&lt;/element&gt;



You may assume that the input selector will always have the different parts in order (element type, id, class, attributes).  
You may assume that the provided attribute selectors will never be an attribute text search (^=, $=, *=).
You may assume that the input word characters (element type, attribute names, class names, ids) will always match the regex [a-z0-9_-]
You may have extra whitespace anywhere except for inside strings (attribute values)


This is code-golf, so the shortest answer (in bytes) wins. Standard loop-holes apply.
PHP, 125 119 bytes
&lt;?=preg_replace(['/#([\w-]+)/','/\.([^[]+)/','/[.[\]]/','/(\S+).*/'],[' id=&quot;$1&quot;',' class=&quot;$1&quot;',' ','&lt;$1&gt;&lt;/$1&gt;'],$argn);

Just regex replacements.

Saved 6 bytes thanks to Christoph.