This method constructs one child of the para
element being built by Section 18.4, “Paragraph.writeNode(): Write as
XML”.
# - - - P a r a g r a p h . _ _ w r i t e P a r a C h i l d
def __writeParaChild ( self, para, pos ):
"""Add one child element to a para element.
[ (para is an et.Element) and
(0 <= pos < len(self.__phraseList)) and
(self.__phraseList[pos] is a marked-up phrase) ->
para := para with a child element made from
the phrase at self.__phraseList[pos] with
its tail made from any following unmarked
phrases ]
return the position in self.__phraseList after
pos where the next marked-up element is, if any,
otherwise len(self.__phraseList) ]
"""
First we extract the child's tag name and text, make it into a
child element, and increment pos.
#-- 1 --
# [ markup := self.__phraseList[pos][0]
# s := self.__phraseList[pos][1]
# pos := pos + 1 ]
markup, s = self.__phraseList[pos]
pos += 1
#-- 2 --
# [ para := para with a new child added whose
# tag is (markup), whose text is (s), and whose
# tail is None
# child := that new child ]
child = et.SubElement ( para, markup )
child.text = s
Next, we find and concatenate any leading unmarked phrases at
position pos, and leave pos
pointing after them.
#-- 2 --
# [ if self.__phraseList[pos:] has any leading unmarked
# phrases ->
# pos := pos advanced past those phrases
# child.tail := concatenation of all text from
# those phrases ]
# else -> I ]
if pos < len(self.__phraseList):
textList = []
while pos < len(self.__phraseList):
markup, s = self.__phraseList[pos]
if markup is not None:
break
textList.append ( s )
pos += 1
if len(textList) > 0:
child.tail = "".join(textList)
Our work here is done, except for returning the position past the material we have consumed.
#-- 3 --
return pos