def insert_tag(tag, before, root):
if not before:<EOL><INDENT>root.childs.append(tag)<EOL>tag.parent = root<EOL>return<EOL><DEDENT>if type(before) in [tuple, list]:<EOL><INDENT>before = first(before)<EOL><DEDENT>if not hasattr(before, "<STR_LIT>"):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>parent = before.parent<EOL>parent.childs.insert(<EOL>parent.childs.index(before),<EOL>tag<EOL>)<EOL>tag.parent = parent<EOL>
Insert `tag` before `before` tag if present. If not, insert it into `root`.

Args:
    tag (obj): HTMLElement instance.
    before (obj): HTMLElement instance.
    root (obj): HTMLElement instance.