本文整理汇总了Python中pandocfilters.RawInline方法的典型用法代码示例。如果您正苦于以下问题:Python pandocfilters.RawInline方法的具体用法?Python pandocfilters.RawInline怎么用?Python pandocfilters.RawInline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandocfilters
的用法示例。
在下文中一共展示了pandocfilters.RawInline方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_link
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawInline [as 别名]
def convert_link(key, val, fmt, meta):
if key == 'Link':
target = val[2][0]
# Links to other notebooks
m = re.match(r'(\d+\-.+)\.ipynb$', target)
if m:
return RawInline('tex', 'Chapter \\ref{sec:%s}' % m.group(1))
# Links to sections of this or other notebooks
m = re.match(r'(\d+\-.+\.ipynb)?#(.+)$', target)
if m:
# pandoc automatically makes labels for headings.
label = m.group(2).lower()
label = re.sub(r'[^\w-]+', '', label) # Strip HTML entities
return RawInline('tex', 'Section \\ref{%s}' % label)
# Other elements will be returned unchanged.
示例2: resolve_one_reference
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawInline [as 别名]
def resolve_one_reference(key, val, fmt, meta):
"""
This takes a tuple of arguments that are compatible with ``pandocfilters.walk()`` that
allows identifying hyperlinks in the document and transforms them into valid LaTeX
\\ref{} calls so that linking to headers between cells is possible.
See the documentation in ``pandocfilters.walk()`` for further information on the meaning
and specification of ``key``, ``val``, ``fmt``, and ``meta``.
"""
if key == 'Link':
target = val[2][0]
m = re.match(r'#(.+)$', target)
if m:
# pandoc automatically makes labels for headings.
label = m.group(1).lower()
label = re.sub(r'[^\w-]+', '', label) # Strip HTML entities
return RawInline('tex', r'Section \ref{%s}' % label)
# Other elements will be returned unchanged.
示例3: _adjust_caption
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawInline [as 别名]
def _adjust_caption(fmt, table, value):
"""Adjusts the caption."""
attrs, caption = table['attrs'], table['caption']
num = references[attrs.id].num
if fmt in['latex', 'beamer']: # Append a \label if this is referenceable
if not table['is_unreferenceable']:
value[1] += [RawInline('tex', r'\label{%s}'%attrs.id)]
else: # Hard-code in the caption name and number/tag
sep = {'none':'', 'colon':':', 'period':'.', 'space':' ',
'quad':u'\u2000', 'newline':'\n'}[separator]
if isinstance(num, int): # Numbered reference
if fmt in ['html', 'html5', 'epub', 'epub2', 'epub3']:
value[1] = [RawInline('html', r'<span>'),
Str(captionname), Space(),
Str('%d%s'%(num, sep)),
RawInline('html', r'</span>')]
else:
value[1] = [Str(captionname),
Space(),
Str('%d%s'%(num, sep))]
value[1] += [Space()] + list(caption)
else: # Tagged reference
assert isinstance(num, STRTYPES)
if num.startswith('$') and num.endswith('$'):
math = num.replace(' ', r'\ ')[1:-1]
els = [Math({"t":"InlineMath", "c":[]}, math), Str(sep)]
else: # Text
els = [Str(num + sep)]
if fmt in ['html', 'html5', 'epub', 'epub2', 'epub3']:
value[1] = \
[RawInline('html', r'<span>'),
Str(captionname),
Space()] + els + [RawInline('html', r'</span>')]
else:
value[1] = [Str(captionname), Space()] + els
value[1] += [Space()] + list(caption)
示例4: _adjust_caption
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawInline [as 别名]
def _adjust_caption(fmt, fig, value):
"""Adjusts the caption."""
attrs, caption = fig['attrs'], fig['caption']
if fmt in ['latex', 'beamer']: # Append a \label if this is referenceable
if PANDOCVERSION < '1.17' and not fig['is_unreferenceable']:
# pandoc >= 1.17 installs \label for us
value[0]['c'][1] += \
[RawInline('tex', r'\protect\label{%s}'%attrs.id)]
else: # Hard-code in the caption name and number/tag
if fig['is_unnumbered']:
return
sep = {'none':'', 'colon':':', 'period':'.', 'space':' ',
'quad':u'\u2000', 'newline':'\n'}[separator]
num = targets[attrs.id].num
if isinstance(num, int): # Numbered target
if fmt in ['html', 'html5', 'epub', 'epub2', 'epub3']:
value[0]['c'][1] = [RawInline('html', r'<span>'),
Str(captionname), Space(),
Str('%d%s' % (num, sep)),
RawInline('html', r'</span>')]
else:
value[0]['c'][1] = [Str(captionname),
Space(),
Str('%d%s' % (num, sep))]
value[0]['c'][1] += [Space()] + list(caption)
else: # Tagged target
if num.startswith('$') and num.endswith('$'): # Math
math = num.replace(' ', r'\ ')[1:-1]
els = [Math({"t":"InlineMath", "c":[]}, math), Str(sep)]
else: # Text
els = [Str(num+sep)]
if fmt in ['html', 'html5', 'epub', 'epub2', 'epub3']:
value[0]['c'][1] = \
[RawInline('html', r'<span>'),
Str(captionname),
Space()] + els + [RawInline('html', r'</span>')]
else:
value[0]['c'][1] = [Str(captionname), Space()] + els
value[0]['c'][1] += [Space()] + list(caption)
示例5: _add_markup
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawInline [as 别名]
def _add_markup(fmt, eq, value):
"""Adds markup to the output."""
attrs = eq['attrs']
# Context-dependent output
if eq['is_unnumbered']: # Unnumbered is also unreferenceable
ret = None
elif fmt in ['latex', 'beamer']:
ret = RawInline('tex',
r'\begin{equation}%s\end{equation}'%value[-1])
elif fmt in ('html', 'html5', 'epub', 'epub2', 'epub3') and \
LABEL_PATTERN.match(attrs.id):
# Present equation and its number in a span
num = str(references[attrs.id].num)
outer = RawInline('html',
'<span%sclass="eqnos">' % \
(' ' if eq['is_unreferenceable'] else
' id="%s" '%attrs.id))
inner = RawInline('html', '<span class="eqnos-number">')
eqno = Math({"t":"InlineMath"}, '(%s)' % num[1:-1]) \
if num.startswith('$') and num.endswith('$') \
else Str('(%s)' % num)
endtags = RawInline('html', '</span></span>')
ret = [outer, AttrMath(*value), inner, eqno, endtags]
elif fmt == 'docx':
# As per http://officeopenxml.com/WPhyperlink.php
bookmarkstart = \
RawInline('openxml',
'<w:bookmarkStart w:id="0" w:name="%s"/><w:r><w:t>'
%attrs.id)
bookmarkend = \
RawInline('openxml',
'</w:t></w:r><w:bookmarkEnd w:id="0"/>')
ret = [bookmarkstart, AttrMath(*value), bookmarkend]
return ret
示例6: latex
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawInline [as 别名]
def latex(s):
return RawInline('latex', s)
示例7: latex
# 需要导入模块: import pandocfilters [as 别名]
# 或者: from pandocfilters import RawInline [as 别名]
def latex(code):
"""LaTeX inline"""
return RawInline('latex', code)