(doc, strip_html=False)
return text
Export doc into a simple text format.

    if complex, go through nodes depth first,
    at each node, output name of node
    if node is leaf, run flatten on it
Export doc into a simple text format.
Export doc into a simple text format .
def make_text(doc, strip_html=False):
    """
    Export doc into a simple text format.

    if complex, go through nodes depth first,
    at each node, output name of node
    if node is leaf, run flatten on it

    """
    # We have a strange beast here - a merged content tree.  Loading it into a synthetic version.
    chapter = doc.get("original_text", doc["text"])
    version = Version({"chapter": chapter})

    index = library.get_index(doc["title"])
    versionSource = doc["versionSource"] or ""
    text = "\n".join([doc["title"], doc.get("heTitle", ""), doc["versionTitle"], versionSource])

    if "versions" in doc:
        if not len(doc["versions"]):
            return None # Occurs when text versions don't actually have content
        text += "\nThis file contains merged sections from the following text versions:"
        for v in doc["versions"]:
            text += "\n-%s\n-%s" % (v[0], v[1])

    def make_node(node, depth, **kwargs):
        if not node.children:
            content = "\n\n%s\n\n" % node.primary_title(doc["language"])
            cnode = version.content_node(node)
            if strip_html:
                cnode = version.remove_html_and_make_presentable(cnode)
            content += flatten(cnode, node.sectionNames)
            return content
        else:
            return "\n\n%s" % node.primary_title(doc["language"])

    def flatten(text, sectionNames):
        text = text or ""
        if len(sectionNames) == 1:
            text = [t if t else "" for t in text]
            # Bandaid for mismatch between text structure, join recursively if text
            # elements are lists instead of strings.
            return "\n".join([t if isinstance(t, str) else "\n".join(t) for t in text])
        flat = ""
        for i in range(len(text)):
            section = section_to_daf(i + 1) if sectionNames[0] == "Daf" else str(i + 1)
            flat += "\n\n%s %s\n\n%s" % (sectionNames[0], section, flatten(text[i], sectionNames[1:]))

        return flat

    text += index.nodes.traverse_to_string(make_node)


    return text
def make_text ( doc , strip_html = False ) : # We have a strange beast here - a merged content tree.  Loading it into a synthetic version. chapter = doc . get ( "original_text" , doc [ "text" ] ) version = Version ( { "chapter" : chapter } ) index = library . get_index ( doc [ "title" ] ) versionSource = doc [ "versionSource" ] or "" text = "\n" . join ( [ doc [ "title" ] , doc . get ( "heTitle" , "" ) , doc [ "versionTitle" ] , versionSource ] ) if "versions" in doc : if not len ( doc [ "versions" ] ) : return None # Occurs when text versions don't actually have content text += "\nThis file contains merged sections from the following text versions:" for v in doc [ "versions" ] : text += "\n-%s\n-%s" % ( v [ 0 ] , v [ 1 ] ) def make_node ( node , depth , * * kwargs ) : if not node . children : content = "\n\n%s\n\n" % node . primary_title ( doc [ "language" ] ) cnode = version . content_node ( node ) if strip_html : cnode = version . remove_html_and_make_presentable ( cnode ) content += flatten ( cnode , node . sectionNames ) return content else : return "\n\n%s" % node . primary_title ( doc [ "language" ] ) def flatten ( text , sectionNames ) : text = text or "" if len ( sectionNames ) == 1 : text = [ t if t else "" for t in text ] # Bandaid for mismatch between text structure, join recursively if text # elements are lists instead of strings. return "\n" . join ( [ t if isinstance ( t , str ) else "\n" . join ( t ) for t in text ] ) flat = "" for i in range ( len ( text ) ) : section = section_to_daf ( i + 1 ) if sectionNames [ 0 ] == "Daf" else str ( i + 1 ) flat += "\n\n%s %s\n\n%s" % ( sectionNames [ 0 ] , section , flatten ( text [ i ] , sectionNames [ 1 : ] ) ) return flat text += index . nodes . traverse_to_string ( make_node ) return text