chapisha/helpers/pages.py
def create_toc_xhtml(metadata: WorkMetadata, spine: list[Matter]) -> str:
    """
    Load the default `toc.xhtml` file, and generate the required terms for the creative work. Return xhtml as a string.
    
    Parameters
    ----------
    metadata: WorkMetadata
        All the terms for updating the work, not all compulsory
    spine: list of Matter
        Spine and guide list of Matter, with `dedication` at 0, if present

    Returns
    -------
    str: xhtml response for `toc.xhtml` as a str.
    """
    with open(DATA_PATH / "xhtml" / DEFAULT_TOC_XHTML, "r+", encoding="utf-8") as toc_file:
        toc_xml = toc_file.read()
        # Table of Contents
        toc_xhtml = ""
        chapter = 1
        for matter in spine:
            if matter.content == FrontMatter.dedication:
                toc_xhtml += F'\t\t\t\t<li>\n\t\t\t\t\t<a href="text/dedication.xhtml">{matter.title}</a>\n\t\t\t\t</li>\n'
            if matter.partition == MatterPartition.body:
                toc_xhtml += F'\t\t\t\t<li>\n\t\t\t\t\t<a href="text/chapter-{chapter}.xhtml">{matter.title}</a>\n\t\t\t\t</li>\n'
                chapter += 1
        toc_xml = toc_xml.replace('\t\t\t\t<li>\n\t\t\t\t\t<a href="text/chapter-1.xhtml"></a>\n\t\t\t\t</li>\n',
                                  toc_xhtml)
        # Landmark Title
        toc_xml = toc_xml.replace('<a href="text/chapter-1.xhtml" epub:type="bodymatter z3998:fiction">WORK_TITLE</a>',
                                  F'<a href="text/chapter-1.xhtml" epub:type="bodymatter z3998:fiction">{metadata.title}</a>')
    return toc_xml

    Load the default `toc.xhtml` file, and generate the required terms for the creative work. Return xhtml as a string.
    
    Parameters
    ----------
    metadata: WorkMetadata
        All the terms for updating the work, not all compulsory
    spine: list of Matter
        Spine and guide list of Matter, with `dedication` at 0, if present

    Returns
    -------
    str: xhtml response for `toc.xhtml` as a str.
    
Load the default `toc.xhtml` file, and generate the required terms for the creative work. Return xhtml as a string.
Parameters

WorkMetadata
All the terms for updating the work, not all compulsory
spine: list of Matter
Spine and guide list of Matter, with `dedication` at 0, if present

Returns

xhtml response for `toc.xhtml` as a str.
Load the default ` toc . xhtml ` file and generate the required terms for the creative work . Return xhtml as a string . Parameters WorkMetadata All the terms for updating the work not all compulsory spine : list of Matter Spine and guide list of Matter with ` dedication ` at 0 if present Returns xhtml response for ` toc . xhtml ` as a str .
def create_toc_xhtml(metadata: WorkMetadata, spine: list[Matter]) -> str:
    with open(DATA_PATH / "xhtml" / DEFAULT_TOC_XHTML, "r+", encoding="utf-8") as toc_file:
        toc_xml = toc_file.read()
        toc_xhtml = ""
        chapter = 1
        for matter in spine:
            if matter.content == FrontMatter.dedication:
                toc_xhtml += F'\t\t\t\t<li>\n\t\t\t\t\t<a href="text/dedication.xhtml">{matter.title}</a>\n\t\t\t\t</li>\n'
            if matter.partition == MatterPartition.body:
                toc_xhtml += F'\t\t\t\t<li>\n\t\t\t\t\t<a href="text/chapter-{chapter}.xhtml">{matter.title}</a>\n\t\t\t\t</li>\n'
                chapter += 1
        toc_xml = toc_xml.replace('\t\t\t\t<li>\n\t\t\t\t\t<a href="text/chapter-1.xhtml"></a>\n\t\t\t\t</li>\n',
                                  toc_xhtml)
        toc_xml = toc_xml.replace('<a href="text/chapter-1.xhtml" epub:type="bodymatter z3998:fiction">WORK_TITLE</a>',
                                  F'<a href="text/chapter-1.xhtml" epub:type="bodymatter z3998:fiction">{metadata.title}</a>')
    return toc_xml
def create_toc_xhtml ( metadata : WorkMetadata , spine : list [ Matter ] ) -> str : with open ( DATA_PATH / "xhtml" / DEFAULT_TOC_XHTML , "r+" , encoding = "utf-8" ) as toc_file : toc_xml = toc_file . read ( ) toc_xhtml = "" chapter = 1 for matter in spine : if matter . content == FrontMatter . dedication : toc_xhtml += F'\t\t\t\t<li>\n\t\t\t\t\t<a href="text/dedication.xhtml">{matter.title}</a>\n\t\t\t\t</li>\n' if matter . partition == MatterPartition . body : toc_xhtml += F'\t\t\t\t<li>\n\t\t\t\t\t<a href="text/chapter-{chapter}.xhtml">{matter.title}</a>\n\t\t\t\t</li>\n' chapter += 1 toc_xml = toc_xml . replace ( '\t\t\t\t<li>\n\t\t\t\t\t<a href="text/chapter-1.xhtml"></a>\n\t\t\t\t</li>\n' , toc_xhtml ) toc_xml = toc_xml . replace ( '<a href="text/chapter-1.xhtml" epub:type="bodymatter z3998:fiction">WORK_TITLE</a>' , F'<a href="text/chapter-1.xhtml" epub:type="bodymatter z3998:fiction">{metadata.title}</a>' ) return toc_xml
Load the default `toc.xhtml` file, and generate the required terms for the creative work.
Load the default ` toc . xhtml ` file and generate the required terms for the creative work .
"""
    Load the default `toc.xhtml` file, and generate the required terms for the creative work. Return xhtml as a string.
    
    Parameters
    ----------
    metadata: WorkMetadata
        All the terms for updating the work, not all compulsory
    spine: list of Matter
        Spine and guide list of Matter, with `dedication` at 0, if present

    Returns
    -------
    str: xhtml response for `toc.xhtml` as a str.
    """ # Table of Contents # Landmark Title
metadata
WorkMetadata
spine
list[Matter]