Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
src = Para(createListStr(u'Exercise +.#'))
dest = Para([
Span(
[u'exercise:2.2', ['pandoc-numbering-text', 'exercise'], []],
[Strong(createListStr(u'Exercise 2.2'))]
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
src = Para([Str(u'Exercise'), Space(), Str(u'#')])
dest = Para([
Span(
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
[Strong(createListStr(u'Exercise 1'))]
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
and so on.
"""
out = []
join_to_out = getattr(out, method)
join_to_out(items[0])
if len(items) == 1:
return out
for item in items[1: -1]:
out.append(pf.Str(', '))
join_to_out(item)
out.append(pf.Str(' and '))
join_to_out(items[-1])
return out
# we are saving to filesystem
ext = mimetypes.guess_extension(key)
filepath = os.path.join(self.resource_dir,
"{}{}".format(chunk_name, ext))
os.makedirs(self.resource_dir, exist_ok=True)
if ext == '.svg':
with open(filepath, 'wt', encoding='utf-8') as f:
f.write(data)
else:
with open(filepath, 'wb') as f:
f.write(base64.decodebytes(data.encode('utf-8')))
# Image :: alt text (list of inlines), target
# Image :: Attr [Inline] Target
# Target :: (string, string) of (URL, title)
block = Para([Image([chunk_name, [], []],
[Str(caption)],
[filepath, "fig: {}".format(chunk_name)])])
return block
RawInline('html', r'')]
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)
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',
'' % \
(' ' 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>')
ret = [outer, AttrMath(*value), inner, eqno, endtags]
elif fmt == 'docx':
# As per http://officeopenxml.com/WPhyperlink.php
bookmarkstart = \
RawInline('openxml',
''
%attrs.id)
bookmarkend = \
RawInline('openxml',
'')
ret = [bookmarkstart, AttrMath(*value), bookmarkend]
return ret
def join_items(items, method='append', call=pf.Str):
"""Join the list of items together in the format
'item[0]' if len(items) == 1
'item[0] and item[1]' if len(items) == 2
'item[0], item[1] and item[2]' if len(items) == 3
and so on.
"""
out = []
join_to_out = getattr(out, method)
join_to_out(items[0])
if len(items) == 1:
return out
def links(key, value, format, meta):
if key == 'Link':
[_, title, target] = value
if (is_absolute(target[0])):
# citation = [{"citationSuffix" : [],
# "citationNoteNum" : 0,
# "citationMode" : {"t":"NormalCitation"},
# "citationPrefix" : [],
# "citationId" : target[0],
# "citationHash" : 0}]
# return Cite(citation, title)
return Span(attributes({}),
[Str(u'\u201c'), Span(attributes({}), title), Str(u'\u201d'),
Space(), Str('('), Str(target[0]), Str(')')])
else:
[_, _, targetInternal] = target[0].rpartition('#')
citation = [{"citationSuffix" : [],
"citationNoteNum" : 0,
"citationMode" : {"t":"NormalCitation"},
"citationPrefix" : [],
"citationId" : targetInternal,
"citationHash" : 0}]
return Cite(citation, [Str("[@{0}]".format(targetInternal))])
def section_replacement(self, key, value, format, metadata):
"""Replace sections with appropriate representation.
"""
level, attr, text = value
label, classes, kvs = attr
if 'unnumbered' in classes:
pretext = ''
else:
ref = self.references[label]
pretext = '{}: '.format(ref['id'])
pretext = [pf.Str(pretext)]
if format in ('html', 'html5', 'markdown'):
return pf.Header(level, attr, pretext + text)
elif format == 'latex':
# have to do this to get rid of hyperref
return pf.Header(level, attr, text)
else:
return pf.Header(level, attr, pretext + text)
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'])