Next / Previous / Contents / Shipman's homepage

6.17. reportLine(): Format one line of the report

docbookindex
# - - -   r e p o r t L i n e

def reportLine ( flow, depth, sectNode ):
    '''Format the report block for one section title.

      [ (flow is an et.Element) and
        (depth is a nonnegative int) and
        (sectNode is an et.Element) ->
          flow  +:=  a block describing sectNode, indented
                     by depth ]
    '''

First, extract the section's id attribute. Every section should have one, but just in case, we will spit out some question marks if it doesn't.

docbookindex
    #-- 1
    # [ if sectNode has an id attribute ->
    #     sectionId  :=  that attribute
    #   else ->
    #     sectionId  :=  "????" ]
    sectionId = sectNode.attrib.get("id", "????")

Next, find the title node. There had better be one, or we'll display nothing.

docbookindex
    #-- 2
    # [ if sectNode has a title child ->
    #     titleInline  :=  title text as an FO inline, with
    #         selected elements rendered and the rest ignored
    #   else ->
    #     titleInline  :=  an empty FO inline ]
    titleNodeList = sectNode.xpath("title")
    if len(titleNodeList) >= 1:
        titleInline = renderTitle(titleNodeList[0])
    else:
        titleInline = E.inline()

For the logic that formats the block element and adds it to the flow, see Section 6.18, “formatLine(): Assemble one block in the report body”.

docbookindex
    #-- 3
    # [ flow  +:=  a block displaying sectionId and titleInline,
    #              indented by (depth) levels ]
    formatLine(flow, depth, sectionId, titleInline)