mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Move transforms for citations to sphinx.domains.citation
This commit is contained in:
parent
a99d749c56
commit
87c6335b46
2
CHANGES
2
CHANGES
@ -36,6 +36,8 @@ Deprecated
|
|||||||
* ``sphinx.ext.autodoc.importer.MockLoader``
|
* ``sphinx.ext.autodoc.importer.MockLoader``
|
||||||
* ``sphinx.ext.autodoc.importer.mock()``
|
* ``sphinx.ext.autodoc.importer.mock()``
|
||||||
* ``sphinx.ext.autosummary.autolink_role()``
|
* ``sphinx.ext.autosummary.autolink_role()``
|
||||||
|
* ``sphinx.transforms.CitationReferences``
|
||||||
|
* ``sphinx.transforms.SmartQuotesSkipper``
|
||||||
* ``sphinx.util.docfields.DocFieldTransformer.preprocess_fieldtypes()``
|
* ``sphinx.util.docfields.DocFieldTransformer.preprocess_fieldtypes()``
|
||||||
* ``sphinx.util.node.find_source_node()``
|
* ``sphinx.util.node.find_source_node()``
|
||||||
* ``sphinx.util.i18n.find_catalog()``
|
* ``sphinx.util.i18n.find_catalog()``
|
||||||
|
@ -141,6 +141,16 @@ The following is a list of deprecated interfaces.
|
|||||||
- 4.0
|
- 4.0
|
||||||
- ``sphinx.ext.autosummary.AutoLink``
|
- ``sphinx.ext.autosummary.AutoLink``
|
||||||
|
|
||||||
|
* - ``sphinx.transforms.CitationReferences``
|
||||||
|
- 2.1
|
||||||
|
- 4.0
|
||||||
|
- ``sphinx.domains.citation.CitationReferenceTransform``
|
||||||
|
|
||||||
|
* - ``sphinx.transforms.SmartQuotesSkipper``
|
||||||
|
- 2.1
|
||||||
|
- 4.0
|
||||||
|
- ``sphinx.domains.citation.CitationDefinitionTransform``
|
||||||
|
|
||||||
* - ``sphinx.util.docfields.DocFieldTransformer.preprocess_fieldtypes()``
|
* - ``sphinx.util.docfields.DocFieldTransformer.preprocess_fieldtypes()``
|
||||||
- 2.1
|
- 2.1
|
||||||
- 4.0
|
- 4.0
|
||||||
|
@ -77,6 +77,7 @@ builtin_extensions = (
|
|||||||
'sphinx.config',
|
'sphinx.config',
|
||||||
'sphinx.domains.c',
|
'sphinx.domains.c',
|
||||||
'sphinx.domains.changeset',
|
'sphinx.domains.changeset',
|
||||||
|
'sphinx.domains.citation',
|
||||||
'sphinx.domains.cpp',
|
'sphinx.domains.cpp',
|
||||||
'sphinx.domains.javascript',
|
'sphinx.domains.javascript',
|
||||||
'sphinx.domains.math',
|
'sphinx.domains.math',
|
||||||
|
66
sphinx/domains/citation.py
Normal file
66
sphinx/domains/citation.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
"""
|
||||||
|
sphinx.domains.citation
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The citation domain.
|
||||||
|
|
||||||
|
:copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
|
||||||
|
:license: BSD, see LICENSE for details.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
|
from docutils import nodes
|
||||||
|
|
||||||
|
from sphinx import addnodes
|
||||||
|
from sphinx.transforms import SphinxTransform
|
||||||
|
from sphinx.util.nodes import copy_source_info
|
||||||
|
|
||||||
|
if False:
|
||||||
|
# For type annotation
|
||||||
|
from typing import Any, Dict # NOQA
|
||||||
|
from sphinx.application import Sphinx # NOQA
|
||||||
|
|
||||||
|
|
||||||
|
class CitationDefinitionTransform(SphinxTransform):
|
||||||
|
"""Mark citation definition labels as not smartquoted."""
|
||||||
|
default_priority = 619
|
||||||
|
|
||||||
|
def apply(self, **kwargs):
|
||||||
|
# type: (Any) -> None
|
||||||
|
for node in self.document.traverse(nodes.citation):
|
||||||
|
label = cast(nodes.label, node[0])
|
||||||
|
label['support_smartquotes'] = False
|
||||||
|
|
||||||
|
|
||||||
|
class CitationReferenceTransform(SphinxTransform):
|
||||||
|
"""
|
||||||
|
Replace citation references by pending_xref nodes before the default
|
||||||
|
docutils transform tries to resolve them.
|
||||||
|
"""
|
||||||
|
default_priority = 619
|
||||||
|
|
||||||
|
def apply(self, **kwargs):
|
||||||
|
# type: (Any) -> None
|
||||||
|
for node in self.document.traverse(nodes.citation_reference):
|
||||||
|
target = node.astext()
|
||||||
|
ref = addnodes.pending_xref(target, refdomain='std', reftype='citation',
|
||||||
|
reftarget=target, refwarn=True,
|
||||||
|
support_smartquotes=False,
|
||||||
|
ids=node["ids"],
|
||||||
|
classes=node.get('classes', []))
|
||||||
|
ref += nodes.inline(target, '[%s]' % target)
|
||||||
|
copy_source_info(node, ref)
|
||||||
|
node.replace_self(ref)
|
||||||
|
|
||||||
|
|
||||||
|
def setup(app):
|
||||||
|
# type: (Sphinx) -> Dict[str, Any]
|
||||||
|
app.add_transform(CitationDefinitionTransform)
|
||||||
|
app.add_transform(CitationReferenceTransform)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'version': 'builtin',
|
||||||
|
'parallel_read_safe': True,
|
||||||
|
'parallel_write_safe': True,
|
||||||
|
}
|
@ -9,7 +9,6 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from typing import cast
|
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.transforms import Transform, Transformer
|
from docutils.transforms import Transform, Transformer
|
||||||
@ -19,13 +18,12 @@ from docutils.utils import normalize_language_tag
|
|||||||
from docutils.utils.smartquotes import smartchars
|
from docutils.utils.smartquotes import smartchars
|
||||||
|
|
||||||
from sphinx import addnodes
|
from sphinx import addnodes
|
||||||
|
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
|
||||||
from sphinx.locale import _, __
|
from sphinx.locale import _, __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
from sphinx.util.docutils import new_document
|
from sphinx.util.docutils import new_document
|
||||||
from sphinx.util.i18n import format_date
|
from sphinx.util.i18n import format_date
|
||||||
from sphinx.util.nodes import (
|
from sphinx.util.nodes import NodeMatcher, apply_source_workaround, is_smartquotable
|
||||||
NodeMatcher, apply_source_workaround, copy_source_info, is_smartquotable
|
|
||||||
)
|
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
@ -200,39 +198,6 @@ class SortIds(SphinxTransform):
|
|||||||
node['ids'] = node['ids'][1:] + [node['ids'][0]]
|
node['ids'] = node['ids'][1:] + [node['ids'][0]]
|
||||||
|
|
||||||
|
|
||||||
class SmartQuotesSkipper(SphinxTransform):
|
|
||||||
"""Mark specific nodes as not smartquoted."""
|
|
||||||
default_priority = 619
|
|
||||||
|
|
||||||
def apply(self, **kwargs):
|
|
||||||
# type: (Any) -> None
|
|
||||||
# citation labels
|
|
||||||
for node in self.document.traverse(nodes.citation):
|
|
||||||
label = cast(nodes.label, node[0])
|
|
||||||
label['support_smartquotes'] = False
|
|
||||||
|
|
||||||
|
|
||||||
class CitationReferences(SphinxTransform):
|
|
||||||
"""
|
|
||||||
Replace citation references by pending_xref nodes before the default
|
|
||||||
docutils transform tries to resolve them.
|
|
||||||
"""
|
|
||||||
default_priority = 619
|
|
||||||
|
|
||||||
def apply(self, **kwargs):
|
|
||||||
# type: (Any) -> None
|
|
||||||
for node in self.document.traverse(nodes.citation_reference):
|
|
||||||
target = node.astext()
|
|
||||||
ref = addnodes.pending_xref(target, refdomain='std', reftype='citation',
|
|
||||||
reftarget=target, refwarn=True,
|
|
||||||
support_smartquotes=False,
|
|
||||||
ids=node["ids"],
|
|
||||||
classes=node.get('classes', []))
|
|
||||||
ref += nodes.inline(target, '[%s]' % target)
|
|
||||||
copy_source_info(node, ref)
|
|
||||||
node.replace_self(ref)
|
|
||||||
|
|
||||||
|
|
||||||
TRANSLATABLE_NODES = {
|
TRANSLATABLE_NODES = {
|
||||||
'literal-block': nodes.literal_block,
|
'literal-block': nodes.literal_block,
|
||||||
'doctest-block': nodes.doctest_block,
|
'doctest-block': nodes.doctest_block,
|
||||||
@ -440,12 +405,22 @@ class ManpageLink(SphinxTransform):
|
|||||||
node.attributes.update(info)
|
node.attributes.update(info)
|
||||||
|
|
||||||
|
|
||||||
|
from sphinx.domains.citation import ( # NOQA
|
||||||
|
CitationDefinitionTransform, CitationReferenceTransform
|
||||||
|
)
|
||||||
|
|
||||||
|
deprecated_alias('sphinx.transforms',
|
||||||
|
{
|
||||||
|
'CitationReferences': CitationReferenceTransform,
|
||||||
|
'SmartQuotesSkipper': CitationDefinitionTransform,
|
||||||
|
},
|
||||||
|
RemovedInSphinx40Warning)
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
# type: (Sphinx) -> Dict[str, Any]
|
# type: (Sphinx) -> Dict[str, Any]
|
||||||
app.add_transform(ApplySourceWorkaround)
|
app.add_transform(ApplySourceWorkaround)
|
||||||
app.add_transform(ExtraTranslatableNodes)
|
app.add_transform(ExtraTranslatableNodes)
|
||||||
app.add_transform(SmartQuotesSkipper)
|
|
||||||
app.add_transform(CitationReferences)
|
|
||||||
app.add_transform(DefaultSubstitutions)
|
app.add_transform(DefaultSubstitutions)
|
||||||
app.add_transform(MoveModuleTargets)
|
app.add_transform(MoveModuleTargets)
|
||||||
app.add_transform(HandleCodeBlocks)
|
app.add_transform(HandleCodeBlocks)
|
||||||
|
Loading…
Reference in New Issue
Block a user