本文整理汇总了Python中docutils.nodes.table方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.table方法的具体用法?Python nodes.table怎么用?Python nodes.table使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.nodes
的用法示例。
在下文中一共展示了nodes.table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: autosummary_table_visit_html
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def autosummary_table_visit_html(self, node):
"""Make the first column of the table non-breaking."""
try:
tbody = node[0][0][-1]
for row in tbody:
col1_entry = row[0]
par = col1_entry[0]
for j, subnode in enumerate(list(par)):
if isinstance(subnode, nodes.Text):
new_text = text_type(subnode.astext())
new_text = new_text.replace(u" ", u"\u00a0")
par[j] = nodes.Text(new_text)
except IndexError:
pass
# -- autodoc integration -------------------------------------------------------
示例2: process
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def process(self, doctree):
for node in doctree.traverse(cfgconfig):
config = node.config
context = node.context
options = self.domain.config_options[config]
if self.builder.config.cfg_options_summary is None:
new_content = []
elif len(options) == 0:
new_content = [nodes.Text("[No options defined for this config]")]
elif self.builder.config.cfg_options_summary == "table":
new_content = self.create_summary_table(config, context, options)
elif self.builder.config.cfg_options_summary == "list":
new_content = [self.create_option_reference(o, config, context) for o in options]
if len(new_content) > 1:
listnode = nodes.bullet_list()
for entry in new_content:
listnode += nodes.list_item('', entry)
new_content = [listnode]
else:
raise ValueError("unknown value for config option `cfg_options_summary`.")
node.replace_self(new_content)
示例3: setup
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def setup(app):
app.add_event('cfg_options-parse_config')
app.add_config_value('cfg_options_recursive_includes', True, 'html')
app.add_config_value('cfg_options_parse_numpydoc_style_options', True, 'html')
app.add_config_value('cfg_options_parse_comma_sep_names', False, 'html')
app.add_config_value('cfg_options_summary', "table", 'html')
app.add_config_value('cfg_options_table_add_header', True, 'html')
app.add_config_value('cfg_options_default_in_summary_table', True, 'html')
app.add_config_value('cfg_options_unique', True, 'html')
app.add_config_value('cfg_options_always_include', [], 'html')
app.add_domain(CfgDomain)
app.add_node(cfgconfig)
app.connect('doctree-resolved', ConfigNodeProcessor)
StandardDomain.initial_data['labels']['cfg-config-index'] =\
('cfg-config', '', 'Config Index')
StandardDomain.initial_data['labels']['cfg-option-index'] =\
('cfg-option', '', 'Config-Options Index')
return {'version': '0.1'}
示例4: get_column_widths
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def get_column_widths(self, max_cols):
if type(self.widths) == list:
if len(self.widths) != max_cols:
error = self.state_machine.reporter.error(
'"%s" widths do not match the number of columns in table '
'(%s).' % (self.name, max_cols), nodes.literal_block(
self.block_text, self.block_text), line=self.lineno)
raise SystemMessagePropagation(error)
col_widths = self.widths
elif max_cols:
col_widths = [100 // max_cols] * max_cols
else:
error = self.state_machine.reporter.error(
'No table data detected in CSV file.', nodes.literal_block(
self.block_text, self.block_text), line=self.lineno)
raise SystemMessagePropagation(error)
if self.widths == 'auto':
widths = 'auto'
elif self.widths: # "grid" or list of integers
widths = 'given'
else:
widths = self.widths
return widths, col_widths
示例5: table
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def table(self, isolate_function, parser_class):
"""Parse a table."""
block, messages, blank_finish = isolate_function()
if block:
try:
parser = parser_class()
tabledata = parser.parse(block)
tableline = (self.state_machine.abs_line_number() - len(block)
+ 1)
table = self.build_table(tabledata, tableline)
nodelist = [table] + messages
except tableparser.TableMarkupError as err:
nodelist = self.malformed_table(block, ' '.join(err.args),
offset=err.offset) + messages
else:
nodelist = messages
return nodelist, blank_finish
示例6: build_table
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def build_table(self, tabledata, tableline, stub_columns=0, widths=None):
colwidths, headrows, bodyrows = tabledata
table = nodes.table()
if widths:
table['classes'] += ['colwidths-%s' % widths]
tgroup = nodes.tgroup(cols=len(colwidths))
table += tgroup
for colwidth in colwidths:
colspec = nodes.colspec(colwidth=colwidth)
if stub_columns:
colspec.attributes['stub'] = 1
stub_columns -= 1
tgroup += colspec
if headrows:
thead = nodes.thead()
tgroup += thead
for row in headrows:
thead += self.build_table_row(row, tableline)
tbody = nodes.tbody()
tgroup += tbody
for row in bodyrows:
tbody += self.build_table_row(row, tableline)
return table
示例7: visit_paragraph
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def visit_paragraph(self, node):
# insert blank line, unless
# * the paragraph is first in a list item,
# * follows a non-paragraph node in a compound,
# * is in a table with auto-width columns
index = node.parent.index(node)
if (index == 0 and (isinstance(node.parent, nodes.list_item) or
isinstance(node.parent, nodes.description))):
pass
elif (index > 0 and isinstance(node.parent, nodes.compound) and
not isinstance(node.parent[index - 1], nodes.paragraph) and
not isinstance(node.parent[index - 1], nodes.compound)):
pass
elif self.active_table.colwidths_auto:
if index == 1: # second paragraph
self.warn('LaTeX merges paragraphs in tables '
'with auto-sized columns!', base_node=node)
if index > 0:
self.out.append('\n')
else:
self.out.append('\n')
if node.get('ids'):
self.out += self.ids_to_labels(node) + ['\n']
if node['classes']:
self.visit_inline(node)
示例8: visit_table
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def visit_table(self, node):
self.requirements['table'] = PreambleCmds.table
if self.active_table.is_open():
self.table_stack.append(self.active_table)
# nesting longtable does not work (e.g. 2007-04-18)
self.active_table = Table(self,'tabular')
# A longtable moves before \paragraph and \subparagraph
# section titles if it immediately follows them:
if (self.active_table._latex_type == 'longtable' and
isinstance(node.parent, nodes.section) and
node.parent.index(node) == 1 and
self.d_class.section(self.section_level).find('paragraph') != -1):
self.out.append('\\leavevmode')
self.active_table.open()
self.active_table.set_table_style(self.settings.table_style,
node['classes'])
if 'align' in node:
self.active_table.set('align', node['align'])
if self.active_table.borders == 'booktabs':
self.requirements['booktabs'] = r'\usepackage{booktabs}'
self.push_output_collector([])
示例9: get_column_widths
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def get_column_widths(self, max_cols):
if type(self.widths) == list:
if len(self.widths) != max_cols:
error = self.state_machine.reporter.error(
'"%s" widths do not match the number of columns in table '
'(%s).' % (self.name, max_cols), nodes.literal_block(
self.block_text, self.block_text), line=self.lineno)
raise SystemMessagePropagation(error)
col_widths = self.widths
elif max_cols:
col_widths = [100 // max_cols] * max_cols
else:
error = self.state_machine.reporter.error(
'No table data detected in CSV file.', nodes.literal_block(
self.block_text, self.block_text), line=self.lineno)
raise SystemMessagePropagation(error)
return col_widths
示例10: build_table
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def build_table(self, tabledata, tableline, stub_columns=0, widths=None):
colwidths, headrows, bodyrows = tabledata
table = nodes.table()
if widths == 'auto':
table['classes'] += ['colwidths-auto']
elif widths: # "grid" or list of integers
table['classes'] += ['colwidths-given']
tgroup = nodes.tgroup(cols=len(colwidths))
table += tgroup
for colwidth in colwidths:
colspec = nodes.colspec(colwidth=colwidth)
if stub_columns:
colspec.attributes['stub'] = 1
stub_columns -= 1
tgroup += colspec
if headrows:
thead = nodes.thead()
tgroup += thead
for row in headrows:
thead += self.build_table_row(row, tableline)
tbody = nodes.tbody()
tgroup += tbody
for row in bodyrows:
tbody += self.build_table_row(row, tableline)
return table
示例11: visit_paragraph
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def visit_paragraph(self, node):
# insert blank line, unless
# * the paragraph is first in a list item or compound,
# * follows a non-paragraph node in a compound,
# * is in a table with auto-width columns
index = node.parent.index(node)
if index == 0 and isinstance(node.parent,
(nodes.list_item, nodes.description, nodes.compound)):
pass
elif (index > 0 and isinstance(node.parent, nodes.compound) and
not isinstance(node.parent[index - 1], nodes.paragraph) and
not isinstance(node.parent[index - 1], nodes.compound)):
pass
elif self.active_table.colwidths_auto:
if index == 1: # second paragraph
self.warn('LaTeX merges paragraphs in tables '
'with auto-sized columns!', base_node=node)
if index > 0:
self.out.append('\n')
else:
self.out.append('\n')
if node.get('ids'):
self.out += self.ids_to_labels(node) + ['\n']
if node['classes']:
self.visit_inline(node)
示例12: prepare_table_header
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def prepare_table_header(titles, widths):
"""Build docutil empty table """
ncols = len(titles)
assert len(widths) == ncols
tgroup = nodes.tgroup(cols=ncols)
for width in widths:
tgroup += nodes.colspec(colwidth=width)
header = nodes.row()
for title in titles:
header += nodes.entry("", nodes.paragraph(text=title))
tgroup += nodes.thead("", header)
tbody = nodes.tbody()
tgroup += tbody
return nodes.table("", tgroup), tbody
示例13: models_table
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def models_table(self, species):
table = nodes.table()
tgroup = nodes.tgroup(cols=2)
for _ in range(2):
colspec = nodes.colspec(colwidth=1)
tgroup.append(colspec)
table += tgroup
thead = nodes.thead()
tgroup += thead
row = nodes.row()
entry = nodes.entry()
entry += nodes.paragraph(text="ID")
row += entry
entry = nodes.entry()
entry += nodes.paragraph(text="Description")
row += entry
thead.append(row)
rows = []
for model in species.demographic_models:
row = nodes.row()
rows.append(row)
mid = self.get_demographic_model_id(species, model)
entry = nodes.entry()
para = nodes.paragraph()
entry += para
para += nodes.reference(internal=True, refid=mid, text=model.id)
row += entry
entry = nodes.entry()
entry += nodes.paragraph(text=model.description)
row += entry
tbody = nodes.tbody()
tbody.extend(rows)
tgroup += tbody
return table
示例14: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def run(self):
index, desc = super().run()
assert isinstance(desc, addnodes.desc)
desc_content = desc[1]
assert isinstance(desc_content, addnodes.desc_content)
return desc_content.children[1:] #don't include the summary table/list/reference
示例15: create_summary_table
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import table [as 别名]
def create_summary_table(self, config, context, options):
default_column = self.builder.config.cfg_options_default_in_summary_table
table_spec = addnodes.tabular_col_spec()
table = nodes.table("", classes=["longtable"])
if default_column:
table_spec['spec'] = r'\X{1}{4}\X{1}{4}\X{2}{4}'
group = nodes.tgroup('', cols=3)
group.append(nodes.colspec('', colwidth=20))
group.append(nodes.colspec('', colwidth=20))
group.append(nodes.colspec('', colwidth=60))
else:
table_spec['spec'] = r'\X{1}{4}\X{2}{4}'
group = nodes.tgroup('', cols=2)
group.append(nodes.colspec('', colwidth=25))
group.append(nodes.colspec('', colwidth=75))
table.append(group)
if self.builder.config.cfg_options_table_add_header:
header = nodes.thead('')
group.append(header)
row = nodes.row()
row += nodes.entry("", nodes.Text("option"))
if default_column:
row += nodes.entry("", nodes.Text("default"))
row += nodes.entry("", nodes.Text("summary"))
header.append(row)
body = nodes.tbody('')
group.append(body)
for opt in options:
body += self.create_option_reference_table_row(opt, config, context)
return [table_spec, table]