Example #1
0
    def visit_moinpage_h(self, element):
        """
        There is not really heading in DocBook, but rather section with
        title. The section is a root tag for all the elements which in
        the dom tree will be between two heading tags.

        So we need to process child manually to determine correctly the
        children of each section.

        A section is closed when we have a new heading with an equal or
        higher level.
        """
        depth = element.get(moin_page('outline-level'))
        # We will have a new section
        # under another section
        if depth > self.current_section:
            self.parent_section = self.current_section
            self.current_section = int(depth)
            self.section_children[self.current_section] = []
            # NB : Error with docbook.title
            title = ET.Element(docbook('title'), attrib={}, children=element[0])
            self.section_children[self.current_section].append(title)

        # We will close a section before starting a new one
        # Need more test
        elif depth < self.current_section:
            if self.parent_section != 0:
                section_tag = 'sect{0}'.format(self.parent_section)
                section = ET.Element(docbook(section_tag), attrib={},
                                     children=self.section_children[self.current_section])
                self.section_children[self.parent_section].append(section)
                self.current_section = int(depth)
Example #2
0
    def visit_moinpage_page(self, element):
        title = ET.Element(docbook('title'), attrib={}, children=[self.title])
        info = ET.Element(docbook.info, attrib={}, children=[title])
        for item in element:
            if item.tag.uri == moin_page and item.tag.name == 'body':
                c = self.do_children(item)
                if not c:
                    self.section_children = sorted(self.section_children.items(),
                                                   reverse=True)
                    section = None
                    for k, v in self.section_children:
                        if section:
                            section_tag = 'sect{0}'.format(k)
                            v.append(section)
                            section = ET.Element(docbook(section_tag),
                                                 attrib={}, children=v)
                        else:
                            section_tag = 'sect{0}'.format(k)
                            section = ET.Element(docbook(section_tag),
                                                 attrib={}, children=v)
                    return ET.Element(docbook.article,
                                      attrib={}, children=[info, section])
                else:
                    c.insert(0, info)
                    return ET.Element(docbook.article, attrib={}, children=c)

        raise RuntimeError('page:page need to contain exactly one page body tag, got {0!r}'.format(element[:]))
Example #3
0
    def visit_moinpage_list(self, element):
        """
        Function called to handle the conversion of list.

        It will called a specific function to handle (un)ordered list,
        with the appropriate DocBook tag.

        Or a specific function to handle definition list.
        """
        item_label_generate = element.get(moin_page('item-label-generate'))
        if 'ordered' == item_label_generate:
            attrib = {}
            # Get the list-style-type to define correctly numeration
            list_style_type = element.get(moin_page('list-style-type'))
            if 'upper-alpha' == list_style_type:
                attrib[docbook('numeration')] = 'upperalpha'
            elif 'upper-roman' == list_style_type:
                attrib[docbook('numeration')] = 'upperroman'
            elif 'lower-alpha' == list_style_type:
                attrib[docbook('numeration')] = 'loweralpha'
            elif 'lower-roman' == list_style_type:
                attrib[docbook('numeration')] = 'lowerroman'
            else:
                attrib[docbook('numeration')] = 'arabic'

            return self.handle_simple_list(docbook.orderedlist,
                                           element, attrib=attrib)
        elif 'unordered' == item_label_generate:
            return self.handle_simple_list(docbook.itemizedlist,
                                           element, attrib={})
        else:
            return self.new_copy(docbook.variablelist, element, attrib={})
Example #4
0
    def visit_moinpage_page(self, element):
        title = ET.Element(docbook('title'), attrib={}, children=[self.title])
        info = ET.Element(docbook.info, attrib={}, children=[title])
        for item in element:
            if item.tag.uri == moin_page and item.tag.name == 'body':
                c = self.do_children(item)
                if not c:
                    self.section_children = sorted(self.section_children.items(),
                                                   reverse=True)
                    section = None
                    for k, v in self.section_children:
                        if section:
                            section_tag = 'sect{0}'.format(k)
                            v.append(section)
                            section = ET.Element(docbook(section_tag),
                                                 attrib={}, children=v)
                        else:
                            section_tag = 'sect{0}'.format(k)
                            section = ET.Element(docbook(section_tag),
                                                 attrib={}, children=v)
                    return ET.Element(docbook.article,
                                      attrib={}, children=[info, section])
                else:
                    c.insert(0, info)
                    return ET.Element(docbook.article, attrib={}, children=c)

        raise RuntimeError('page:page need to contain exactly one page body tag, got {0!r}'.format(element[:]))
Example #5
0
    def visit_moinpage_blockquote(self, element):
        """
        Convert::

            <blockquote>text<blockquote>

        to::

            <blockquote>
                <attribution>Unknown</attribution>
                <simpara>text</text>
            </blockquote>

        Expand::

        <blockquote source="author">text</blockquote>

        output::

            <blockquote>
                <attribution>author</attribution>
                <simpara>text</text>
            </blockquote>
        """
        author = element.get(moin_page('source'))
        if not author:
            # TODO: Internationalization
            author = "Unknown"
        attribution = self.new(docbook('attribution'), attrib={}, children=[author])
        children = self.do_children(element)
        para = self.new(docbook('simpara'), attrib={}, children=children)
        return self.new(docbook('blockquote'), attrib={}, children=[attribution, para])
