Ejemplo n.º 1
0
def styledtext_to_html(
    styledtext: StyledText,
    space_format: int,
    contains_html: bool = False,
    link_format: Optional[str] = None,
):
    """Return the note in HTML format.

    Adapted from DynamicWeb.
    """
    backend = HtmlBackend()
    if link_format is not None:
        backend.build_link = build_link_factory(link_format)

    text = str(styledtext)

    if not text:
        return ""

    s_tags = styledtext.get_tags()
    html_list = Html("div", class_="grampsstylednote")
    if contains_html:
        markuptext = backend.add_markup_from_styled(text,
                                                    s_tags,
                                                    split="\n",
                                                    escape=False)
        html_list += markuptext
    else:
        markuptext = backend.add_markup_from_styled(text, s_tags, split="\n")
        linelist = []
        linenb = 1
        sigcount = 0
        for line in markuptext.split("\n"):
            [line, sigcount] = process_spaces(line, format=space_format)
            if sigcount == 0:
                # The rendering of an empty paragraph '<p></p>'
                # is undefined so we use a non-breaking space
                if linenb == 1:
                    linelist.append("&nbsp;")
                html_list.extend(Html("p") + linelist)
                linelist = []
                linenb = 1
            else:
                if linenb > 1:
                    linelist[-1] += "<br />"
                linelist.append(line)
                linenb += 1
        if linenb > 1:
            html_list.extend(Html("p") + linelist)
        # if the last line was blank, then as well as outputting the previous para,
        # which we have just done,
        # we also output a new blank para
        if sigcount == 0:
            linelist = ["&nbsp;"]
            html_list.extend(Html("p") + linelist)
    return "\n".join(html_list)
Ejemplo n.º 2
0
    def open(self, filename):
        """
        Overwrite base method
        """
        self._backend = HtmlBackend(filename)
        self._backend.open()
        self.htmllist += [self._backend.html_body]
        #start a gramps report
        self.htmllist += [Html('div', id="grampstextdoc")]

        self.build_header()
Ejemplo n.º 3
0
def styled_note(styledtext, format, contains_html=False):
    """Return the note in HTML format.

    Adapted from DynamicWeb.
    """
    _backend = HtmlBackend()

    text = str(styledtext)

    if (not text): return ('')

    s_tags = styledtext.get_tags()
    htmllist = Html("div", class_="grampsstylednote")
    if contains_html:
        markuptext = _backend.add_markup_from_styled(text,
                                                     s_tags,
                                                     split='\n',
                                                     escape=False)
        htmllist += markuptext
    else:
        markuptext = _backend.add_markup_from_styled(text, s_tags, split='\n')
        linelist = []
        linenb = 1
        sigcount = 0
        for line in markuptext.split('\n'):
            [line, sigcount] = process_spaces(line, format)
            if sigcount == 0:
                # The rendering of an empty paragraph '<p></p>'
                # is undefined so we use a non-breaking space
                if linenb == 1:
                    linelist.append('&nbsp;')
                htmllist.extend(Html('p') + linelist)
                linelist = []
                linenb = 1
            else:
                if linenb > 1:
                    linelist[-1] += '<br />'
                linelist.append(line)
                linenb += 1
        if linenb > 1:
            htmllist.extend(Html('p') + linelist)
        # if the last line was blank, then as well as outputting the previous para,
        # which we have just done,
        # we also output a new blank para
        if sigcount == 0:
            linelist = ["&nbsp;"]
            htmllist.extend(Html('p') + linelist)
    return '\n'.join(htmllist)