Commit 12662d50 authored by Ingo Meyer's avatar Ingo Meyer

Merge branch 'develop'

parents 617af609 0bbcc5e2
__version_info__ = (0, 2, 0)
__version_info__ = (0, 2, 1)
__version__ = '.'.join(map(str, __version_info__))
from .code_directive import CodeBlock
from .embedded_image_directive import EmbeddedImage
from .jupyter_outbox_directive import JupyterOutbox
from .tikz_directive import Tikz, TikzFigure
from .output_mode import get_output_mode, set_output_mode
__all__ = ("CodeBlock", "EmbeddedImage", "Tikz", "TikzFigure", "get_output_mode", "set_output_mode")
__all__ = ("CodeBlock", "EmbeddedImage", "JupyterOutbox", "Tikz", "TikzFigure", "get_output_mode", "set_output_mode")
......@@ -19,6 +19,7 @@ from .output_mode import get_output_mode
TMP_IMAGE_FILENAME = "_downloaded_image{i:04d}.{ext}"
TMP_QPDF_OUT_FILENAME = "_qpdf_out.pdf"
OUT_PDF_FILENAME = "_converted_image{i:04d}.pdf"
......@@ -65,6 +66,14 @@ def load_and_convert_image(image_filepath_or_url, convert_to_base64=True, conver
stdout=devnull,
stderr=devnull,
)
try:
subprocess.check_call(
["qpdf", out_pdf_filename, TMP_QPDF_OUT_FILENAME], stdout=devnull, stderr=devnull
)
os.remove(out_pdf_filename)
shutil.move(TMP_QPDF_OUT_FILENAME, out_pdf_filename)
except subprocess.CalledProcessError:
pass
image_filepath = out_pdf_filename
image_is_svg = False
image_is_pdf = True
......
from docutils import nodes
from docutils.parsers.rst import Directive
class JupyterOutbox(Directive):
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = False
option_spec = {}
has_content = True
def run(self):
content = u"\n".join(self.content)
latex = u"\\begin{{minted}}[bgcolor=white,breakanywhere=true,breaklines=true,linenos=false]{{text}}\n{}\n\\end{{minted}}".format(content)
return [nodes.raw("", latex, format="latex")]
......@@ -18,6 +18,7 @@ except:
from docutils.core import publish_cmdline, default_description
from docutils.parsers.rst import directives
from docutils.parsers.rst.directives.body import ParsedLiteral
from ..directives import EmbeddedImage, Tikz, TikzFigure, set_output_mode
......@@ -27,6 +28,7 @@ description = "Generates (X)HTML documents from standalone reStructuredText " "s
def main():
set_output_mode("html")
directives.register_directive("embedded-image", EmbeddedImage)
directives.register_directive("jupyter-outbox", ParsedLiteral)
directives.register_directive("tikz", Tikz)
directives.register_directive("tikz-figure", TikzFigure)
publish_cmdline(writer_name="html", description=description)
......
......@@ -19,7 +19,7 @@ except:
from docutils.core import publish_cmdline
from docutils.parsers.rst import directives
from ..directives import CodeBlock, EmbeddedImage, Tikz, TikzFigure, set_output_mode
from ..directives import CodeBlock, EmbeddedImage, JupyterOutbox, Tikz, TikzFigure, set_output_mode
description = (
......@@ -37,6 +37,7 @@ def main():
for directive_name in ("code", "code-block"):
directives.register_directive(directive_name, CodeBlock)
directives.register_directive("embedded-image", EmbeddedImage)
directives.register_directive("jupyter-outbox", JupyterOutbox)
directives.register_directive("tikz", Tikz)
directives.register_directive("tikz-figure", TikzFigure)
publish_cmdline(writer_name="latex", description=description)
......
......@@ -78,3 +78,9 @@
\makeatother
\end{titlepage}
}
\IfFileExists{custom.sty}{%
\usepackage{custom}
}
}{%
}
......@@ -97,3 +97,8 @@
\makeatother
\end{titlepage}
}
\IfFileExists{custom.sty}{%
\usepackage{custom}
}{%
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment