mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6967 from tk0miya/6966_graphviz_class
Close #6966: graphviz: Support ``:class:`` option
This commit is contained in:
commit
9656b6d4dd
1
CHANGES
1
CHANGES
@ -26,6 +26,7 @@ Features added
|
||||
* #6446: duration: Add ``sphinx.ext.durations`` to inspect which documents slow
|
||||
down the build
|
||||
* #6837: LaTeX: Support a nested table
|
||||
* #6966: graphviz: Support ``:class:`` option
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
@ -82,6 +82,13 @@ It adds these directives:
|
||||
|
||||
.. versionadded:: 1.6
|
||||
|
||||
.. rst:directive:option:: class: class names
|
||||
:type: a list of class names separeted by spaces
|
||||
|
||||
The class name of the graph.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
|
||||
|
||||
.. rst:directive:: graph
|
||||
|
||||
@ -131,6 +138,13 @@ It adds these directives:
|
||||
|
||||
.. versionadded:: 1.6
|
||||
|
||||
.. rst:directive:option:: class: class names
|
||||
:type: a list of class names separeted by spaces
|
||||
|
||||
The class name of the graph.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
|
||||
|
||||
.. rst:directive:: digraph
|
||||
|
||||
@ -176,6 +190,13 @@ It adds these directives:
|
||||
|
||||
.. versionadded:: 1.6
|
||||
|
||||
.. rst:directive:option:: class: class names
|
||||
:type: a list of class names separeted by spaces
|
||||
|
||||
The class name of the graph.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
|
||||
|
||||
There are also these config values:
|
||||
|
||||
|
@ -121,6 +121,7 @@ class Graphviz(SphinxDirective):
|
||||
'layout': directives.unchanged,
|
||||
'graphviz_dot': directives.unchanged, # an old alias of `layout` option
|
||||
'name': directives.unchanged,
|
||||
'class': directives.class_option,
|
||||
}
|
||||
|
||||
def run(self) -> List[Node]:
|
||||
@ -158,6 +159,8 @@ class Graphviz(SphinxDirective):
|
||||
node['alt'] = self.options['alt']
|
||||
if 'align' in self.options:
|
||||
node['align'] = self.options['align']
|
||||
if 'class' in self.options:
|
||||
node['classes'] = self.options['class']
|
||||
|
||||
if 'caption' not in self.options:
|
||||
self.add_name(node)
|
||||
@ -182,6 +185,7 @@ class GraphvizSimple(SphinxDirective):
|
||||
'caption': directives.unchanged,
|
||||
'graphviz_dot': directives.unchanged,
|
||||
'name': directives.unchanged,
|
||||
'class': directives.class_option,
|
||||
}
|
||||
|
||||
def run(self) -> List[Node]:
|
||||
@ -195,6 +199,8 @@ class GraphvizSimple(SphinxDirective):
|
||||
node['alt'] = self.options['alt']
|
||||
if 'align' in self.options:
|
||||
node['align'] = self.options['align']
|
||||
if 'class' in self.options:
|
||||
node['classes'] = self.options['class']
|
||||
|
||||
if 'caption' not in self.options:
|
||||
self.add_name(node)
|
||||
@ -267,10 +273,8 @@ def render_dot_html(self: HTMLTranslator, node: graphviz, code: str, options: Di
|
||||
logger.warning(__('dot code %r: %s'), code, exc)
|
||||
raise nodes.SkipNode
|
||||
|
||||
if imgcls:
|
||||
imgcls += " graphviz"
|
||||
else:
|
||||
imgcls = "graphviz"
|
||||
classes = [imgcls, 'graphviz'] + node.get('classes', [])
|
||||
imgcls = ' '.join(filter(None, classes))
|
||||
|
||||
if fname is None:
|
||||
self.body.append(self.encode(code))
|
||||
|
@ -14,8 +14,9 @@ Hello |graph| graphviz world
|
||||
|
||||
.. digraph:: foo
|
||||
:graphviz_dot: neato
|
||||
:class: neato_graph
|
||||
|
||||
bar -> baz
|
||||
baz -> qux
|
||||
|
||||
|
||||
.. graphviz:: graph.dot
|
||||
|
@ -29,8 +29,9 @@ def test_graphviz_png_html(app, status, warning):
|
||||
html = 'Hello <div class="graphviz"><img .*?/></div>\n graphviz world'
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
html = '<img src=".*?" alt="digraph {\n bar -> baz\n}" class="graphviz" />'
|
||||
assert re.search(html, content, re.M)
|
||||
html = ('<img src=".*?" alt="digraph foo {\nbaz -> qux\n}" '
|
||||
'class="graphviz neato-graph" />')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
html = (r'<div class="figure align-right" .*?>\s*'
|
||||
r'<div class="graphviz"><img .*?/></div>\s*<p class="caption">'
|
||||
|
Loading…
Reference in New Issue
Block a user