def _process_link(self, match: Match) -> bool: if match.group('link') is None: return False link = Link(uri=match.group('uri'), text=match.group('text')) self._inline_elements.append(link) return True
def _build_file_list_recursive(self, list_item: ListItem, file_subtree: Dict[str, Any], dpath: Path): for name in sorted(file_subtree.keys()): new_link = Link(text=name, uri=str(dpath / name)) new_sub_item = ListItem(inline_elements=[new_link]) list_item.sub_items.append(new_sub_item) self._build_file_list_recursive(new_sub_item, file_subtree[name], dpath / name)
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)
def test_link_without_text(self): self._test_one_element( Paragraph([Link(uri='www.wikipedia.de', text=None)]), '<p><a href="www.wikipedia.de">www.wikipedia.de</a></p>' )
def _create_link(xml_link) -> Link: uri = xml_link.attrib['uri'] return Link(uri=uri, text=xml_link.text)
def test_link_without_text(self): self._test_one_element( Paragraph([Link(uri="https://www.wikipedia.de", text=None)]), '<paragraph><link uri="https://www.wikipedia.de" /></paragraph>')
def test_link_with_text(self): self._test_one_element( Paragraph([Link(uri="https://www.wikipedia.de", text="Wikipedia")]), '<paragraph><link uri="https://www.wikipedia.de">Wikipedia</link></paragraph>' )