mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #2113: Allow `:class:
` option to code-block directive
This commit is contained in:
parent
bf1cc70996
commit
4234c88f21
1
CHANGES
1
CHANGES
@ -18,6 +18,7 @@ Features added
|
|||||||
using HTTP basic auth
|
using HTTP basic auth
|
||||||
* C++, added support for template parameter in function info field lists.
|
* C++, added support for template parameter in function info field lists.
|
||||||
* C++, added support for pointers to member (function).
|
* C++, added support for pointers to member (function).
|
||||||
|
* #2113: Allow ``:class:`` option to code-block directive
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -93,6 +93,7 @@ class CodeBlock(Directive):
|
|||||||
'lineno-start': int,
|
'lineno-start': int,
|
||||||
'emphasize-lines': directives.unchanged_required,
|
'emphasize-lines': directives.unchanged_required,
|
||||||
'caption': directives.unchanged_required,
|
'caption': directives.unchanged_required,
|
||||||
|
'class': directives.class_option,
|
||||||
'name': directives.unchanged,
|
'name': directives.unchanged,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,6 +120,7 @@ class CodeBlock(Directive):
|
|||||||
literal['language'] = self.arguments[0]
|
literal['language'] = self.arguments[0]
|
||||||
literal['linenos'] = 'linenos' in self.options or \
|
literal['linenos'] = 'linenos' in self.options or \
|
||||||
'lineno-start' in self.options
|
'lineno-start' in self.options
|
||||||
|
literal['classes'] += self.options.get('class', [])
|
||||||
extra_args = literal['highlight_args'] = {}
|
extra_args = literal['highlight_args'] = {}
|
||||||
if hl_lines is not None:
|
if hl_lines is not None:
|
||||||
extra_args['hl_lines'] = hl_lines
|
extra_args['hl_lines'] = hl_lines
|
||||||
@ -165,6 +167,7 @@ class LiteralInclude(Directive):
|
|||||||
'append': directives.unchanged_required,
|
'append': directives.unchanged_required,
|
||||||
'emphasize-lines': directives.unchanged_required,
|
'emphasize-lines': directives.unchanged_required,
|
||||||
'caption': directives.unchanged,
|
'caption': directives.unchanged,
|
||||||
|
'class': directives.class_option,
|
||||||
'name': directives.unchanged,
|
'name': directives.unchanged,
|
||||||
'diff': directives.unchanged_required,
|
'diff': directives.unchanged_required,
|
||||||
}
|
}
|
||||||
@ -322,6 +325,7 @@ class LiteralInclude(Directive):
|
|||||||
retnode['linenos'] = 'linenos' in self.options or \
|
retnode['linenos'] = 'linenos' in self.options or \
|
||||||
'lineno-start' in self.options or \
|
'lineno-start' in self.options or \
|
||||||
'lineno-match' in self.options
|
'lineno-match' in self.options
|
||||||
|
retnode['classes'] += self.options.get('class', [])
|
||||||
extra_args = retnode['highlight_args'] = {}
|
extra_args = retnode['highlight_args'] = {}
|
||||||
if hl_lines is not None:
|
if hl_lines is not None:
|
||||||
extra_args['hl_lines'] = hl_lines
|
extra_args['hl_lines'] = hl_lines
|
||||||
|
21
tests/roots/test-directive-code/classes.rst
Normal file
21
tests/roots/test-directive-code/classes.rst
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
classes
|
||||||
|
=======
|
||||||
|
|
||||||
|
Code blocks
|
||||||
|
-----------
|
||||||
|
|
||||||
|
.. code-block:: ruby
|
||||||
|
:class: foo bar
|
||||||
|
:name: code_block
|
||||||
|
|
||||||
|
def ruby?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Literal Includes
|
||||||
|
----------------
|
||||||
|
|
||||||
|
.. literalinclude:: literal.inc
|
||||||
|
:class: bar baz
|
||||||
|
:name: literal_include
|
@ -207,3 +207,20 @@ def test_literalinclude_caption_latex(app, status, warning):
|
|||||||
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
|
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
|
||||||
caption = '\\captionof{literal-block}{caption \\textbf{test} py}'
|
caption = '\\captionof{literal-block}{caption \\textbf{test} py}'
|
||||||
assert caption in latex
|
assert caption in latex
|
||||||
|
|
||||||
|
|
||||||
|
@with_app('xml', testroot='directive-code')
|
||||||
|
def test_literalinclude_classes(app, status, warning):
|
||||||
|
app.builder.build(['classes'])
|
||||||
|
et = ElementTree.parse(app.outdir / 'classes.xml')
|
||||||
|
secs = et.findall('./section/section')
|
||||||
|
|
||||||
|
code_block = secs[0].findall('literal_block')
|
||||||
|
assert len(code_block) > 0
|
||||||
|
assert 'foo bar' == code_block[0].get('classes')
|
||||||
|
assert 'code_block' == code_block[0].get('names')
|
||||||
|
|
||||||
|
literalinclude = secs[1].findall('literal_block')
|
||||||
|
assert len(literalinclude) > 0
|
||||||
|
assert 'bar baz' == literalinclude[0].get('classes')
|
||||||
|
assert 'literal_include' == literalinclude[0].get('names')
|
||||||
|
Loading…
Reference in New Issue
Block a user