summaryrefslogtreecommitdiff
path: root/sphinx/ext/mathbase.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2018-01-19 23:12:25 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2018-01-19 23:13:21 +0900
commitf91c7327494a8dab1e1bcc985fcadb0cc6cb5ebf (patch)
treee3e6c4930d6e29fea6583278b6016cee7f8aeffc /sphinx/ext/mathbase.py
parentf9a53f50c6cc9034a0fa7fb171b4c7a8553f7821 (diff)
downloadsphinx-git-f91c7327494a8dab1e1bcc985fcadb0cc6cb5ebf.tar.gz
Fix #4438: math: math with labels with whitespace cause html error
Diffstat (limited to 'sphinx/ext/mathbase.py')
-rw-r--r--sphinx/ext/mathbase.py15
1 files changed, 9 insertions, 6 deletions
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: