summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-03-10 17:45:06 +0900
committerGitHub <noreply@github.com>2019-03-10 17:45:06 +0900
commit1aba35f445e254738962e7813097a44906cd56a5 (patch)
tree2c24b97c8b61cd749f5e622872cdf982c43e522b
parenta37e508b3fc7b28cf10bbd51b766ce62fc390c4c (diff)
parentc0755bf5824d3ab2389901868c6d6d1336de7d06 (diff)
downloadsphinx-git-1aba35f445e254738962e7813097a44906cd56a5.tar.gz
Merge pull request #6158 from tk0miya/refactor_citation_ref
refactor CitationReferences transform
-rw-r--r--sphinx/io.py6
-rw-r--r--sphinx/transforms/__init__.py43
2 files changed, 28 insertions, 21 deletions
diff --git a/sphinx/io.py b/sphinx/io.py
index 368f661d5..00fc2bf1a 100644
--- a/sphinx/io.py
+++ b/sphinx/io.py
@@ -20,7 +20,7 @@ from docutils.writers import UnfilteredWriter
from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx.transforms import (
- ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences,
+ ApplySourceWorkaround, ExtraTranslatableNodes, SmartQuotesSkipper, CitationReferences,
DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, SortIds, FigureAligner,
AutoNumbering, AutoIndexUpgrader, FilterSystemMessages,
UnreferencedFootnotesDetector, SphinxSmartQuotes, DoctreeReadEvent, ManpageLink
@@ -99,7 +99,7 @@ class SphinxStandaloneReader(SphinxBaseReader):
RemoveTranslatableInline, FilterSystemMessages, RefOnlyBulletListTransform,
UnreferencedFootnotesDetector, SphinxSmartQuotes, ManpageLink,
SphinxDomains, SubstitutionDefinitionsRemover, DoctreeReadEvent,
- UIDTransform]
+ UIDTransform, SmartQuotesSkipper]
def __init__(self, app, *args, **kwargs):
# type: (Sphinx, Any, Any) -> None
@@ -141,7 +141,7 @@ class SphinxI18nReader(SphinxBaseReader):
AutoNumbering, SortIds, RemoveTranslatableInline,
FilterSystemMessages, RefOnlyBulletListTransform,
UnreferencedFootnotesDetector, SphinxSmartQuotes, ManpageLink,
- SubstitutionDefinitionsRemover]
+ SubstitutionDefinitionsRemover, SmartQuotesSkipper]
def set_lineno_for_reporter(self, lineno):
# type: (int) -> None
diff --git a/sphinx/transforms/__init__.py b/sphinx/transforms/__init__.py
index 6f513377b..dd7a4c04f 100644
--- a/sphinx/transforms/__init__.py
+++ b/sphinx/transforms/__init__.py
@@ -23,7 +23,9 @@ from sphinx.locale import _, __
from sphinx.util import logging
from sphinx.util.docutils import new_document
from sphinx.util.i18n import format_date
-from sphinx.util.nodes import NodeMatcher, apply_source_workaround, is_smartquotable
+from sphinx.util.nodes import (
+ NodeMatcher, apply_source_workaround, copy_source_info, is_smartquotable
+)
if False:
# For type annotation
@@ -198,6 +200,18 @@ class SortIds(SphinxTransform):
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
@@ -207,23 +221,16 @@ class CitationReferences(SphinxTransform):
def apply(self, **kwargs):
# type: (Any) -> None
- # mark citation labels as not smartquoted
- for citation in self.document.traverse(nodes.citation):
- label = cast(nodes.label, citation[0])
- label['support_smartquotes'] = False
-
- for citation_ref in self.document.traverse(nodes.citation_reference):
- cittext = citation_ref.astext()
- refnode = addnodes.pending_xref(cittext, refdomain='std', reftype='citation',
- reftarget=cittext, refwarn=True,
- support_smartquotes=False,
- ids=citation_ref["ids"])
- refnode.source = citation_ref.source or citation_ref.parent.source
- refnode.line = citation_ref.line or citation_ref.parent.line
- refnode += nodes.inline(cittext, '[%s]' % cittext)
- for class_name in citation_ref.attributes.get('classes', []):
- refnode['classes'].append(class_name)
- citation_ref.parent.replace(citation_ref, refnode)
+ 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 = {