Next / Previous / Contents / Shipman's homepage

6.12. foRenderChild(): Convert one child node to FO

# - - -   f o R e n d e r C h i l d

def foRenderChild(foNode, docNode):
    '''Render one DocBook element and its tail.

      [ (foNode is an FO container as an et.Element) and
        (docNode is a DocBook node as an et.Element) ->
          foNode  :=  foNode + (child rendered as FO with
                      selected markup) + child.tail ]

For markupMap, the dictionary that relates DocBook elements to FO inline styles, see Section 6.10, “renderTitle(): Remove tags from a title element. Test case: ABCD”. If the DocBook node's tag is a key in this dictionary, we will create a new inline child element to foNode whose style is taken from the corresponding value in markupMap. If docNode is not one of the rendered elements, no inline is created. In either case, foDest specifies the element to which the rendered content of docNode will be added.

    #-- 1
    # [ if docNode.tag is a key in markupMap ->
    #     foNode  :=  foNode with a new inline added whose style
    #                 comes from markupMap[docNode.tag]
    #     foDest  :=  that new inline
    #   else ->
    #     foDest  :=  foNode ]
        style = markupMap[docNode.tag]
        foDest = subElement(foNode, h.inline(style))
    except KeyError:
        foDest = foNode

Next comes a recursive call to Section 6.11, “foRenderContent(): Render text and descendants into FO”, which renders only the content (text and child elements) of docNode.

    #-- 2
    # [ foDest  :=  foDest + (docNode.text if any) +
    #               (descendants of docNode with selected markup) ]
    foRenderContent(foDest, docNode)

Finally, we must add the .tail text of docNode to the output. If no children were added to foNode in the previous step (because foNode had no rendered descendants), that text will be added to the .text attribute of foNode. If any children were added, the text will be added to the .tail attribute of the last child.

    #-- 3
    # [ if foNode has any children ->
    #     foNode  :=  foNode with docNode.tail added to its
    #                 last child
    #   else ->
    #     foNode.text  +:=  docNode.tail ]
    addText(foNode, docNode.tail)