summaryrefslogtreecommitdiff
path: root/sphinx/writers/html5.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/writers/html5.py')
-rw-r--r--sphinx/writers/html5.py48
1 files changed, 20 insertions, 28 deletions
diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py
index 4ceeaafdf..5eb35cbfe 100644
--- a/sphinx/writers/html5.py
+++ b/sphinx/writers/html5.py
@@ -12,8 +12,8 @@ import os
import posixpath
import re
import warnings
-from typing import Any, Iterable, Tuple
-from typing import cast
+from typing import Iterable, Tuple
+from typing import TYPE_CHECKING, cast
from docutils import nodes
from docutils.nodes import Element, Node, Text
@@ -21,14 +21,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
@@ -58,14 +57,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
@@ -719,22 +711,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 = {}
@@ -791,3 +768,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)