Пример #1
0
    def startElement(self, name, attrs):

        # Track indentation for lists.

        if list_tags.has_key(name):
            self.indents.append(self.indents[-1] + 1)

        # Track element nesting.

        if self.states.has_key(name):
            self.states[name] += 1

        # Track cumulative element nesting in order to produce appropriate depth
        # indicators in the formatted output.

        if name in preformatted_tags or name in formatted_tags:
            self.level += 1
            self.max_level = max(self.level, self.max_level)

            # Reset indentation within regions.

            self.indents.append(0)

        if name in headings:
            self.held_anchors = []

        Parser.startElement(self, name, attrs)

        # Remember macro information for use within the element.

        if name == "ac:macro":
            self.macros.append(self.attributes[-1].get("ac:name"))
            self.macro_parameters.append({})
Пример #2
0
    def endElement(self, name):

        # Reset the indent for any preformatted/formatted region so that it may
        # itself be indented.

        if name in preformatted_tags or name in formatted_tags:
            self.indents.pop()

        Parser.endElement(self, name)

        if list_tags.has_key(name):
            self.indents.pop()

        if self.states.has_key(name):
            self.states[name] -= 1

        if name in preformatted_tags or name in formatted_tags:
            self.level -= 1
            if not self.level:
                self.max_level = 0

        # Discard macro state.

        if name == "ac:macro":
            self.macros.pop()
            self.macro_parameters.pop()
Пример #3
0
    def __init__(self, out):
        Parser.__init__(self)
        self.out = out

        # Link target and label information.

        self.target = None
        self.target_type = None
        self.label = None

        # Macro information.

        self.macros = []
        self.macro_parameters = []
        self.held_anchors = []

        # Indentation and element nesting states.

        self.indents = [0]
        self.states = {}
        self.max_level = self.level = 0

        for name in preformatted_tags + single_level_tags:
            self.states[name] = 0

        # Table states.

        self.table_rows = 0
        self.table_columns = 0

        # Block states.

        self.have_block = False
Пример #4
0
 def characters(self, content):
     if not self.is_preformatted():
         content = self.normalise(content, self.elements[-1])
     Parser.characters(self, content)