def run(self): # type: () -> List[nodes.Node] ncolumns = self.options.get('columns', 2) node = nodes.paragraph() node.document = self.state.document self.state.nested_parse(self.content, self.content_offset, node) if len(node.children) != 1 or not isinstance(node.children[0], nodes.bullet_list): return [ self.state.document.reporter.warning( '.. hlist content is not a list', line=self.lineno) ] fulllist = node.children[0] # create a hlist node where the items are distributed npercol, nmore = divmod(len(fulllist), ncolumns) index = 0 newnode = addnodes.hlist() for column in range(ncolumns): endindex = index + (column < nmore and (npercol + 1) or npercol) col = addnodes.hlistcol() col += nodes.bullet_list() col[0] += fulllist.children[index:endindex] index = endindex newnode += col return [newnode]
def run(self) -> List[Node]: ncolumns = self.options.get('columns', 2) node = nodes.paragraph() node.document = self.state.document self.state.nested_parse(self.content, self.content_offset, node) if len(node.children) != 1 or not isinstance(node.children[0], nodes.bullet_list): reporter = self.state.document.reporter return [ reporter.warning('.. hlist content is not a list', line=self.lineno) ] fulllist = node.children[0] # create a hlist node where the items are distributed npercol, nmore = divmod(len(fulllist), ncolumns) index = 0 newnode = addnodes.hlist() newnode['ncolumns'] = str(ncolumns) for column in range(ncolumns): endindex = index + ((npercol + 1) if column < nmore else npercol) bullet_list = nodes.bullet_list() bullet_list += fulllist.children[index:endindex] newnode += addnodes.hlistcol('', bullet_list) index = endindex return [newnode]
def run(self): ncolumns = self.options.get('columns', 2) node = nodes.paragraph() node.document = self.state.document self.state.nested_parse(self.content, self.content_offset, node) if len(node.children) != 1 or not isinstance(node.children[0], nodes.bullet_list): return [self.state.document.reporter.warning( '.. hlist content is not a list', line=self.lineno)] fulllist = node.children[0] # create a hlist node where the items are distributed npercol, nmore = divmod(len(fulllist), ncolumns) index = 0 newnode = addnodes.hlist() for column in range(ncolumns): endindex = index + (column < nmore and (npercol+1) or npercol) col = addnodes.hlistcol() col += nodes.bullet_list() col[0] += fulllist.children[index:endindex] index = endindex newnode += col return [newnode]
def build_node(self) -> nodes.Node: book_topic = nodes.topic(classes=['book-topic']) book_topic += nodes.target('', '', ids=[self.id]) book_title = nodes.paragraph(text=self.title, classes=['book-title']) if not self.subtitle == '': book_title += nodes.inline(text=': ', classes=['book-punctuation']) book_title += nodes.inline(text=self.subtitle, classes=['book-subtitle']) book_topic += book_title if not self.title_localized == '': book_title_localized = nodes.paragraph( text=self.title_localized, classes=['book-title-localized']) if not self.subtitle_localized == '': book_title_localized += nodes.inline( text=': ', classes=['book-punctuation']) book_title_localized += nodes.inline( text=self.subtitle_localized, classes=['book-subtitle-localized']) book_topic += book_title_localized book_tags = nodes.paragraph(classes=['book-tags-container']) first_space = True for t in self.tags: if first_space: first_space = False if not first_space: book_tags += nodes.inline(text=' ', classes=['book-punctuation']) tag_unique_id = -1 \ if self.domain is None else self.domain.get_tag_unique_id(t.strip()) domain_name = 'problematic' if self.domain is None else self.domain.name current_file_name = 'problematic' \ if self.domain is None else self.domain.env.docname tag_index_file_name = '{}-{}_{}'.format(domain_name, 'tag', tag_unique_id) tag_reference = nodes.reference(internal=True) tag_reference[ 'refuri'] = self.domain.env.app.builder.get_relative_uri( current_file_name, tag_index_file_name) tag_reference += nodes.inline(text=t.strip(), classes=['book-tag']) book_tags += tag_reference book_topic += book_tags book_folder_component = nodes.paragraph( text=self.build_folder_title(), classes=['book-file-component']) book_topic += book_folder_component book_left_bullet_list = nodes.bullet_list(bullet='*') authors_list_item = nodes.list_item() authors_list_item += self.build_node_authors() book_left_bullet_list += authors_list_item book_right_bullet_list = nodes.bullet_list(bullet='*') issues_list_item = nodes.list_item() issues_list_item += self.build_node_issues() book_right_bullet_list += issues_list_item root_hlist = addnodes.hlist() root_hlist += addnodes.hlistcol('', book_left_bullet_list) root_hlist += addnodes.hlistcol('', book_right_bullet_list) book_topic += root_hlist return book_topic