Beispiel #1
0
    def _add_html_listitem(self, html_parent, list_item: ListItem) -> None:
        html_list_item = ET.SubElement(html_parent, 'li')

        inline_elements: TList[InlineElement] = list_item.inline_elements
        if list_item.symbol != '-':
            if len(inline_elements) > 0 and isinstance(inline_elements[0],
                                                       NormalText):
                inline_elements[0] = NormalText(list_item.symbol + ' ' +
                                                inline_elements[0].text)
            else:
                inline_elements = [NormalText(list_item.symbol + ' ')
                                   ] + inline_elements

        # if list_item.preformatted:
        #     html_cur_item = ET.SubElement(html_list_item, 'pre')
        # else:
        #     html_cur_item = html_list_item
        # self._add_html_inline_elements(html_cur_item, inline_elements)
        if list_item.preformatted:
            self._add_preformatted_html_inline_elements(
                html_list_item, inline_elements)
        else:
            self._add_html_inline_elements(html_list_item, inline_elements)

        for sub_item in list_item.sub_items:
            # html_list = ET.SubElement(html_cur_item, 'ul')
            html_list = ET.SubElement(html_list_item, 'ul')
            self._add_html_listitem(html_list, sub_item)
Beispiel #2
0
 def _iter_inline_elements(self, xml_element) -> Iterator[InlineElement]:
     """ <a>a.text<b>b.text</b>b.tail</a>"""
     if xml_element.text:
         yield NormalText(xml_element.text)
     for xml_child in xml_element:
         inline_elem = self._create_inline_element(xml_child)
         if inline_elem is not None:
             yield inline_elem
             if xml_child.tail:
                 yield NormalText(xml_child.tail)
Beispiel #3
0
 def test_list_with_sublist(self):
     self._test_one_element(
         List([
             ListItem(inline_elements=[
                 NormalText('aaa'),
                 BoldText('bbb'),
                 NormalText('ccc')
             ],
                      sub_items=[ListItem([NormalText('ddd')])])
         ]), '<list>'
         '<item>aaa<bold>bbb</bold>ccc'
         '<item>ddd</item>'
         '</item>'
         '</list>')
Beispiel #4
0
 def test_nested_list(self):
     self._test_one_element(
         List([
             ListItem([NormalText('aaa')],
                      sub_items=[ListItem([NormalText('bbb')])])
         ]),
         '<ul>'
         '<li>aaa'
         '<ul>'
         '<li>bbb</li>'
         '</ul>'
         '</li>'
         '</ul>'
     )
Beispiel #5
0
 def test_table(self):
     self._test_one_element(
         Table(columns=[Column(halign=HAlign.LEFT, text='A'),
                        Column(halign=HAlign.RIGHT, text='B')],
               rows=[Row([Cell([NormalText('aaa')]),
                          Cell([NormalText('bbb')])])]),
         '<table>'
         '<thead>'
         '<tr>' '<th align="left">A</th>' '<th align="right">B</th>' '</tr>'
         '</thead>'
         '<tbody>'
         '<tr>' '<td>aaa</td>' '<td>bbb</td>' '</tr>'
         '</tbody>'
         '</table>'
     )
Beispiel #6
0
 def test_table(self):
     self._test_one_element(
         Table(
             columns=[
                 Column(halign=HAlign.LEFT, text='A'),
                 Column(halign=HAlign.RIGHT, text='B')
             ],
             rows=[
                 Row([Cell([NormalText('aaa')]),
                      Cell([NormalText('bbb')])])
             ]), '<table>'
         '<column halign="left">A</column>'
         '<column halign="right">B</column>'
         '<row><cell>aaa</cell><cell>bbb</cell></row>'
         '</table>')
Beispiel #7
0
    def create(self) -> ET.XML:
        html_page: ET.XML = ET.fromstring('<html></html>')

        if self._title:
            self._add_html_header(
                html_page,
                Header(level=0, inline_elements=[NormalText(self._title)]))

        for block_element in self._page.block_elements:
            self._add_html_block_element(html_page, block_element)
        return html_page
