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 #74 from docascode/yitian/fix-remarks
Browse files Browse the repository at this point in the history
Yitian/fix remarks
  • Loading branch information
killa1218 committed Jul 24, 2018
2 parents eb39eac + b39ef0a commit 121abb9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def sphinx_build(test_dir):

try:
app = Sphinx(
srcdir='.',
confdir='.',
srcdir='doc',
confdir='doc',
outdir='_build/yaml',
doctreedir='_build/.doctrees',
buildername='html',
Expand All @@ -23,5 +23,5 @@ def sphinx_build(test_dir):
os.chdir('../..')

if __name__ == '__main__':
with sphinx_build('pyexample'):
with sphinx_build('example'):
print('Debug finished.')
23 changes: 13 additions & 10 deletions docfx_yaml/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .nodes import remarks

TYPE_SEP_PATTERN = '(\[|\]|, |\(|\))'
REF_PATTERN = ':(func|class|meth|mod|ref|any):`~?([a-zA-Z_\.<> ]*?)`'

def _get_desc_data(node):
assert node.tagname == 'desc'
Expand Down Expand Up @@ -174,15 +175,15 @@ def transform_para(para_field):
return transform_node(para_field)
else:
return para_field.astext()

def resolve_type(data_type):
# Remove @ ~ and \n for cross reference in parameter/return value type to apply to docfx correctly
data_type = re.sub('[@~\n]', '', data_type)

# Add references for docfx to resolve ref if type contains TYPE_SEP_PATTERN
_spec_list = []
_spec_fullnames = re.split(TYPE_SEP_PATTERN, data_type)

_added_reference = {}
if len(_spec_fullnames) > 1:
_added_reference_name = ''
Expand All @@ -202,7 +203,7 @@ def resolve_type(data_type):
'fullName': data_type,
'spec.python': _spec_list
}

return data_type, _added_reference

def extract_exception_desc(field_object):
Expand Down Expand Up @@ -267,8 +268,8 @@ def extract_exception_desc(field_object):
_type = u''.join(transform_para(n) for n in fieldtypes[field])
else:
_type = None
_para_types = []

_para_types = []
if fieldtype.name == 'parameter':
if _type:
# Support or in parameter type
Expand Down Expand Up @@ -324,8 +325,10 @@ def transform_all(self, node):
name, uid = _get_desc_data(node.parent)
for child in node:
if isinstance(child, remarks):
data['remarks'] = child.astext()
if isinstance(child, addnodes.desc):
remarks_string = child.astext()
data['remarks'] = re.sub(REF_PATTERN, lambda x: '@' + x.group(2), remarks_string)
node.remove(child)
elif isinstance(child, addnodes.desc):
if child.get('desctype') == 'attribute':
attribute_map = {} # Used for detecting duplicated attributes in intermediate data and merge them

Expand All @@ -350,7 +353,7 @@ def transform_all(self, node):
if len(item_ids) == 0: # ensure the order of docstring attributes and real attributes is fixed
attribute_map[curuid]['syntax']['content'] += (' ' + item.astext())
# concat the description of duplicated nodes
else:
else:
attribute_map[curuid]['syntax']['content'] = item.astext() + ' ' + attribute_map[curuid]['syntax']['content']
else:
if _is_desc_of_enum_class(node):
Expand Down Expand Up @@ -410,7 +413,7 @@ def transform_all(self, node):
# skip 'Bases' in summary
if not content.startswith('Bases: '):
summary.append(content)

if "desctype" in node.parent and node.parent["desctype"] == 'class':
data.pop('exceptions', '') # Make sure class doesn't have 'exceptions' field.

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='sphinx-docfx-yaml',
version='1.2.39',
version='1.2.40',
author='Eric Holscher',
author_email='eric@ericholscher.com',
url='https://github.com/ericholscher/sphinx-docfx-yaml',
Expand Down

0 comments on commit 121abb9

Please sign in to comment.