diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index da7dc0caa..6ea525b0f 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 9cd504142..db4a621a4 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 cb1a923ce..17547d0fd 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 c0fbdd8c8..137a9e755 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 84b37517a..8818e447b 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 6ffdb7142..f60f82d26 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 174b5950d..90b5d23a9 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 a82ef53ca..4efb1ff40 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 0874c7ce9..14b11fcff 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 += '
%s
%s
caption-test.rb
caption-test.py