For a discussion of the algorithm used to convert self.__phraseList to XML, see Section 18.4, “Paragraph.writeNode(): Write as
XML”.
# - - - P a r a g r a p h . w r i t e C o n t e n t
def writeContent ( self, parent ):
"""Convert self.__phraseList to XML.
[ parent is an et.Element ->
parent := parent with XML content made from
self.__phraseList ]
"""
As we work through self.__phraseList, we'll use
an index named pos to mark our current position.
#-- 1 --
# [ pos := position of first marked-up phrase in
# self.__phraseList, or past the end if there are
# no marked-up phrases
# parent.text := concatenation of text parts of all
# initial unmarked phrases in self.__phraseList ]
pos = 0; textList = []
while pos < len(self.__phraseList):
markup, s = self.__phraseList[pos]
if markup is None:
textList.append ( s )
pos += 1
else:
break
parent.text = "".join(textList)
At this point, pos points either at the first
marked-up phrase, or the end of the list. Work through the
remainder of the list if any, converting each sequence of
marked-up phrase optionally followed by unmarked phrase into a
new child element. See Section 18.6, “Paragraph.__writeParaChild()”.
#-- 2 --
# [ parent := parent with child elements made from marked-up
# elements of self.__phraseList[pos:], each with
# its tail made from unmarked following elements ]
while pos < len(self.__phraseList):
#-- 3 body --
# [ pos := position in self.__phraseList after
# pos where the next marked-up element is
# parent := parent with a child element made from
# the phrase at self.__phraseList[pos] with
# its tail made from any following unmarked
# phrases ]
pos = self.__writeParaChild ( parent, pos )