本文整理汇总了Python中sdoc.sdoc2.NodeStore.NodeStore类的典型用法代码示例。如果您正苦于以下问题:Python NodeStore类的具体用法?Python NodeStore怎么用?Python NodeStore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_numbering
def set_numbering(self):
"""
Sets the numbering status to the heading node.
"""
if 'numbering' in self._options:
if self._options['numbering'] == 'off':
self.numbering = False
elif self._options['numbering'] == 'on':
self.numbering = True
else:
NodeStore.error("Invalid value '{}' for attribute 'numbering'. Allowed values are 'on' and 'off'.".
format(self._options['numbering']), self)
示例2: __check_document_info
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)
示例3: generate
def generate(self, node, file):
"""
Generates the HTML code for an icon node.
:param sdoc.sdoc2.node.IconNode.IconNode node: The icon node.
:param file file: The output file.
"""
attributes = IconNode.get_definition(node.argument)
if attributes:
img_element = Html.generate_void_element('img', attributes)
file.write(img_element)
else:
NodeStore.error("There is no definition for icon with name '{}'".format(node.argument), node)
示例4: _generate_table_cell
def _generate_table_cell(align, col):
"""
Returns the 'column' with HTML data.
:param mixed col: The column in a table.
:rtype: str
"""
attributes = {}
if align:
attributes['style'] = "text-align: {0}".format(align)
if isinstance(col, str):
data = col
is_html = False
else:
# Generates html in nested node ('col') with specified formatter.
formatter = NodeStore.get_formatter('html', col.get_command())
data = formatter.get_html(col)
is_html = True
return Html.generate_element('td', attributes, data, is_html)
示例5: is_block_command
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)
示例6: level_up
# ------------------------------------------------------------------------------------------------------------------
@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)
示例7: is_inline_command
def is_inline_command(self):
"""
Returns True.
:rtype: bool
"""
return True
# ------------------------------------------------------------------------------------------------------------------
def generate_toc(self):
"""
Generates the table of contents.
"""
self._options['ids'] = []
for node in node_store.nodes.values():
if not isinstance(node, ParagraphNode) and isinstance(node, HeadingNode):
node.set_toc_id()
data = {'id': node.get_option_value('id'),
'arg': node.argument,
'level': node.get_hierarchy_level(),
'number': node.get_option_value('number'),
'numbering': node.numbering}
self._options['ids'].append(data)
# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('toc', TocNode)
示例8: generate
HtmlFormatter for generating HTML code for smile.
"""
# ------------------------------------------------------------------------------------------------------------------
def generate(self, node, file):
"""
Generates the HTML code for a smile node.
:param sdoc.sdoc2.node.SmileNode.SmileNode node: The smile node.
:param file file: The output file.
"""
file.write(SmileHtmlFormatter.get_html(node))
HtmlFormatter.generate(self, node, file)
# ------------------------------------------------------------------------------------------------------------------
@staticmethod
def get_html(node):
"""
Returns string with generated HTML tag.
:param sdoc.sdoc2.node.SmileNode.SmileNode node: The smile node.
:rtype: str
"""
return Html.generate_element('b', {}, 'SMILE')
# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('smile', 'html', SmileHtmlFormatter)
示例9: prune_whitespace
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)
示例10: in_scope
:param sdoc.sdoc2.node.DocumentNode.DocumentNode node: The document node.
:param file file: The output file.
"""
file.write('<div class="sdoc-document-title-outer">')
if node.title_node_id:
title_node = in_scope(node.title_node_id)
file.write(Html.generate_element('h1', {}, title_node.argument))
out_scope(title_node)
file.write('<div class="sdoc-document-title-inner">')
if node.date_node_id:
date_node = in_scope(node.date_node_id)
if date_node.argument:
file.write(Html.generate_element('span', {'class': 'sdoc-document-date'}, date_node.argument))
out_scope(date_node)
if node.version_node_id:
version_node = in_scope(node.version_node_id)
if version_node.argument:
file.write(Html.generate_element('span', {'class': 'sdoc-document-version'}, version_node.argument))
out_scope(version_node)
file.write('</div>')
file.write('</div>')
# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('document', 'html', DocumentHtmlFormatter)
示例11: write_elements
TocHtmlFormatter.write_elements(item, file)
elif not depth:
TocHtmlFormatter.write_elements(item, file)
# ------------------------------------------------------------------------------------------------------------------
@staticmethod
def write_elements(item, file):
"""
Write the containing elements.
:param dict[str,str] item: The item which we outputs.
:param file file: The output file.
"""
class_attr = 'level{}'.format(item['level'])
file.write(Html.generate_tag('li', {'class': class_attr}))
file.write(Html.generate_tag('a', {'href': '#{}'.format(item['id'])}))
number = item['number'] if item['numbering'] else None
if number:
file.write(Html.generate_element('span', {}, str(number)))
file.write(' {}'.format(item['arg']))
file.write('</a>')
file.write('</li>')
# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('toc', 'html', TocHtmlFormatter)
示例12: HyperlinkHtmlFormatter
class HyperlinkHtmlFormatter(HtmlFormatter):
"""
HtmlFormatter for generating HTML code for hyperlinks.
"""
# ------------------------------------------------------------------------------------------------------------------
def generate(self, node, file):
"""
Generates the HTML code for a hyperlink node.
:param sdoc.sdoc2.node.HyperlinkNode.HyperlinkNode node: The hyperlink node.
:param file file: The output file.
"""
file.write(HyperlinkHtmlFormatter.get_html(node))
# ------------------------------------------------------------------------------------------------------------------
@staticmethod
def get_html(node):
"""
Returns string with generated HTML tag.
:param sdoc.sdoc2.node.HyperlinkNode.HyperlinkNode node: The hyperlink node.
:rtype: str
"""
return Html.generate_element('a', node.get_html_attributes(), node.argument)
# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('hyperlink', 'html', HyperlinkHtmlFormatter)
示例13: get_command
# ------------------------------------------------------------------------------------------------------------------
def get_command(self):
"""
Returns the command of this node, i.e. caption.
:rtype: str
"""
return 'caption'
# ------------------------------------------------------------------------------------------------------------------
def is_block_command(self):
"""
Returns False.
:rtype: bool
"""
return False
# ------------------------------------------------------------------------------------------------------------------
def is_inline_command(self):
"""
Returns True.
:rtype: bool
"""
return True
# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('caption', CaptionNode)
示例14: is_block_command
# ------------------------------------------------------------------------------------------------------------------
def is_block_command(self):
"""
Returns False.
:rtype: bool
"""
return False
# ------------------------------------------------------------------------------------------------------------------
def is_inline_command(self):
"""
Returns True.
:rtype: bool
"""
return True
# ------------------------------------------------------------------------------------------------------------------
def is_phrasing(self):
"""
Returns True.
:rtype: bool
"""
return True
# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_inline_command('version', VersionNode)
示例15: ParagraphHtmlFormatter
Copyright 2016 Set Based IT Consultancy
Licence MIT
"""
# ----------------------------------------------------------------------------------------------------------------------
from sdoc.sdoc2.NodeStore import NodeStore
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
class ParagraphHtmlFormatter(HtmlFormatter):
"""
HtmlFormatter for generating HTML code for paragraph.
"""
# ------------------------------------------------------------------------------------------------------------------
def generate(self, node, file):
"""
Generates the HTML code for a paragraph node.
:param sdoc.sdoc2.node.ParagraphNode.ParagraphNode node: The paragraph node.
:param file file: The output file.
"""
file.write('<p>')
HtmlFormatter.generate(self, node, file)
file.write('</p>')
# ----------------------------------------------------------------------------------------------------------------------
NodeStore.register_formatter('paragraph', 'html', ParagraphHtmlFormatter)