mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #3498 from shibukawa/fix/multiple_id_for_table
fix #1733: fix span tags for ids is in table tag (for html5 validation)
This commit is contained in:
@@ -918,7 +918,7 @@ class StandaloneHTMLBuilder(Builder):
|
||||
def dump_inventory(self):
|
||||
# type: () -> None
|
||||
def safe_name(string):
|
||||
return re.sub("\s+", " ", string)
|
||||
return re.sub(r"\s+", " ", string)
|
||||
|
||||
logger.info(bold('dumping object inventory... '), nonl=True)
|
||||
with open(path.join(self.outdir, INVENTORY_FILENAME), 'wb') as f:
|
||||
|
||||
@@ -325,36 +325,14 @@ class HTML5Translator(BaseTranslator):
|
||||
format = u'<a class="headerlink" href="#%s" title="%s">%s</a>'
|
||||
self.body.append(format % (node['ids'][0], title, self.permalink_text))
|
||||
|
||||
def generate_targets_for_listing(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
"""Generate hyperlink targets for listings.
|
||||
|
||||
Original visit_bullet_list(), visit_definition_list() and visit_enumerated_list()
|
||||
generates hyperlink targets inside listing tags (<ul>, <ol> and <dl>) if multiple
|
||||
IDs are assigned to listings. That is invalid DOM structure.
|
||||
(This is a bug of docutils <= 0.12)
|
||||
|
||||
This exports hyperlink targets before listings to make valid DOM structure.
|
||||
"""
|
||||
for id in node['ids'][1:]:
|
||||
self.body.append('<span id="%s"></span>' % id)
|
||||
node['ids'].remove(id)
|
||||
|
||||
# overwritten
|
||||
def visit_bullet_list(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
if len(node) == 1 and node[0].tagname == 'toctree':
|
||||
# avoid emitting empty <ul></ul>
|
||||
raise nodes.SkipNode
|
||||
self.generate_targets_for_listing(node)
|
||||
BaseTranslator.visit_bullet_list(self, node)
|
||||
|
||||
# overwritten
|
||||
def visit_enumerated_list(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
self.generate_targets_for_listing(node)
|
||||
BaseTranslator.visit_enumerated_list(self, node)
|
||||
|
||||
# overwritten
|
||||
def visit_title(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
@@ -789,8 +767,24 @@ class HTML5Translator(BaseTranslator):
|
||||
|
||||
# overwritten to add even/odd classes
|
||||
|
||||
def generate_targets_for_table(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
"""Generate hyperlink targets for tables.
|
||||
|
||||
Original visit_table() generates hyperlink targets inside table tags
|
||||
(<table>) if multiple IDs are assigned to listings.
|
||||
That is invalid DOM structure. (This is a bug of docutils <= 0.13.1)
|
||||
|
||||
This exports hyperlink targets before tables to make valid DOM structure.
|
||||
"""
|
||||
for id in node['ids'][1:]:
|
||||
self.body.append('<span id="%s"></span>' % id)
|
||||
node['ids'].remove(id)
|
||||
|
||||
def visit_table(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
self.generate_targets_for_table(node)
|
||||
|
||||
self._table_row_index = 0
|
||||
|
||||
classes = [cls.strip(u' \t\n')
|
||||
|
||||
Reference in New Issue
Block a user