`sphinx.ext.graphviz` supports graph substituions by locale

This commit is contained in:
Takeshi KOMIYA 2016-01-28 22:12:28 +09:00
parent 3f0843bca0
commit 0636d54f6f
5 changed files with 25 additions and 1 deletions

View File

@ -25,6 +25,7 @@ from docutils.statemachine import ViewList
import sphinx
from sphinx.errors import SphinxError
from sphinx.locale import _
from sphinx.util.i18n import search_image_for_language
from sphinx.util.osutil import ensuredir, ENOENT, EPIPE, EINVAL
from sphinx.util.compat import Directive
@ -77,7 +78,8 @@ class Graphviz(Directive):
'Graphviz directive cannot have both content and '
'a filename argument', line=self.lineno)]
env = self.state.document.settings.env
rel_filename, filename = env.relfn2path(self.arguments[0])
argument = search_image_for_language(self.arguments[0], env)
rel_filename, filename = env.relfn2path(argument)
env.note_dependency(rel_filename)
try:
fp = codecs.open(filename, 'r', 'utf-8')

View File

@ -0,0 +1,3 @@
digraph {
bar -> baz
}

View File

@ -0,0 +1,3 @@
digraph {
BAR -> BAZ
}

View File

@ -16,3 +16,6 @@ Hello |graph| graphviz world
:graphviz_dot: neato
bar -> baz
.. graphviz:: graph.dot

View File

@ -52,6 +52,9 @@ def test_graphviz_html(app, status, warning):
html = 'Hello <img .*?/>\n graphviz world'
assert re.search(html, content, re.S)
html = '<img src=".*?" alt="digraph {\n bar -&gt; baz\n}" />'
assert re.search(html, content, re.M)
@with_app('latex', testroot='ext-graphviz')
@skip_if_graphviz_not_found
@ -66,3 +69,13 @@ def test_graphviz_latex(app, status, warning):
macro = 'Hello \\\\includegraphics{graphviz-\w+.pdf} graphviz world'
assert re.search(macro, content, re.S)
@with_app('html', testroot='ext-graphviz', confoverrides={'language': 'xx'})
@skip_if_graphviz_not_found
def test_graphviz_i18n(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'index.html').text()
html = '<img src=".*?" alt="digraph {\n BAR -&gt; BAZ\n}" />'
assert re.search(html, content, re.M)