Next / Previous / Contents / Shipman's homepage

6.10. renderTitle(): Remove tags from a title element. Test case: ABCD

The purpose of this function is to convert the content of a DocBook title to an equivalent FO inline.

In most cases the content will be only text, but we will convert certain markup to FO inlines:

The title of this section contains a test case: letter A is inside an application tag, letter B is inside a phrase tag (to be ignored), letter C is outside the phrase but inside the application; and letter D is outside the application. The rendered title should end with “ABC” marked up as application, but “D” not marked up.

The logic to do this conversion is a bit tricky. For elements that are rendered, the .tail text on that element must appear in the .tail of the inline; but for elements that are not rendered, the .tail text goes inside the same element containing the surrounding text.

At this level, the logic is fairly simple. We create a new inline as a container for all the rendered text, and call Section 6.11, “foRenderContent(): Render text and descendants into FO” to render the content of the title element into that inline. The inline is returned as the result of this function.

We'll need a dictionary that maps each DocBook element to the corresponding FO font. In the intended functions that follow, the phrase “selected markup” refers to elements whose tags are keys in the markupMap dictionary.

docbookindex
# - - -   r e n d e r T i t l e

markupMap = {
    "application":  APP_FONT,
    "replaceable":  REPLACE_FONT,
    "code":         MONO_FONT,
    "filename":     MONO_FONT,
    "userinput":    MONO_FONT }

def renderTitle(node):
    '''Similar to the text() function in XSLT.

      [ node is a DocBook title node as an et.Element ->
          return node as an FO inline, with selected markup
          rendered as FO and the remaining content not
          marked up ]
    '''
    #-- 1
    # [ result  :=  a new, empty FO inline ]
    result = E.inline()

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

    #-- 3
    return result