This method constructs one child of the
element being built by Section 19.4, “
Paragraph.writeNode(): Write as
# - - - 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
#-- 1 -- # [ markup := self._phraseList[pos] # s := self._phraseList[pos] # 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
pos, and leave
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