diff options
Diffstat (limited to 'sphinx/writers/html5.py')
-rw-r--r-- | sphinx/writers/html5.py | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index fafa125f8..5e0be1a41 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -12,7 +12,7 @@ import os import posixpath import re import warnings -from typing import Any, Iterable, Tuple, cast +from typing import TYPE_CHECKING, Iterable, Tuple, cast from docutils import nodes from docutils.nodes import Element, Node, Text @@ -20,14 +20,13 @@ from docutils.writers.html5_polyglot import HTMLTranslator as BaseTranslator from sphinx import addnodes from sphinx.builders import Builder -from sphinx.deprecation import RemovedInSphinx40Warning +from sphinx.deprecation import RemovedInSphinx60Warning from sphinx.locale import _, __, admonitionlabels from sphinx.util import logging from sphinx.util.docutils import SphinxTranslator from sphinx.util.images import get_image_size -if False: - # For type annotation +if TYPE_CHECKING: from sphinx.builders.html import StandaloneHTMLBuilder @@ -57,14 +56,7 @@ class HTML5Translator(SphinxTranslator, BaseTranslator): builder = None # type: StandaloneHTMLBuilder - def __init__(self, *args: Any) -> None: - if isinstance(args[0], nodes.document) and isinstance(args[1], Builder): - document, builder = args - else: - warnings.warn('The order of arguments for HTML5Translator has been changed. ' - 'Please give "document" as 1st and "builder" as 2nd.', - RemovedInSphinx40Warning, stacklevel=2) - builder, document = args + def __init__(self, document: nodes.document, builder: Builder) -> None: super().__init__(document, builder) self.highlighter = self.builder.highlighter @@ -718,22 +710,7 @@ class HTML5Translator(SphinxTranslator, BaseTranslator): # overwritten to add even/odd classes - def generate_targets_for_table(self, node: Element) -> 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: Element) -> None: - self.generate_targets_for_table(node) - self._table_row_index = 0 atts = {} @@ -790,3 +767,18 @@ class HTML5Translator(SphinxTranslator, BaseTranslator): def unknown_visit(self, node: Node) -> None: raise NotImplementedError('Unknown node: ' + node.__class__.__name__) + + def generate_targets_for_table(self, node: Element) -> 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. + """ + warnings.warn('generate_targets_for_table() is deprecated', + RemovedInSphinx60Warning, stacklevel=2) + for id in node['ids'][1:]: + self.body.append('<span id="%s"></span>' % id) + node['ids'].remove(id) |