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

Commit

Permalink
Fix Bug: xref links in summary are not being parsed (#58)
Browse files Browse the repository at this point in the history
* Fix Bug: xref links in summary are not being parsed

* Support <> ref pattern
  • Loading branch information
yannanwang1 authored and bianliu1013 committed Aug 9, 2017
1 parent 157b75e commit 6043d76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions docfx_yaml/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class bcolors:
REFMETHOD = 'meth'
REFFUNCTION = 'func'
INITPY = '__init__.py'
REF_PATTERN = ':(func|class|meth|mod|ref):`~?[a-zA-Z_\.<> ]*?`'


def build_init(app):
Expand Down Expand Up @@ -155,6 +156,28 @@ def _refact_example_in_module_summary(lines):
return new_lines


def _resolve_reference_in_module_summary(lines):
new_lines = []
for line in lines:
matched_objs = list(re.finditer(REF_PATTERN, line))
new_line = line
for matched_obj in matched_objs:
start = matched_obj.start()
end = matched_obj.end()
matched_str = line[start:end]
if '<' in matched_str and '>' in matched_str:
# match string like ':func:`***<***>`'
index = matched_str.index('<')
ref_name = matched_str[index+1:-2]
else:
# match string like ':func:`~***`' or ':func:`***`'
index = matched_str.index('~') if '~' in matched_str else matched_str.index('`')
ref_name = matched_str[index+1:-1]
new_line = new_line.replace(matched_str, '@' + ref_name)
new_lines.append(new_line)
return new_lines


def _create_datam(app, cls, module, name, _type, obj, lines=None):
"""
Build the data structure for an autodoc class
Expand Down Expand Up @@ -247,6 +270,7 @@ def _update_friendly_package_name(path):

# Only add summary to parts of the code that we don't get it from the monkeypatch
if _type == MODULE:
lines = _resolve_reference_in_module_summary(lines)
summary = app.docfx_transform_string('\n'.join(_refact_example_in_module_summary(lines)))
if summary:
datam['summary'] = summary
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.18',
version='1.2.19',
author='Eric Holscher',
author_email='eric@ericholscher.com',
url='https://github.com/ericholscher/sphinx-docfx-yaml',
Expand Down

0 comments on commit 6043d76

Please sign in to comment.