def create_element(type, props=None, *children):
    """ Convenience function to create a dictionary to represent
    a virtual DOM node. Intended for use inside ``Widget._render_dom()``.

    The content of the widget may be given as a series/list of child nodes
    (virtual or real), and strings. Strings are converted to text nodes. To
    insert raw HTML, use the ``innerHTML`` prop, but be careful not to
    include user-defined text, as this may introduce openings for XSS attacks.

    The returned dictionary has three fields: type, props, children.
    """
    if len(children) == 0:
        children = None  # i.e. don't touch children
    elif len(children) == 1 and isinstance(children[0], list):
        children = children[0]

    return dict(type=type,
                props=props or {},
                children=children,
                )