chapisha/helpers/pages.py
def restructure_chapter(source: bytes):
    """
    Given an xml source, restructure the content into the default chapter xhtml format.

    Parameters
    ----------
    source: bytes
        Chapter xhtml as bytes.

    Returns
    -------
    Beautifulsoup xhtml.
    """
    if not isinstance(source, bytes):
        e = "Source is not of type `bytes`."
        raise TypeError(e)
    source = BeautifulSoup(source.decode("utf-8"), "lxml")
    # rename `media` folder to `images`
    for img in source.find_all("img"):
        img["src"] = img["src"].replace("../media/", "../images/")
    with open(DATA_PATH / "xhtml" / DEFAULT_CHAPTER, "r+", encoding="utf-8") as dc:
        chapter = BeautifulSoup(dc.read(), "lxml")
        chapter.section.contents = source.section.contents
        chapter.title.contents = source.title.contents
        chapter.smooth()
    return chapter

    Given an xml source, restructure the content into the default chapter xhtml format.

    Parameters
    ----------
    source: bytes
        Chapter xhtml as bytes.

    Returns
    -------
    Beautifulsoup xhtml.
    
Given an xml source, restructure the content into the default chapter xhtml format.
Parameters

bytes
Chapter xhtml as bytes.

Returns

Beautifulsoup xhtml.
Given an xml source restructure the content into the default chapter xhtml format . Parameters bytes Chapter xhtml as bytes . Returns Beautifulsoup xhtml .
def restructure_chapter(source: bytes):
    if not isinstance(source, bytes):
        e = "Source is not of type `bytes`."
        raise TypeError(e)
    source = BeautifulSoup(source.decode("utf-8"), "lxml")
    for img in source.find_all("img"):
        img["src"] = img["src"].replace("../media/", "../images/")
    with open(DATA_PATH / "xhtml" / DEFAULT_CHAPTER, "r+", encoding="utf-8") as dc:
        chapter = BeautifulSoup(dc.read(), "lxml")
        chapter.section.contents = source.section.contents
        chapter.title.contents = source.title.contents
        chapter.smooth()
    return chapter
def restructure_chapter ( source : bytes ) : if not isinstance ( source , bytes ) : e = "Source is not of type `bytes`." raise TypeError ( e ) source = BeautifulSoup ( source . decode ( "utf-8" ) , "lxml" ) for img in source . find_all ( "img" ) : img [ "src" ] = img [ "src" ] . replace ( "../media/" , "../images/" ) with open ( DATA_PATH / "xhtml" / DEFAULT_CHAPTER , "r+" , encoding = "utf-8" ) as dc : chapter = BeautifulSoup ( dc . read ( ) , "lxml" ) chapter . section . contents = source . section . contents chapter . title . contents = source . title . contents chapter . smooth ( ) return chapter
Given an xml source, restructure the content into the default chapter xhtml format.
Given an xml source restructure the content into the default chapter xhtml format .
"""
    Given an xml source, restructure the content into the default chapter xhtml format.

    Parameters
    ----------
    source: bytes
        Chapter xhtml as bytes.

    Returns
    -------
    Beautifulsoup xhtml.
    """ # rename `media` folder to `images`
source
bytes