def create_graph(zettels, graph, include_self_references=True, only_listed=
    False):
    """
    Create of graph of the zettels linking to each other.

    Parameters
    ----------
    zettels : list of dictionaries
    include_self_references : bool, optional
        Include links to the source document. Defaults to True.
    only_listed : bool, optional
        Only include nodes in the graph it's actually one of the zettels.
        Default is False.

    Returns
    -------
    graph : nx.Graph

    """
    zettel_ids = set()
    link_ids = set()
    for zettel in zettels:
        zettel_ids.add(zettel['id'])
        link_ids.update(zettel['links'])
    if only_listed:
        ids_to_include = zettel_ids
    else:
        ids_to_include = zettel_ids | link_ids
    for zettel in zettels:
        graph.add_node(zettel['id'], title=zettel['title'])
        for link in zettel['links']:
            if link not in ids_to_include:
                continue
            if include_self_references or zettel['id'] != link:
                graph.add_edge(zettel['id'], link)
    return graph
