def render_enumerated_list( self, obj, key_format, internal_format, sort_order, ordinal_base, inner_list_types, inner_key_formats, inner_internal_formats, inner_sort_orders, inner_ordinal_bases, ): m = re.match(ENUMERATOR_PATTERN, key_format) if m is None: raise self.error("Invalid {} {} for {}".format( KEY_FORMATS_OPTION, key_format, "bullet")) # We instantiate this docutils state-machine state just so we leverage methods defined on it # which allows us to maintain consistency with the core docutils behaviour body = Body(None) fmt, sequence, text, start = body.parse_enumerator(m) list_node = nodes.enumerated_list() if sequence == "#": list_node["enumtype"] = "arabic" else: list_node["enumtype"] = sequence list_node["prefix"] = body.enum.formatinfo[fmt].prefix list_node["suffix"] = body.enum.formatinfo[fmt].suffix if start != 1: list_node["start"] = start child_ordinals, child_keys, child_values, child_nodes = self.render_child_nodes( obj, sort_order, ordinal_base, inner_list_types, inner_key_formats, inner_internal_formats, inner_sort_orders, inner_ordinal_bases, ) list_node["bullet"] = key_format for ordinal, key, value, child_node in zip(child_ordinals, child_keys, child_values, child_nodes): list_item_node = nodes.list_item() header_text = internal_format.format(o=ordinal, k=key, v=value) if header_text and not header_text.isspace(): list_item_node += nodes.paragraph(text=header_text) list_node += list_item_node list_item_node += child_node return list_node
def wideformat(): state = Body(RSTStateMachine([], None)) state.build_table = Mock() lineno = 1 source = '' options = {} app = None return wide_format.WideFormat(state, lineno, source, options, app)
def build_table(self, tabledata, tableline, stub_columns: int = 0, widths=None): return Body.build_table(self, tabledata, tableline, stub_columns, widths)
def wideformat(): state = Body(RSTStateMachine(None, None)) #state = Mock() lineno = 1 app = None return wide_format.WideFormat(state, lineno, app)
def visit_enumerated_list(self, node): enumtype = node['enumtype'] fmt = { ('(', ')'): 'parens', ('', ')'): 'rparen', ('', '.'): 'period' }[node['prefix'], node['suffix']] try: start = node['start'] except KeyError: start = 1 else: start = { 'arabic': int, 'loweralpha': lambda s: ord(s) - ord('a') + 1, 'upperalpha': lambda s: ord(s) - ord('A') + 1, 'lowerroman': lambda s: roman.fromRoman(s.upper()), 'upperroman': lambda s: roman.fromRoman(s), }[enumtype](start) enumerators = [ Body(None).make_enumerator(i, enumtype, fmt)[0] for i in range(start, start + len(node)) ] width = max(map(len, enumerators)) enumerators = [enum.ljust(width) for enum in enumerators] self._indent_iterator_stack.append(iter(enumerators))
def visit_enumerated_list(self, node): enumtype = node['enumtype'] fmt = {('(', ')'): 'parens', ('', ')'): 'rparen', ('', '.'): 'period'}[node['prefix'], node['suffix']] start = node.get('start', 1) enumerators = [Body(None).make_enumerator(i, enumtype, fmt)[0] for i in range(start, start + len(node))] width = max(map(len, enumerators)) enumerators = [enum.ljust(width) for enum in enumerators] self._indent_iterator_stack.append(iter(enumerators))
def build_table_row(self, rowdata, tableline): return Body.build_table_row(self, rowdata, tableline)