diff --git a/CHANGES b/CHANGES index 9e473bde1..ad1436925 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,7 @@ Bugs fixed * #1922: html search: Upper characters problem in French * #4412: Updated jQuery version from 3.1.0 to 3.2.1 +* #4438: math: math with labels with whitespace cause html error Testing -------- diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py index 549ca30cd..8370c923e 100644 --- a/sphinx/ext/mathbase.py +++ b/sphinx/ext/mathbase.py @@ -10,6 +10,7 @@ """ from docutils import nodes, utils +from docutils.nodes import make_id from docutils.parsers.rst import Directive, directives from sphinx.roles import XRefRole @@ -51,7 +52,8 @@ class MathDomain(Domain): label = 'mathematics' initial_data = { - 'objects': {}, # labelid -> (docname, eqno) + 'nameids': {}, # label -> equation ID + 'objects': {}, # equation ID -> (docname, eqno) } # type: Dict[unicode, Dict[unicode, Tuple[unicode, int]]] dangling_warnings = { 'eq': 'equation not found: %(target)s', @@ -59,9 +61,9 @@ class MathDomain(Domain): def clear_doc(self, docname): # type: (unicode) -> None - for labelid, (doc, eqno) in list(self.data['objects'].items()): + for equation_id, (doc, eqno) in list(self.data['objects'].items()): if doc == docname: - del self.data['objects'][labelid] + del self.data['objects'][equation_id] def merge_domaindata(self, docnames, otherdata): # type: (Iterable[unicode], Dict) -> None @@ -81,8 +83,8 @@ class MathDomain(Domain): return newnode else: title = nodes.Text("(%d)" % number) - return make_refnode(builder, fromdocname, docname, - "equation-" + target, title) + node_id = make_id('equation-%s' % target) + return make_refnode(builder, fromdocname, docname, node_id, title) else: return None @@ -226,7 +228,8 @@ class MathDirective(Directive): node['number'] = eqno # add target node - target = nodes.target('', '', ids=['equation-' + node['label']]) + node_id = make_id('equation-%s' % node['label']) + target = nodes.target('', '', ids=[node_id]) self.state.document.note_explicit_target(target) ret.insert(0, target) except UserWarning as exc: diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py index 2b8a68f9c..8ecf7ca4d 100644 --- a/tests/test_ext_math.py +++ b/tests/test_ext_math.py @@ -27,9 +27,9 @@ def test_jsmath(app, status, warning): assert (u'(1)\xb6' u'