本文整理汇总了Python中pandocfilters.Span方法的典型用法代码示例。如果您正苦于以下问题:Python pandocfilters.Span方法的具体用法?Python pandocfilters.Span怎么用?Python pandocfilters.Span使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandocfilters
的用法示例。
在下文中一共展示了pandocfilters.Span方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: join_strings
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Span [as 别名]
def join_strings(key, value, fmt=None, meta=None):
"""Joins adjacent Str elements found in `value`."""
if key in ['Para', 'Plain']:
_join_strings(value)
elif key == 'Span':
_join_strings(value, 1)
elif key == 'Image':
_join_strings(value[-2])
elif key == 'Table':
_join_strings(value[-5])
# repair_refs() -------------------------------------------------------------
# Reference pattern. This splits a reference into three components: the
# prefix, label and suffix. e.g.:
# >>> _REF.match('xxx{+@fig:1}xxx').groups()
# ('xxx{+', 'fig:1', '}xxx').
示例2: insert_secnos_factory
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Span [as 别名]
def insert_secnos_factory(f):
"""Returns insert_secnos(key, value, fmt, meta) action that inserts
section numbers into the attributes of elements of type `f`.
"""
# Get the name and standard length
name = f.__closure__[0].cell_contents
n = f.__closure__[1].cell_contents
def insert_secnos(key, value, fmt, meta): # pylint: disable=unused-argument
"""Inserts section numbers into elements attributes."""
global _sec # pylint: disable=global-statement
if key == 'Header':
if 'unnumbered' in value[1][1]:
return
if value[0] == 1:
_sec += 1
if key == name:
# Only insert if attributes are attached. Images always have
# attributes for pandoc >= 1.16. Same for Spans.
assert len(value) <= n+1
if (name == 'Image' and len(value) == 3) or name == 'Div' or \
name == 'Span' or len(value) == n+1:
# Make sure value[0] represents attributes
assert isinstance(value[0][0], STRTYPES)
assert isinstance(value[0][1], list)
assert isinstance(value[0][2], list)
# Insert the section number into the attributes
value[0][2].insert(0, ['secno', _sec])
return insert_secnos
# delete_secnos_factory() ----------------------------------------------------
示例3: delete_secnos_factory
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Span [as 别名]
def delete_secnos_factory(f):
"""Returns delete_secnos(key, value, fmt, meta) action that deletes
section numbers from the attributes of elements of type `f`.
"""
# Get the name and standard length
name = f.__closure__[0].cell_contents
n = f.__closure__[1].cell_contents
def delete_secnos(key, value, fmt, meta): # pylint: disable=unused-argument
"""Deletes section numbers from elements attributes."""
# Only delete if attributes are attached. Images always have
# attributes for pandoc >= 1.16. Same for Spans.
if key == name:
assert len(value) <= n+1
if (name == 'Image' and len(value) == 3) or name == 'Div' or \
name == 'Span' or len(value) == n+1:
# Make sure value[0] represents attributes
assert isinstance(value[0][0], STRTYPES)
assert isinstance(value[0][1], list)
assert isinstance(value[0][2], list)
# Remove the secno attribute
if value[0][2] and value[0][2][0][0] == 'secno':
del value[0][2][0]
return delete_secnos
# install_rawblock_factory() -------------------------------------------------
示例4: metavars
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import Span [as 别名]
def metavars(key, value, format, meta):
if key == 'Str':
m = pattern.match(value)
if m:
field = m.group(1)
result = meta.get(field, {})
if 'MetaInlines' in result['t']:
return Span(attributes({'class': 'interpolated',
'field': field}),
result['c'])
elif 'MetaString' in result[t]:
return Str(result['c'])