Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
doc-utils
doc-utils
Commits
58108e8c
Commit
58108e8c
authored
Jul 02, 2019
by
Ingo Meyer
Browse files
Merge branch 'develop'
parents
d67ad02b
6928f538
Changes
5
Hide whitespace changes
Inline
Side-by-side
docutils_extended/_version.py
View file @
58108e8c
__version_info__
=
(
0
,
2
,
4
)
__version_info__
=
(
0
,
3
,
0
)
__version__
=
'.'
.
join
(
map
(
str
,
__version_info__
))
docutils_extended/directives/embedded_image_directive.py
View file @
58108e8c
...
...
@@ -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
(
...
...
docutils_extended/directives/tikz_directive.py
View file @
58108e8c
...
...
@@ -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"
)):
...
...
docutils_extended/sphinx_extension.py
0 → 100644
View file @
58108e8c
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'
}
setup.py
View file @
58108e8c
...
...
@@ -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"
,
],
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment