diff options
author | Takayuki Shimizukawa <shimizukawa+bitbucket@gmail.com> | 2014-08-24 11:02:36 +0900 |
---|---|---|
committer | Takayuki Shimizukawa <shimizukawa+bitbucket@gmail.com> | 2014-08-24 11:02:36 +0900 |
commit | 514e36e733876ff59219e6a594a535921aafb9f9 (patch) | |
tree | 664bc175d55372757afa2ba2ee05a244040570f4 | |
parent | 9f99eab62dc5d40e8302d395a8ca0794445ddc43 (diff) | |
parent | 3b6930d27d18b2fbedc198293f269f62fb46ed60 (diff) | |
download | sphinx-514e36e733876ff59219e6a594a535921aafb9f9.tar.gz |
Merged in tk0miya/sphinx (pull request #266)
Rename :filename: option of code-block directive to :caption:
-rw-r--r-- | sphinx/directives/code.py | 20 | ||||
-rw-r--r-- | sphinx/themes/agogo/static/agogo.css_t | 2 | ||||
-rw-r--r-- | sphinx/themes/basic/static/basic.css_t | 6 | ||||
-rw-r--r-- | sphinx/themes/default/static/default.css_t | 2 | ||||
-rw-r--r-- | sphinx/themes/nature/static/nature.css_t | 2 | ||||
-rw-r--r-- | sphinx/themes/pyramid/static/pyramid.css_t | 2 | ||||
-rw-r--r-- | sphinx/themes/sphinxdoc/static/sphinxdoc.css_t | 2 | ||||
-rw-r--r-- | sphinx/themes/traditional/static/traditional.css_t | 2 | ||||
-rw-r--r-- | sphinx/writers/html.py | 6 | ||||
-rw-r--r-- | sphinx/writers/latex.py | 6 | ||||
-rw-r--r-- | tests/roots/test-directive-code/caption.rst | 21 | ||||
-rw-r--r-- | tests/roots/test-directive-code/index.rst | 1 | ||||
-rw-r--r-- | tests/test_directive_code.py | 42 |
13 files changed, 89 insertions, 25 deletions
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index da7dc0ca..6ea525b0 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -77,7 +77,7 @@ class CodeBlock(Directive): 'dedent': int, 'lineno-start': int, 'emphasize-lines': directives.unchanged_required, - 'filename': directives.unchanged_required, + 'caption': directives.unchanged_required, } def run(self): @@ -101,9 +101,9 @@ class CodeBlock(Directive): literal = nodes.literal_block(code, code) literal['language'] = self.arguments[0] - filename = self.options.get('filename') - if filename: - literal['filename'] = filename + caption = self.options.get('caption') + if caption: + literal['caption'] = caption literal['linenos'] = 'linenos' in self.options or \ 'lineno-start' in self.options extra_args = literal['highlight_args'] = {} @@ -140,7 +140,7 @@ class LiteralInclude(Directive): 'prepend': directives.unchanged_required, 'append': directives.unchanged_required, 'emphasize-lines': directives.unchanged_required, - 'filename': directives.unchanged, + 'caption': directives.unchanged, 'diff': directives.unchanged_required, } @@ -269,11 +269,11 @@ class LiteralInclude(Directive): retnode['language'] = self.options['language'] retnode['linenos'] = 'linenos' in self.options or \ 'lineno-start' in self.options - filename = self.options.get('filename') - if filename is not None: - if not filename: - filename = self.arguments[0] - retnode['filename'] = filename + caption = self.options.get('caption') + if caption is not None: + if not caption: + caption = self.arguments[0] + retnode['caption'] = caption extra_args = retnode['highlight_args'] = {} if hl_lines is not None: extra_args['hl_lines'] = hl_lines diff --git a/sphinx/themes/agogo/static/agogo.css_t b/sphinx/themes/agogo/static/agogo.css_t index 9cd50414..db4a621a 100644 --- a/sphinx/themes/agogo/static/agogo.css_t +++ b/sphinx/themes/agogo/static/agogo.css_t @@ -467,7 +467,7 @@ div.viewcode-block:target { border-bottom: 1px solid #ac9; } -div.code-block-filename { +div.code-block-caption { background-color: #ddd; color: #333; padding: 2px 5px; diff --git a/sphinx/themes/basic/static/basic.css_t b/sphinx/themes/basic/static/basic.css_t index cb1a923c..17547d0f 100644 --- a/sphinx/themes/basic/static/basic.css_t +++ b/sphinx/themes/basic/static/basic.css_t @@ -475,7 +475,7 @@ table.highlighttable td { padding: 0 0.5em 0 0.5em; } -div.code-block-filename { +div.code-block-caption { padding: 2px 5px; font-size: small; } @@ -484,8 +484,8 @@ div.code-block-filename code { background-color: transparent; } -div.code-block-filename + pre, -div.code-block-filename + div.highlight > pre { +div.code-block-caption + pre, +div.code-block-caption + div.highlight > pre { margin-top: 0; } diff --git a/sphinx/themes/default/static/default.css_t b/sphinx/themes/default/static/default.css_t index c0fbdd8c..137a9e75 100644 --- a/sphinx/themes/default/static/default.css_t +++ b/sphinx/themes/default/static/default.css_t @@ -309,7 +309,7 @@ div.viewcode-block:target { border-bottom: 1px solid #ac9; } -div.code-block-filename { +div.code-block-caption { color: #efefef; background-color: #1c4e63; } diff --git a/sphinx/themes/nature/static/nature.css_t b/sphinx/themes/nature/static/nature.css_t index 84b37517..8818e447 100644 --- a/sphinx/themes/nature/static/nature.css_t +++ b/sphinx/themes/nature/static/nature.css_t @@ -244,7 +244,7 @@ div.viewcode-block:target { border-bottom: 1px solid #ac9; } -div.code-block-filename { +div.code-block-caption { background-color: #ddd; color: #222; border: 1px solid #C6C9CB; diff --git a/sphinx/themes/pyramid/static/pyramid.css_t b/sphinx/themes/pyramid/static/pyramid.css_t index 6ffdb714..f60f82d2 100644 --- a/sphinx/themes/pyramid/static/pyramid.css_t +++ b/sphinx/themes/pyramid/static/pyramid.css_t @@ -341,7 +341,7 @@ code.xref { font-style: normal; } -div.code-block-filename { +div.code-block-caption { background-color: #ddd; color: #222; } diff --git a/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t b/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t index 174b5950..90b5d23a 100644 --- a/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t +++ b/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t @@ -338,7 +338,7 @@ div.viewcode-block:target { border-bottom: 1px solid #ac9; } -div.code-block-filename { +div.code-block-caption { background-color: #ddd; color: #222; border: 1px solid #ccc; diff --git a/sphinx/themes/traditional/static/traditional.css_t b/sphinx/themes/traditional/static/traditional.css_t index a82ef53c..4efb1ff4 100644 --- a/sphinx/themes/traditional/static/traditional.css_t +++ b/sphinx/themes/traditional/static/traditional.css_t @@ -703,6 +703,6 @@ div.viewcode-block:target { padding: 0 10px; } -div.code-block-filename { +div.code-block-caption { background-color: #cceeff; } diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 0874c7ce..14b11fcf 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -283,9 +283,9 @@ class HTMLTranslator(BaseTranslator): **highlight_args) starttag = self.starttag(node, 'div', suffix='', CLASS='highlight-%s' % lang) - if 'filename' in node: - starttag += '<div class="code-block-filename"><code>%s</code></div>' % ( - node['filename'],) + if 'caption' in node: + starttag += '<div class="code-block-caption"><code>%s</code></div>' % ( + node['caption'],) self.body.append(starttag + highlighted + '</div>\n') raise nodes.SkipNode diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index d77c2c54..a7459c92 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1345,11 +1345,11 @@ class LaTeXTranslator(nodes.NodeVisitor): highlight_args['force'] = True if 'linenos' in node: linenos = node['linenos'] - filename = node.get('filename') - if filename: + caption = node.get('caption') + if caption: self.body.append('\n{\\colorbox[rgb]{0.9,0.9,0.9}' '{\\makebox[\\textwidth][l]' - '{\\small\\texttt{%s}}}}\n' % (filename,)) + '{\\small\\texttt{%s}}}}\n' % (caption,)) def warner(msg): self.builder.warn(msg, (self.curfilestack[-1], node.line)) hlcode = self.highlighter.highlight_block(code, lang, warn=warner, diff --git a/tests/roots/test-directive-code/caption.rst b/tests/roots/test-directive-code/caption.rst new file mode 100644 index 00000000..274d0f19 --- /dev/null +++ b/tests/roots/test-directive-code/caption.rst @@ -0,0 +1,21 @@ +Dedent +====== + +Code blocks +----------- + +.. code-block:: ruby + :caption: caption-test.rb + + def ruby? + false + end + + +Literal Include +--------------- + +.. literalinclude:: literal.inc + :language: python + :caption: caption-test.py + :lines: 10-11 diff --git a/tests/roots/test-directive-code/index.rst b/tests/roots/test-directive-code/index.rst index ac7e519e..dab6b708 100644 --- a/tests/roots/test-directive-code/index.rst +++ b/tests/roots/test-directive-code/index.rst @@ -2,6 +2,7 @@ test-directive-code =================== .. toctree:: + :glob: * diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py index b0da9a04..4dbdff88 100644 --- a/tests/test_directive_code.py +++ b/tests/test_directive_code.py @@ -77,6 +77,27 @@ def test_code_block_dedent(app): assert actual == '\n\n'
+@with_app(buildername='html',
+ srcdir=(test_roots / 'test-directive-code'),
+ _copy_to_temp=True)
+def test_code_block_caption_html(app):
+ app.builder.build('index')
+ html = (app.outdir / 'caption.html').text()
+ caption = '<div class="code-block-caption"><code>caption-test.rb</code></div>'
+ assert caption in html
+
+
+@with_app(buildername='latex',
+ srcdir=(test_roots / 'test-directive-code'),
+ _copy_to_temp=True)
+def test_code_block_caption_latex(app):
+ app.builder.build('index')
+ latex = (app.outdir / 'Python.tex').text()
+ caption = ('{\\colorbox[rgb]{0.9,0.9,0.9}{\\makebox[\\textwidth][l]'
+ '{\\small\\texttt{caption-test.rb}}}}')
+ assert caption in latex
+
+
@with_app(buildername='xml',
srcdir=(test_roots / 'test-directive-code'),
_copy_to_temp=True)
@@ -129,3 +150,24 @@ def test_literal_include_dedent(app): actual = get_dedent_actual(1000)
assert actual == '\n\n'
+
+
+@with_app(buildername='html',
+ srcdir=(test_roots / 'test-directive-code'),
+ _copy_to_temp=True)
+def test_literalinclude_caption_html(app):
+ app.builder.build('index')
+ html = (app.outdir / 'caption.html').text()
+ caption = '<div class="code-block-caption"><code>caption-test.py</code></div>'
+ assert caption in html
+
+
+@with_app(buildername='latex',
+ srcdir=(test_roots / 'test-directive-code'),
+ _copy_to_temp=True)
+def test_literalinclude_caption_latex(app):
+ app.builder.build('index')
+ latex = (app.outdir / 'Python.tex').text()
+ caption = ('{\\colorbox[rgb]{0.9,0.9,0.9}{\\makebox[\\textwidth][l]'
+ '{\\small\\texttt{caption-test.py}}}}')
+ assert caption in latex
|