mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
`sphinx.ext.graphviz
` supports graph substituions by locale
This commit is contained in:
parent
3f0843bca0
commit
0636d54f6f
@ -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')
|
||||
|
3
tests/roots/test-ext-graphviz/graph.dot
Normal file
3
tests/roots/test-ext-graphviz/graph.dot
Normal file
@ -0,0 +1,3 @@
|
||||
digraph {
|
||||
bar -> baz
|
||||
}
|
3
tests/roots/test-ext-graphviz/graph.xx.dot
Normal file
3
tests/roots/test-ext-graphviz/graph.xx.dot
Normal file
@ -0,0 +1,3 @@
|
||||
digraph {
|
||||
BAR -> BAZ
|
||||
}
|
@ -16,3 +16,6 @@ Hello |graph| graphviz world
|
||||
:graphviz_dot: neato
|
||||
|
||||
bar -> baz
|
||||
|
||||
|
||||
.. graphviz:: graph.dot
|
||||
|
@ -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 -> 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 -> BAZ\n}" />'
|
||||
assert re.search(html, content, re.M)
|
||||
|
Loading…
Reference in New Issue
Block a user