def insert_or_append(parent, node, next_sibling):
    """
    Insert the node before next_sibling, at the specified character index. If
    next_sibling is None, append the node last instead. If the insert split a
    text node, return the previous and next siblings of the newly inserted
    node.
    """
    if next_sibling:
        parent.insertBefore(node, next_sibling)
    else:
        parent.appendChild(node)
