Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def plain_output(text: str, pandoc_format: str="markdown",
pandoc_extra_args: list=None, pandoc: bool=False) -> list:
if pandoc:
return tokenize_block(text, pandoc_format, pandoc_extra_args)
else:
return [Div(['', ['output'], []], [CodeBlock(['', [], []], text)])]
def plain_output(text: str, pandoc_extra_args: list=None, pandoc: bool=False) -> list:
if pandoc:
return tokenize_block(text, pandoc_extra_args)
else:
return [Div(['', ['output'], []], [CodeBlock(['', [], []], text)])]
def image(self):
'returns documentation in a CodeBlock'
# CodeBlock value = [(Identity, [classes], [(key, val)]), code]
if not self.code:
return pf.CodeBlock(('', [], []), __doc__)
elif self.code == 'classes':
classes = wrap(', '.join(sorted(Handler.workers.keys())), 78)
return pf.CodeBlock(('', [], []), '\n'.join(classes))
doc = []
for name in self.code.splitlines():
name = name.lower()
worker = self.workers.get(name, None)
doc.append("Codeblock class: " + name)
if worker is None:
doc.append('No worker found for %s' % name)
continue
if worker.__doc__:
doc.append(worker.__doc__)
doc.append(" runs:")
doc.append(' > ' + worker.image.__doc__)
else:
doc.append('No help available.')
def image(self):
'returns documentation in a CodeBlock'
# CodeBlock value = [(Identity, [classes], [(key, val)]), code]
if not self.code:
return pf.CodeBlock(('', [], []), __doc__)
elif self.code == 'classes':
classes = wrap(', '.join(sorted(Handler.workers.keys())), 78)
return pf.CodeBlock(('', [], []), '\n'.join(classes))
doc = []
for name in self.code.splitlines():
name = name.lower()
worker = self.workers.get(name, None)
doc.append("Codeblock class: " + name)
if worker is None:
doc.append('No worker found for %s' % name)
continue
if worker.__doc__:
doc.append(worker.__doc__)
doc.append(" runs:")
doc.append(' > ' + worker.image.__doc__)
else:
msg = '?? missing %s' % self.outfile
self.msg(1, msg)
rv.append(pf.Para([pf.Str(msg)]))
elif output_elm == 'fcb':
rv.append(self.anon_codeblock())
elif output_elm == 'ocb':
attr = ['', self.classes, self.keyvals]
rv.append(pf.CodeBlock(attr, self.codec[1]))
elif output_elm == 'stdout':
if self.stdout:
attr = ['', self.classes, self.keyvals]
rv.append(pf.CodeBlock(attr, to_str(self.stdout, enc)))
else:
self.msg(1, 'stdout requested, but saw nothing')
elif output_elm == 'stderr':
if self.stderr:
attr = ['', self.classes, self.keyvals]
rv.append(pf.CodeBlock(attr, to_str(self.stderr, enc)))
else:
self.msg(1, 'stderr requested, but saw nothing')
if not rv:
return None # no results; None keeps original FCB
if len(rv) > 1:
return rv # multiple results
return rv[0] # just 1 block level element
def code_include(key, value, format, meta):
if key == 'CodeBlock':
[[ident, classes, namevals], code] = value
for nameval in namevals:
if nameval[0] == 'include':
with open(nameval[1], 'rb') as content_file:
content = content_file.read()
content.decode('utf-8')
namevals.remove(nameval)
return CodeBlock([ident, classes, namevals], content)
for k,v in self.md_opts.items():
if k not in self.workers:
glob_opts.append(" imagine.{}: {}".format(k,v))
else: # elif k == name:
for kk,vv in self.md_opts.get(name, {}).items():
klass_opts.append(" imagine.{}.{}: {}".format(k,
kk,vv))
if klass_opts or glob_opts:
doc.append("\nMetadata options")
# doc.append(" ---")
doc.extend(glob_opts + klass_opts)
# doc.append(" ...")
doc.append('\n')
return pf.CodeBlock(('', [], []), '\n'.join(doc))
enc = sys.getdefaultencoding() # result always unicode
for output_elm in self.im_out:
if output_elm == 'img':
if os.path.isfile(self.outfile):
rv.append(pf.Para([self.url()]))
else:
msg = '?? missing %s' % self.outfile
self.msg(1, msg)
rv.append(pf.Para([pf.Str(msg)]))
elif output_elm == 'fcb':
rv.append(self.anon_codeblock())
elif output_elm == 'ocb':
attr = ['', self.classes, self.keyvals]
rv.append(pf.CodeBlock(attr, self.codec[1]))
elif output_elm == 'stdout':
if self.stdout:
attr = ['', self.classes, self.keyvals]
rv.append(pf.CodeBlock(attr, to_str(self.stdout, enc)))
else:
self.msg(1, 'stdout requested, but saw nothing')
elif output_elm == 'stderr':
if self.stderr:
attr = ['', self.classes, self.keyvals]
rv.append(pf.CodeBlock(attr, to_str(self.stderr, enc)))
else:
self.msg(1, 'stderr requested, but saw nothing')
if not rv:
def anon_codeblock(self):
'reproduce the original CodeBlock inside an anonymous CodeBlock'
(id_, klasses, keyvals), code = self.codec
id_ = '#' + id_ if id_ else id_
klasses = ' '.join('.%s' % c for c in klasses)
keyvals = ' '.join('%s="%s"' % (k, v) for k, v in keyvals)
attr = '{%s}' % ' '.join(a for a in [id_, klasses, keyvals] if a)
# prefer ```cmd over ```{.cmd}
attr = attr if attr.find(' ') > -1 else attr[2:-1]
codeblock = '```%s\n%s\n```' % (attr, code)
return pf.CodeBlock(['', [], []], codeblock)