For a discussion of the algorithm used to convert self._phraseList to XML, see Section 19.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 19.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)