Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #26 from ericholscher/jinhwa/bug_cross_reference
Browse files Browse the repository at this point in the history
fix cross preference issue
  • Loading branch information
bianliu1013 committed May 26, 2017
2 parents 39b279b + 02451bc commit 7dd876a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
12 changes: 12 additions & 0 deletions docfx_yaml/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from sphinx.util.console import darkgreen, bold
from sphinx.util import ensuredir
from sphinx.errors import ExtensionError
from sphinx.util.nodes import make_refnode

from .utils import transform_node, transform_string, get_method_sig
from .settings import API_ROOT
Expand Down Expand Up @@ -399,6 +400,16 @@ def find_node_in_toc_tree(toc_yaml, to_add_node):
)


def missing_reference(app, env, node, contnode):
reftarget = ''
refdoc = ''
if 'refdomain' in node.attributes and node.attributes['refdomain'] == 'py':
reftarget = node['reftarget']
if 'refdoc' in node:
refdoc = node['refdoc']
return make_refnode(app.builder, refdoc, reftarget, '', contnode)


def setup(app):
"""
Plugin init for our Sphinx extension.
Expand All @@ -410,4 +421,5 @@ def setup(app):
app.connect('builder-inited', build_init)
app.connect('autodoc-process-docstring', process_docstring)
app.connect('build-finished', build_finished)
app.connect('missing-reference', missing_reference)
app.add_config_value('docfx_yaml_output', API_ROOT, 'html')
9 changes: 8 additions & 1 deletion docfx_yaml/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from sphinx.util.docfields import _is_single_paragraph
from sphinx.util import docfields
from sphinx import directives, addnodes
from sphinx import addnodes

from .utils import transform_node as _transform_node

Expand Down Expand Up @@ -149,6 +150,12 @@ def make_param(_id, _description, _type=None):
ret['type'] = [_type]
return ret

def transform_para(para_field):
if isinstance(para_field, addnodes.pending_xref):
return transform_node(para_field)
else:
return para_field.astext()

for entry in entries:
if isinstance(entry, nodes.field):
# pass-through old field
Expand All @@ -175,7 +182,7 @@ def make_param(_id, _description, _type=None):
_id = field
_description = transform_node(node_list[0])
if field in fieldtypes:
_type = u''.join(n.astext() for n in fieldtypes[field])
_type = u''.join(transform_para(n) for n in fieldtypes[field])
else:
_type = None
if fieldtype.name == 'parameter':
Expand Down
7 changes: 6 additions & 1 deletion docfx_yaml/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,12 @@ def visit_reference(self, node):
if 'http' in node.attributes['refuri']:
self.add_text('[{}]({})'.format(node.astext(), node.attributes['refuri']))
else:
self.add_text('@{}'.format(node.attributes['refuri'].replace('#', '')))
# TODO: refactor? so 'hardcoding'
# no need '.html#id' ending in yml files
pos = node.attributes['refuri'].find('.html')
if pos != -1:
node.attributes['refuri'] = node.attributes['refuri'][0: pos]
self.add_text('@{}'.format(node.attributes['refuri']))
else:
self.add_text('{}<!-- {} -->'.format(node.tagname, json.dumps(node.attributes)))
raise nodes.SkipNode
Expand Down

0 comments on commit 7dd876a

Please sign in to comment.