Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_numbering_prefix_single():
init()
src = Para(createListStr(u'Exercise #ex:'))
dest = Para([
Span(
[u'ex:1', ['pandoc-numbering-text', 'ex'], []],
[Strong(createListStr(u'Exercise 1'))]
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
src = Para(createListStr(u'Exercise #'))
dest = Para([
Span(
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
[Strong(createListStr(u'Exercise 1'))]
)
])
def test_numbering_sectioning_map_error():
init()
meta = getMeta3()
sectioning(meta)
src = Para(createListStr(u'Exercise #'))
dest = Para([
Span(
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
[Strong(createListStr(u'Exercise 1'))]
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], '', meta) == dest
def test_numbering_sectioning_map():
init()
meta = getMeta2()
sectioning(meta)
src = Para([Str(u'Exercise'), Space(), Str(u'#')])
dest = Para([
Span(
[u'exercise:2.2.1', ['pandoc-numbering-text', 'exercise'], []],
[Strong(createListStr(u'Exercise 2.1'))]
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], '', meta) == dest
def test_numbering_prefix_single():
init()
src = Para(createListStr(u'Exercise #ex:'))
dest = Para([
Span(
[u'ex:1', ['pandoc-numbering-text', 'ex'], []],
[Strong(createListStr(u'Exercise 1'))]
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
src = Para(createListStr(u'Exercise #'))
dest = Para([
Span(
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
[Strong(createListStr(u'Exercise 1'))]
)
])
def tbl_contents(s):
result = []
for row in s:
para = []
for col in row:
if col:
para.extend(col[0]['c'])
para.append(inlatex(' & '))
result.extend(para)
result[-1] = inlatex(r'\\' '\n')
return pf.Para(result)
def tbl_headers(s):
#print(s, s[0], len(s), file=sys.stderr)
if s[0]:
start = 1
result = s[0][0]['c'][:]
else:
start = 2
result = s[1][0]['c'][:]
for i in range(start, len(s)):
result.append(inlatex(' & '))
result.extend(s[i][0]['c'])
result.append(inlatex(r' \\\midrule'))
return pf.Para(result)
else:
# 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
def _add_markup(fmt, fig, value):
"""Adds markup to the output."""
# pylint: disable=global-statement
global has_tagged_figures # Flags a tagged figure was found
if fig['is_unnumbered']:
if fmt in ['latex', 'beamer']:
# Use the no-prefix-figure-caption environment
return [RawBlock('tex', r'\begin{fignos:no-prefix-figure-caption}'),
Para(value),
RawBlock('tex', r'\end{fignos:no-prefix-figure-caption}')]
return None # Nothing to do
attrs = fig['attrs']
ret = None
if fmt in ['latex', 'beamer']:
if fig['is_tagged']: # A figure cannot be tagged if it is unnumbered
# Use the tagged-figure environment
has_tagged_figures = True
ret = [RawBlock('tex', r'\begin{fignos:tagged-figure}[%s]' % \
str(targets[attrs.id].num)),
Para(value),
RawBlock('tex', r'\end{fignos:tagged-figure}')]
elif fmt in ('html', 'html5', 'epub', 'epub2', 'epub3'):
if LABEL_PATTERN.match(attrs.id):
if format in self.formats:
figure = figure_styles[format].format(attr=attr,
filename=filename,
alt=fcaption,
fcaption=fcaption,
caption=caption,
star=star).encode('utf-8')
return RawBlock(format, figure)
else:
alt = [pf.Str(fcaption)]
target = (filename, '')
image = pf.Image(alt, target)
figure = pf.Para([image])
return pf.Div(attr.to_pandoc(), [figure])