本文整理汇总了Python中pandocfilters.RawBlock方法的典型用法代码示例。如果您正苦于以下问题:Python pandocfilters.RawBlock方法的具体用法?Python pandocfilters.RawBlock怎么用?Python pandocfilters.RawBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandocfilters
的用法示例。
在下文中一共展示了pandocfilters.RawBlock方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insert_rawblocks_factory
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawBlock [as 别名]
def insert_rawblocks_factory(rawblocks):
r"""Returns insert_rawblocks(key, value, fmt, meta) action that inserts
non-duplicate RawBlock elements.
"""
# pylint: disable=unused-argument
def insert_rawblocks(key, value, fmt, meta):
"""Inserts non-duplicate RawBlock elements."""
if not rawblocks:
return None
# Put the RawBlock elements in front of the first block element that
# isn't also a RawBlock.
if not key in ['Plain', 'Para', 'CodeBlock', 'RawBlock',
'BlockQuote', 'OrderedList', 'BulletList',
'DefinitionList', 'Header', 'HorizontalRule',
'Table', 'Div', 'Null']:
return None
if key == 'RawBlock': # Remove duplicates
rawblock = RawBlock(*value)
if rawblock in rawblocks:
rawblocks.remove(rawblock)
return None
if rawblocks: # Insert blocks
el = _getel(key, value)
return [rawblocks.pop(0) for i in range(len(rawblocks))] + [el]
return None
return insert_rawblocks
示例2: latexblock
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawBlock [as 别名]
def latexblock(code):
"""LaTeX block"""
return RawBlock('latex', code)
示例3: htmlblock
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawBlock [as 别名]
def htmlblock(code):
"""Html block"""
return RawBlock('html', code)
示例4: latex
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawBlock [as 别名]
def latex(x):
return RawBlock('latex', x)
示例5: html
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawBlock [as 别名]
def html(x):
return RawBlock('html', x)
示例6: _add_markup
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawBlock [as 别名]
def _add_markup(fmt, table, value):
"""Adds markup to the output."""
# pylint: disable=global-statement
global has_tagged_tables # Flags a tagged tables was found
if table['is_unnumbered']:
if fmt in ['latex', 'beamer']:
# Use the no-prefix-table-caption environment
return [RawBlock('tex',
r'\begin{tablenos:no-prefix-table-caption}'),
Table(*(value if len(value) == 5 else value[1:])),
RawBlock('tex', r'\end{tablenos:no-prefix-table-caption}')]
return None # Nothing to do
attrs = table['attrs']
ret = None
if fmt in ['latex', 'beamer']:
if table['is_tagged']: # A table cannot be tagged if it is unnumbered
has_tagged_tables = True
ret = [RawBlock('tex', r'\begin{tablenos:tagged-table}[%s]' % \
references[attrs.id].num),
AttrTable(*value),
RawBlock('tex', r'\end{tablenos:tagged-table}')]
elif fmt in ('html', 'html5', 'epub', 'epub2', 'epub3'):
if LABEL_PATTERN.match(attrs.id):
# Enclose table in hidden div
pre = RawBlock('html', '<div id="%s" class="tablenos">'%attrs.id)
post = RawBlock('html', '</div>')
ret = [pre, AttrTable(*value), post]
elif fmt == 'docx':
# As per http://officeopenxml.com/WPhyperlink.php
bookmarkstart = \
RawBlock('openxml',
'<w:bookmarkStart w:id="0" w:name="%s"/>'
%attrs.id)
bookmarkend = \
RawBlock('openxml', '<w:bookmarkEnd w:id="0"/>')
ret = [bookmarkstart, AttrTable(*value), bookmarkend]
return ret
# pylint: disable=unused-argument, too-many-return-statements
示例7: add_to_header_includes
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawBlock [as 别名]
def add_to_header_includes(meta, fmt, block, warninglevel=None, regex=None):
"""Adds `block` to header-includes field of `meta`. The block is
encapsulated in a pandoc RawBlock.
Parameters:
meta - the document metadata
fmt - the format of the block (tex, html, ...)
block - the block of text to add to the header-includes
warninglevel - DEPRECATED (set global WARNINGLEVEL instead)
regex - a regular expression used to check existing header-includes
in the document metadata for overlap
"""
# Set the global warning level (DEPRECATED)
# pylint: disable=global-statement
global _WARNINGLEVEL
assert(warninglevel is None or isinstance(warninglevel, int))
if warninglevel is not None:
_WARNINGLEVEL = warninglevel
# If pattern is found in the meta-includes then bail out
if regex and 'header-includes' in meta:
pattern = re.compile(regex)
if pattern.search(str(meta['header-includes'])):
return
# Create the rawblock and install it in the header-includes
block = textwrap.dedent(block)
rawblock = {'t': 'RawBlock', 'c': [fmt, block]}
metablocks = {'t': 'MetaBlocks', 'c': [rawblock]}
if 'header-includes' not in meta:
meta['header-includes'] = metablocks
elif meta['header-includes']['t'] in ['MetaBlocks', 'MetaInlines']:
meta['header-includes'] = \
{'t': 'MetaList', 'c': [meta['header-includes'], metablocks]}
elif meta['header-includes']['t'] == 'MetaList':
meta['header-includes']['c'].append(metablocks)
else:
msg = textwrap.dedent("""\
header-includes metadata cannot be parsed:
%s
""" % str(meta['header-includes']))
raise RuntimeError(msg)
# Print the block to stderr at warning level 2
if _WARNINGLEVEL == 2:
if hasattr(textwrap, 'indent'):
STDERR.write(textwrap.indent(block, ' '))
else:
STDERR.write('\n'.join(' ' + line for line in block.split('\n')))
STDERR.flush()
# cleveref_required() --------------------------------------------------------
示例8: _add_markup
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawBlock [as 别名]
def _add_markup(fmt, fig, value):
"""Adds markup to the output."""
# pylint: disable=global-statement
global has_tagged_figures # Flags a tagged figure was found
if fig['is_unnumbered']:
if fmt in ['latex', 'beamer']:
# Use the no-prefix-figure-caption environment
return [RawBlock('tex', r'\begin{fignos:no-prefix-figure-caption}'),
Para(value),
RawBlock('tex', r'\end{fignos:no-prefix-figure-caption}')]
return None # Nothing to do
attrs = fig['attrs']
ret = None
if fmt in ['latex', 'beamer']:
if fig['is_tagged']: # A figure cannot be tagged if it is unnumbered
# Use the tagged-figure environment
has_tagged_figures = True
ret = [RawBlock('tex', r'\begin{fignos:tagged-figure}[%s]' % \
str(targets[attrs.id].num)),
Para(value),
RawBlock('tex', r'\end{fignos:tagged-figure}')]
elif fmt in ('html', 'html5', 'epub', 'epub2', 'epub3'):
if LABEL_PATTERN.match(attrs.id):
pre = RawBlock('html', '<div id="%s" class="fignos">'%attrs.id)
post = RawBlock('html', '</div>')
ret = [pre, Para(value), post]
# Eliminate the id from the Image
attrs.id = ''
value[0]['c'][0] = attrs.list
elif fmt == 'docx':
# As per http://officeopenxml.com/WPhyperlink.php
bookmarkstart = \
RawBlock('openxml',
'<w:bookmarkStart w:id="0" w:name="%s"/>'
%attrs.id)
bookmarkend = \
RawBlock('openxml', '<w:bookmarkEnd w:id="0"/>')
ret = [bookmarkstart, Para(value), bookmarkend]
return ret