本文整理匯總了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'])