Commit 58108e8c authored by Ingo Heimbach's avatar Ingo Heimbach

Merge branch 'develop'

parents d67ad02b 6928f538
__version_info__ = (0, 2, 4)
__version_info__ = (0, 3, 0)
__version__ = '.'.join(map(str, __version_info__))
......@@ -6,7 +6,10 @@ import os
import shutil
import subprocess
import tempfile
import urlparse
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
import sys
from io import BytesIO
from PIL import Image
......@@ -25,7 +28,7 @@ OUT_PNG_FILENAME = "_converted_image{i:04d}.png"
def is_url(url):
return urlparse.urlparse(url).scheme not in ("", "file")
return urlparse(url).scheme not in ("", "file")
def load_and_convert_image(
......
......@@ -49,6 +49,7 @@ TMP_PNG_FILENAME = "tikz_picture.png"
OUT_PNG_FILENAME = "_tikz_rendered{:04d}.png"
TMP_SVG_FILENAME = "tikz_picture.svg"
OUT_SVG_FILENAME = "_tikz_rendered{:04d}.svg"
BUILD_DIRECTORY = '.'
class TemporaryDirectory(object):
......@@ -142,7 +143,7 @@ def convert_image_to_html_base64(image_filepath):
if filetype == "svg":
filetype = "svg+xml"
with open(image_filepath.encode(sys.getfilesystemencoding()), "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
return "data:image/{format};base64,".format(format=filetype) + encoded_string
......@@ -193,7 +194,9 @@ class Tikz(Directive):
rendered_tikz_filename = render_tikz("\n".join(content), self.options, output_svg=is_output_mode_html)
if is_output_mode_html:
reference = directives.uri(convert_image_to_html_base64(rendered_tikz_filename))
os.remove(rendered_tikz_filename)
else:
shutil.move(rendered_tikz_filename, os.path.join(BUILD_DIRECTORY, os.path.basename(rendered_tikz_filename)))
reference = directives.uri(rendered_tikz_filename)
self.options["uri"] = reference
if is_output_mode_html and not any(attr in self.options for attr in ("height", "width", "scale")):
......
from . import directives
from .directives import tikz_directive
def setup(app):
tikz_directive.BUILD_DIRECTORY = app.outdir
app.add_directive('tikz', directives.Tikz)
app.connect('builder-inited', lambda app: directives.set_output_mode(app.builder.format))
return {'version': '0.1'}
......@@ -56,7 +56,7 @@ setup(
name="docutils-extended",
version=version,
packages=find_packages(),
python_requires=">=2.7, <3",
python_requires=">=2.7",
install_requires=install_requires,
entry_points={
"console_scripts": [
......@@ -80,7 +80,7 @@ setup(
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2 :: Only",
"Programming Language :: Python :: 3",
"Topic :: Documentation",
"Topic :: Software Development :: Documentation",
],
......
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