diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-08-18 12:12:15 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-08-18 12:12:15 +0900 |
commit | 1cfde018d2e6c61f9bba1914517eab421cc16d3e (patch) | |
tree | 6cc43207f6c1d2767eba91bdc953b7d70402c803 /sphinx/directives/code.py | |
parent | 6e3bba431f9ddfa64ca876c6edf65ca55886fbc9 (diff) | |
parent | 1c9524deddf12a61aeb59ed2022ddf859401673a (diff) | |
download | sphinx-git-1cfde018d2e6c61f9bba1914517eab421cc16d3e.tar.gz |
Merge branch 'stable'
Diffstat (limited to 'sphinx/directives/code.py')
-rw-r--r-- | sphinx/directives/code.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index f88b30987..a2738a30d 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -18,6 +18,7 @@ from docutils.statemachine import ViewList from six import string_types from sphinx import addnodes +from sphinx.locale import _ from sphinx.util import parselinenos from sphinx.util.nodes import set_source_info @@ -68,6 +69,8 @@ def container_wrapper(directive, literal_node, caption): parsed = nodes.Element() directive.state.nested_parse(ViewList([caption], source=''), directive.content_offset, parsed) + if isinstance(parsed[0], nodes.system_message): + raise ValueError(parsed[0]) caption_node = nodes.caption(parsed[0].rawsource, '', *parsed[0].children) caption_node.source = parsed[0].source @@ -131,7 +134,12 @@ class CodeBlock(Directive): caption = self.options.get('caption') if caption: self.options.setdefault('name', nodes.fully_normalize_name(caption)) - literal = container_wrapper(self, literal, caption) + try: + literal = container_wrapper(self, literal, caption) + except ValueError as exc: + document = self.state.document + errmsg = _('Invalid caption: %s' % exc[0][0].astext()) + return [document.reporter.warning(errmsg, line=self.lineno)] # literal will be note_implicit_target that is linked from caption and numref. # when options['name'] is provided, it should be primary ID. @@ -333,7 +341,12 @@ class LiteralInclude(Directive): if not caption: caption = self.arguments[0] self.options.setdefault('name', nodes.fully_normalize_name(caption)) - retnode = container_wrapper(self, retnode, caption) + try: + retnode = container_wrapper(self, retnode, caption) + except ValueError as exc: + document = self.state.document + errmsg = _('Invalid caption: %s' % exc[0][0].astext()) + return [document.reporter.warning(errmsg, line=self.lineno)] # retnode will be note_implicit_target that is linked from caption and numref. # when options['name'] is provided, it should be primary ID. |