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