Skip to content

Commit

Permalink
Merge pull request #7232 from tk0miya/refactor_js_domain
Browse files Browse the repository at this point in the history
refactor: js domain: Change make_old_*_id() to methods
  • Loading branch information
tk0miya committed Mar 1, 2020
2 parents dfaff26 + 0ef797f commit 7ebf6c2
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions sphinx/domains/javascript.py
Expand Up @@ -34,24 +34,6 @@
logger = logging.getLogger(__name__)


def make_old_jsmod_id(modname: str) -> str:
"""Generate old styled node_id for JS modules.
.. note:: Old Styled node_id was used until Sphinx-3.0.
This will be removed in Sphinx-5.0.
"""
return 'module-' + modname


def make_old_jsobj_id(fullname: str) -> str:
"""Generate old styled node_id for JS objects.
.. note:: Old Styled node_id was used until Sphinx-3.0.
This will be removed in Sphinx-5.0.
"""
return fullname.replace('$', '_S_')


class JSObject(ObjectDescription):
"""
Description of a JavaScript object.
Expand Down Expand Up @@ -129,7 +111,7 @@ def add_target_and_index(self, name_obj: Tuple[str, str], sig: str,

# Assign old styled node_id not to break old hyperlinks (if possible)
# Note: Will be removed in Sphinx-5.0 (RemovedInSphinx50Warning)
old_node_id = make_old_jsobj_id(fullname)
old_node_id = self.make_old_id(fullname)
if old_node_id not in self.state.document.ids and old_node_id not in signode['ids']:
signode['ids'].append(old_node_id)

Expand Down Expand Up @@ -211,6 +193,14 @@ def after_content(self) -> None:
self.env.ref_context['js:object'] = (objects[-1] if len(objects) > 0
else None)

def make_old_id(self, fullname: str) -> str:
"""Generate old styled node_id for JS objects.
.. note:: Old Styled node_id was used until Sphinx-3.0.
This will be removed in Sphinx-5.0.
"""
return fullname.replace('$', '_S_')


class JSCallable(JSObject):
"""Description of a JavaScript function, method or constructor."""
Expand Down Expand Up @@ -282,7 +272,7 @@ def run(self) -> List[Node]:

# Assign old styled node_id not to break old hyperlinks (if possible)
# Note: Will be removed in Sphinx-5.0 (RemovedInSphinx50Warning)
old_node_id = make_old_jsmod_id(mod_name)
old_node_id = self.make_old_id(mod_name)
if old_node_id not in self.state.document.ids and old_node_id not in target['ids']:
target['ids'].append(old_node_id)

Expand All @@ -293,6 +283,14 @@ def run(self) -> List[Node]:
ret.append(inode)
return ret

def make_old_id(self, modname: str) -> str:
"""Generate old styled node_id for JS modules.
.. note:: Old Styled node_id was used until Sphinx-3.0.
This will be removed in Sphinx-5.0.
"""
return 'module-' + modname


class JSXRefRole(XRefRole):
def process_link(self, env: BuildEnvironment, refnode: Element,
Expand Down

0 comments on commit 7ebf6c2

Please sign in to comment.