alignments.append('center') elif hyphens.startswith(':'): alignments.append('left') elif hyphens.endswith(':'): alignments.append('right') else: alignments.append('') return alignments # ------------------------------------------------------------------------------------------------------------------ @staticmethod def prune_whitespace(row): """ Strips whitespaces from the text of an each cell. :param list[str] row: The row with text of an each cell. :rtype: list[str] """ clear_row = [] for item in row: clear_text = item.strip() clear_text = re.sub(r'\s+', ' ', clear_text) clear_row.append(clear_text) return clear_row # ---------------------------------------------------------------------------------------------------------------------- NodeStore.register_block_command('table', TableNode)
# ------------------------------------------------------------------------------------------------------------------ @staticmethod def level_up(numbers): """ Increments the level of hierarchy. :param dict[str,str] numbers: The number of last node. """ if 'item' in numbers: numbers['item'] += '.0' else: numbers['item'] = '0' # ------------------------------------------------------------------------------------------------------------------ def number(self, numbers): """ Passing over all child nodes, for numeration. :param dict[str,str] numbers: The number of last node. """ self.level_up(numbers) super().number(numbers) numbers['item'] = self.level_down(numbers['item']) # ---------------------------------------------------------------------------------------------------------------------- NodeStore.register_block_command('itemize', ItemizeNode)
# ------------------------------------------------------------------------------------------------------------------ @staticmethod def __check_document_info(info_node_current, info_node_new): """ Checks if a document info node has been set already. If so, an error will be logged. :param int|None info_node_current: The current document info node (i.e. a property of the document). :param sdoc.sdoc2.node.Node.Node info_node_new: The (new) document info node. """ if info_node_current: node = in_scope(info_node_current) position = node.position out_scope(node) NodeStore.error("Document info {0} can be specified only once. Previous definition at {1}.".format( info_node_new.name, str(position)), info_node_new) # ------------------------------------------------------------------------------------------------------------------ def __remove_document_info_nodes(self): """ Removes the nodes with document info from the list of child nodes. """ obsolete_node_ids = [self.date_node_id, self.title_node_id, self.version_node_id] obsolete_node_ids = [node_id for node_id in obsolete_node_ids if node_id is not None] self._remove_child_nodes(obsolete_node_ids) # ---------------------------------------------------------------------------------------------------------------------- NodeStore.register_block_command('document', DocumentNode)
Checks if a document info node has been set already. If so, an error will be logged. :param int|None info_node_current: The current document info node (i.e. a property of the document). :param Node info_node_new: The (new) document info node. """ if info_node_current: node = in_scope(info_node_current) position = node.position out_scope(node) NodeStore.error( "Document info {0} can be specified only once. Previous definition at {1}." .format(info_node_new.name, str(position)), info_node_new) # ------------------------------------------------------------------------------------------------------------------ def __remove_document_info_nodes(self): """ Removes the nodes with document info from the list of child nodes. """ obsolete_node_ids = [ self.date_node_id, self.title_node_id, self.version_node_id ] obsolete_node_ids = [ node_id for node_id in obsolete_node_ids if node_id is not None ] self._remove_child_nodes(obsolete_node_ids) # ---------------------------------------------------------------------------------------------------------------------- NodeStore.register_block_command('document', DocumentNode)
def is_block_command(self): """ Returns False. :rtype: bool """ return False # ------------------------------------------------------------------------------------------------------------------ def is_inline_command(self): """ Returns True. :rtype: bool """ return False # ------------------------------------------------------------------------------------------------------------------ def is_phrasing(self): """ Returns True. :rtype: bool """ return True # ---------------------------------------------------------------------------------------------------------------------- NodeStore.register_block_command('unknown', UnknownNode) NodeStore.register_inline_command('unknown', UnknownNode)
""" Returns the command of this node, i.e. unknown. """ return 'unknown' # ------------------------------------------------------------------------------------------------------------------ def is_block_command(self) -> bool: """ Returns False. """ return False # ------------------------------------------------------------------------------------------------------------------ def is_inline_command(self) -> bool: """ Returns True. """ return False # ------------------------------------------------------------------------------------------------------------------ def is_phrasing(self) -> bool: """ Returns True. """ return True # ---------------------------------------------------------------------------------------------------------------------- NodeStore.register_block_command('unknown', UnknownNode) NodeStore.register_inline_command('unknown', UnknownNode)
# ------------------------------------------------------------------------------------------------------------------ @staticmethod def level_up(numbers: Dict[str, str]) -> None: """ Increments the level of hierarchy. :param dict[str,str] numbers: The number of last node. """ if 'item' in numbers: numbers['item'] += '.0' else: numbers['item'] = '0' # ------------------------------------------------------------------------------------------------------------------ def number(self, numbers: Dict[str, str]) -> None: """ Passing over all child nodes, for numeration. :param dict[str,str] numbers: The number of last node. """ self.level_up(numbers) super().number(numbers) numbers['item'] = self.level_down(numbers['item']) # ---------------------------------------------------------------------------------------------------------------------- NodeStore.register_block_command('itemize', ItemizeNode)
# ------------------------------------------------------------------------------------------------------------------ @staticmethod def _increment_last_level(enumerable_numbers): """ Increments the last level of figures enumeration. :param dict[str,str] enumerable_numbers: The current numbers of enumerable nodes. """ heading_numbers = enumerable_numbers['figures'].split('.') heading_numbers[-1] = str(int(heading_numbers[-1]) + 1) enumerable_numbers['figures'] = '.'.join(heading_numbers) # ------------------------------------------------------------------------------------------------------------------ def number(self, enumerable_numbers): """ Sets the number of this figure node. :param dict[str,str] enumerable_numbers: The current numbers of enumerable nodes. """ self._get_numeration(enumerable_numbers) self._increment_last_level(enumerable_numbers) self._options['number'] = enumerable_numbers['figures'] super().number(enumerable_numbers) # ---------------------------------------------------------------------------------------------------------------------- NodeStore.register_block_command('figure', FigureNode)