Skip to content

Commit 4f7648f

Browse files
committed
REF: Respect __docformat__ from the documented module
Refs: #169
1 parent 7222477 commit 4f7648f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pdoc/html_helpers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ def to_html(text: str, docformat: str = 'numpy,google', *,
409409
return _md.reset().convert(md)
410410

411411

412-
def to_markdown(text: str, docformat: str = 'numpy,google', *,
412+
def to_markdown(text: str, *,
413+
docformat: str = None,
413414
module: pdoc.Module = None, link: Callable[..., str] = None):
414415
"""
415416
Returns `text`, assumed to be a docstring in `docformat`, converted to markdown.
@@ -418,7 +419,13 @@ def to_markdown(text: str, docformat: str = 'numpy,google', *,
418419
resolved) and `link` is the hyperlinking function like the one in the
419420
example template.
420421
"""
421-
assert all(i in (None, '', 'numpy', 'google') for i in docformat.split(',')), docformat
422+
if docformat is None:
423+
docformat = getattr(getattr(module, 'obj', None), '__docformat__', 'numpy,google ')
424+
docformat, *_ = docformat.lower().split()
425+
if not (set(docformat.split(',')) & {'', 'numpy', 'google'}):
426+
warn('__docformat__ value {!r} in module {!r} not supported. '
427+
'Supported values are: numpy, google.'.format(docformat, module))
428+
docformat = 'numpy,google'
422429

423430
text = _ToMarkdown.admonitions(text, module)
424431

0 commit comments

Comments
 (0)