Next / Previous / Contents / Shipman's homepage

23.18. MonthCell.__paraContent(): Content of one paragraph

This method translates the “phrase list” structure inside a Paragraph instance into XHTML.

Although some text in a paragraph can be marked up (e.g., with genus tags), the structure is only one level deep: the child elements do not themselves have element children.

However, the rendering of even this shallow structure is not completely obvious, due to the strange way that the lxml package handles mixed content: text after an element is stored in the .tail attribute of the preceding element, and not associated with the parent (as it would be in the Document Object Model).

Fortunately, the tccpage2 module already contains a function named addTextMixed() that handles this problem. For details of this function, see the documentation for tccpage2.

For a Paragraph element P, method P.genContent() produces a list of (tag, text) tuples.

noteweb
# - - -   M o n t h C e l l . _ _ p a r a C o n t e n t

    def __paraContent ( self, parent, para ):
        """Translate the content inside one paragraph.

          [ (parent is an et.Element) and
            (para is a birdnotes.Paragraph instance) ->
              parent  +:=  XHTML rendering of para's contents ]
        """
        #-- 1 --
        for tag, s in para.genContent():
            #-- 1 body --
            # [ (tag is None or a tag string) and
            #   (s is a string) ->
            #     if tag is None ->
            #       parent  :=  parent with (s) added to its text
            #     else ->
            #       parent  :=  parent with a new span element
            #           added, with class=(tag), and text (s) ]
            if tag is None:
                tccpage2.addTextMixed ( parent, s )
            else:
                self.__span ( parent, tag, s )