Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if re.search("@bibitem", value):
title, desc, date, url = value.split(":", 1)[1].split(", ")
inline = r"\bibitem{" + title + "} " + desc
inline += r" \textsl{" + date + "}."
inline2 = 'latex', r"\url{" + url + "}"
type_ = 'latex'
return [RawInline(type_, inline), LineBreak(), RawInline(inline2)]
elif key == 'Image':
[attrs, caption, src] = value
new_capt = src[0]
# add \label{IMAGE_LABEL} to the picture description
new_desc = "\\" + "label{" + new_capt + "}"
caption.append(RawInline('latex', new_desc))
return Image(attrs, caption, src)
def transform_key(k):
# fig.width -> width, fig.height -> height;
return k.split('fig.', 1)[-1]
attrs = [(transform_key(k), v)
for k, v in attrs.items()
if transform_key(k) in image_keys]
if self.self_contained:
if 'png' in key:
data = 'data:image/png;base64,{}'.format(data)
elif 'svg' in key:
data = 'data:image/svg+xml;base64,{}'.format(b64_encode(data))
if 'png' in key or 'svg' in key:
block = Para([Image([chunk_name, [], attrs],
[Str(caption)],
[data, ""])])
else:
raise TypeError("Unknown mimetype %s" % key)
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') as f:
f.write(data)
else:
with open(filepath, 'wb') as f:
f.write(base64.decodebytes(data.encode('utf-8')))
f.write(txt)
subprocess.check_call(PLANTUML_BIN.split() +
["-t" + filetype, src])
sys.stderr.write('Created image ' + dest + '\n')
# Update symlink each run
for ind, keyval in enumerate(keyvals):
if keyval[0] == 'plantuml-filename':
link = keyval[1]
keyvals.pop(ind)
rel_mkdir_symlink(dest, link)
dest = link
break
return Para([Image([ident, [], keyvals], caption, [dest, typef])])
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') 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
p = Popen(["whereis", "plantuml"], stderr=PIPE, stdout=PIPE)
(stdout, stderr) = p.communicate()
sys.stderr.write(stdout.decode())
sys.stderr.write(stderr.decode())
p = Popen(["plantuml", "-t" + filetype, src], stderr=PIPE, stdout=PIPE)
(stdout, stderr) = p.communicate()
if stderr.decode() != "":
sys.stderr.write("WARNING: failed to run plantuml: " + stderr.decode() + "\n")
else:
sys.stderr.write("Created image %s\n" % dest)
#call(["plantuml", "-t"+filetype, src])
#sys.stderr.write('Created image ' + dest + '\n')
return Para([Image([ident, [], keyvals], title, [dest, typef])])
attr.classes.insert(0, 'figure')
if format in self.formats:
figure = self.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])
def url(self):
'return an image link for existing/new output image-file'
# pf.Image is an Inline element. Callers usually wrap it in a pf.Para
return pf.Image([self.id_, self.classes, self.keyvals],
self.caption, [self.outfile, self.typef])
with open(src, "wb") as f:
f.write(txt)
# Default command to execute
cmd = [MERMAID_BIN, "-i", src, "-o", dest]
if PUPPETEER_CFG is not None:
cmd.extend(["-p", PUPPETEER_CFG])
if os.path.isfile('.puppeteer.json'):
cmd.extend(["-p", ".puppeteer.json"])
subprocess.check_call(cmd)
sys.stderr.write('Created image ' + dest + '\n')
return Para([Image([ident, [], keyvals], caption, [dest, typef])])