Example #6
0
    def visit_moinpage_list(self, element):
        """
        Function called to handle the conversion of list.

        It will called a specific function to handle (un)ordered list,
        with the appropriate DocBook tag.

        Or a specific function to handle definition list.
        """
        item_label_generate = element.get(moin_page('item-label-generate'))
        if 'ordered' == item_label_generate:
            attrib = {}
            # Get the list-style-type to define correctly numeration
            list_style_type = element.get(moin_page('list-style-type'))
            if 'upper-alpha' == list_style_type:
                attrib[docbook('numeration')] = 'upperalpha'
            elif 'upper-roman' == list_style_type:
                attrib[docbook('numeration')] = 'upperroman'
            elif 'lower-alpha' == list_style_type:
                attrib[docbook('numeration')] = 'loweralpha'
            elif 'lower-roman' == list_style_type:
                attrib[docbook('numeration')] = 'lowerroman'
            else:
                attrib[docbook('numeration')] = 'arabic'

            return self.handle_simple_list(docbook.orderedlist,
                                           element, attrib=attrib)
        elif 'unordered' == item_label_generate:
            return self.handle_simple_list(docbook.itemizedlist,
                                           element, attrib={})
        else:
            return self.new_copy(docbook.variablelist, element, attrib={})
Example #7
0
    def visit_moinpage_h(self, element):
        """
        There is not really heading in DocBook, but rather section with
        title. The section is a root tag for all the elements which in
        the dom tree will be between two heading tags.

        So we need to process child manually to determine correctly the
        children of each section.

        A section is closed when we have a new heading with an equal or
        higher level.
        """
        depth = element.get(moin_page('outline-level'))
        # We will have a new section
        # under another section
        if depth > self.current_section:
            self.parent_section = self.current_section
            self.current_section = int(depth)
            self.section_children[self.current_section] = []
            # NB : Error with docbook.title
            title = ET.Element(docbook('title'), attrib={}, children=element[0])
            self.section_children[self.current_section].append(title)

        # We will close a section before starting a new one
        # Need more test
        elif depth < self.current_section:
            if self.parent_section != 0:
                section_tag = 'sect{0}'.format(self.parent_section)
                section = ET.Element(docbook(section_tag), attrib={},
                                     children=self.section_children[self.current_section])
                self.section_children[self.parent_section].append(section)
                self.current_section = int(depth)
Example #8
0
    def visit_moinpage_blockquote(self, element):
        """
        Convert::

            <blockquote>text<blockquote>

        to::

            <blockquote>
                <attribution>Unknown</attribution>
                <simpara>text</text>
            </blockquote>

        Expand::

        <blockquote source="author">text</blockquote>

        output::

            <blockquote>
                <attribution>author</attribution>
                <simpara>text</text>
            </blockquote>
        """
        author = element.get(moin_page('source'))
        if not author:
            # TODO: Internationalization
            author = "Unknown"
        attribution = self.new(docbook('attribution'), attrib={}, children=[author])
        children = self.do_children(element)
        para = self.new(docbook('simpara'), attrib={}, children=children)
        return self.new(docbook('blockquote'), attrib={}, children=[attribution, para])
Example #9
0
 def visit_moinpage_table(self, element):
     # TODO: Attributes conversion
     title = element.get(html('title'))
     if not title:
         # TODO: Translation
         title = "Table {0}".format(self.table_counter)
     self.table_counter += 1
     caption = ET.Element(docbook('caption'), attrib={}, children=[title])
     children = [caption]
     children.extend(self.do_children(element))
     return self.new(docbook.table, attrib={}, children=children)
Example #10
0
 def visit_moinpage_table(self, element):
     # TODO: Attributes conversion
     title = element.get(html('title'))
     if not title:
         # TODO: Translation
         title = "Table {0}".format(self.table_counter)
     self.table_counter += 1
     caption = ET.Element(docbook('caption'), attrib={}, children=[title])
     children = [caption]
     children.extend(self.do_children(element))
     return self.new(docbook.table, attrib={}, children=children)
Example #11
0
    def visit_moinpage_admonition(self, element):
        """
        There is 5 admonition in DocBook, which are also supported
        in the DOM Tree.

        For instance: <caution> --> <admonition type='caution'>
        """
        tag = element.get(moin_page('type'))
        if tag in self.admonition_tags:
            # Our tag is valid for DocBook 5
            return self.new_copy(docbook(tag), element, attrib={})
        else:
            # For the other situation, just ignore the element
            return self.do_children(element)
Example #12
0
    def visit_moinpage_admonition(self, element):
        """
        There is 5 admonition in DocBook, which are also supported
        in the DOM Tree.

        For instance: <caution> --> <admonition type='caution'>
        """
        tag = element.get(moin_page('type'))
        if tag in self.admonition_tags:
            # Our tag is valid for DocBook 5
            return self.new_copy(docbook(tag), element, attrib={})
        else:
            # For the other situation, just ignore the element
            return self.do_children(element)
Example #13
0
 def visit_moinpage_p(self, element):
     """
     If we have a title attribute for p, we return a para,
     with a <title> child.
     Otherwise we return a <simpara>.
     """
     title_attr = element.get(html('title'))
     if title_attr:
         print title_attr
         children = []
         title_elem = self.new(docbook('title'), attrib={},
                               children=[title_attr])
         children.append(title_elem)
         children.extend(self.do_children(element))
         return self.new(docbook.para, attrib={}, children=children)
     else:
         return self.new_copy(docbook.simpara, element, attrib={})
Example #14
0
 def visit_moinpage_p(self, element):
     """
     If we have a title attribute for p, we return a para,
     with a <title> child.
     Otherwise we return a <simpara>.
     """
     title_attr = element.get(html('title'))
     if title_attr:
         print title_attr
         children = []
         title_elem = self.new(docbook('title'), attrib={},
                               children=[title_attr])
         children.append(title_elem)
         children.extend(self.do_children(element))
         return self.new(docbook.para, attrib={}, children=children)
     else:
         return self.new_copy(docbook.simpara, element, attrib={})