Beispiel #8
0
    def _extend_page_with_task_cache(self, page: Page, task: Task) -> None:
        task_cache = task.cache
        if task_cache:
            if task_cache.readme:
                page.block_elements.append(
                    Header(level=2, inline_elements=[NormalText('readme:')]))
                page.block_elements.append(
                    Paragraph([NormalText(task_cache.readme)],
                              preformatted=True))
            if task_cache.file_names:
                page.block_elements.append(
                    Header(level=2, inline_elements=[NormalText('files:')]))
                file_tree = FilebufSplitter(task_cache.file_names).split()
                new_list = List()
                task_path = task.get_path(self._task_model.tasks_root)
                for name in sorted(file_tree.keys()):
                    new_link = Link(text=name, uri=str(task_path / name))
                    new_item = ListItem(inline_elements=[new_link])
                    self._build_file_list_recursive(new_item, file_tree[name],
                                                    task_path / name)
                    new_list.items.append(new_item)

                page.block_elements.append(new_list)
Beispiel #9
0
 def test_preformatted_list(self):
     self._test_one_element(
         List([ListItem([NormalText('  aaa\n  bbb')], preformatted=True)]),
         '<ul><li><pre>  aaa</pre><pre>  bbb</pre></li></ul>'
     )
Beispiel #10
0
 def test_list_with_arrow(self):
     self._test_one_element(
         List([ListItem([NormalText('aaa')]),
               ListItem([NormalText('bbb')], symbol='=>')]),
         '<ul><li>aaa</li><li>=&gt; bbb</li></ul>'
     )
Beispiel #11
0
 def test_simple_list(self):
     self._test_one_element(List([ListItem([NormalText('aaa')])]),
                            '<list><item>aaa</item></list>')
Beispiel #12
0
 def test_list(self):
     self._test_one_element(
         List([ListItem([NormalText('aaa')])]),
         '<ul><li>aaa</li></ul>'
     )
Beispiel #13
0
 def test_bold(self):
     self._test_one_element(
         Paragraph([NormalText('aaa'), BoldText('bbb'), NormalText('ccc')]),
         '<p>aaa<b>bbb</b>ccc</p>'
     )
Beispiel #14
0
 def test_preformatted_paragraph(self):
     self._test_one_element(
         Paragraph([NormalText('  aaa\n  bbb')], preformatted=True),
         '<pre>  aaa\n  bbb</pre>'
     )
Beispiel #15
0
 def test_preformatted_paragraph(self):
     self._test_one_element(
         Paragraph([NormalText('aaa')], preformatted=True),
         '<paragraph preformatted="true">aaa</paragraph>')
Beispiel #16
0
 def test_preformatted_list_item(self):
     self._test_one_element(
         List([ListItem([NormalText('aaa')], preformatted=True)]),
         '<list><item preformatted="true">aaa</item></list>')
Beispiel #17
0
 def test_list_with_non_default_symbol(self):
     self._test_one_element(
         List([ListItem([NormalText('aaa')], symbol='a.')]),
         '<list><item symbol="a.">aaa</item></list>')
Beispiel #18
0
 def test_header(self):
     self._test_one_element(
         Header(level=1, inline_elements=[NormalText('aaa')]),
         '<h2>aaa</h2>'
     )
Beispiel #19
0
 def test_simple_paragraph(self):
     self._test_one_element(
         Paragraph([NormalText('aaa')]),
         '<p>aaa</p>'
     )
Beispiel #20
0
 def _process_gap_text(self, gap_text: str) -> None:
     if len(gap_text) > 0:
         normal_text = NormalText(gap_text)
         self._inline_elements.append(normal_text)
Beispiel #21
0
 def test_paragraph(self):
     self._test_one_element(Paragraph([NormalText('aaa')]),
                            '<paragraph>aaa</paragraph>')