| 1 |
<% |
| 2 |
import re |
| 3 |
import pdoc |
| 4 |
from pdoc.html_helpers import to_markdown |
| 5 |
|
| 6 |
def link(dobj: pdoc.Doc): |
| 7 |
name = dobj.qualname + ('()' if isinstance(dobj, pdoc.Function) else '') |
| 8 |
if isinstance(dobj, pdoc.External): |
| 9 |
return name |
| 10 |
return f'[{name}](#{dobj.refname} "{dobj.refname}")' |
| 11 |
|
| 12 |
def _to_md(text, module): |
| 13 |
text = to_markdown(text, docformat=docformat, module=module, link=link) |
| 14 |
# Setext H2 headings to atx H2 headings |
| 15 |
text = re.sub(r'\n(.+)\n-{3,}\n', r'\n## \1\n\n', text) |
| 16 |
# Convert admonitions into simpler paragraphs, dedent contents |
| 17 |
def paragraph_fmt(m): |
| 18 |
sub = re.sub('\n {,4}', '\n', m.group(4)) |
| 19 |
return f'{m.group(2)}**{m.group(3)}:** {sub}' |
| 20 |
text = re.sub(r'^(?P<indent>( *))!!! \w+ \"([^\"]*)\"(.*(?:\n(?P=indent) +.*)*)', |
| 21 |
paragraph_fmt, text, flags=re.MULTILINE) |
| 22 |
return text |
| 23 |
|
| 24 |
def subh(text, level=2): |
| 25 |
# Deepen heading levels so H2 becomes H4 etc. |
| 26 |
return re.sub(r'\n(#+) +(.+)\n', fr'\n{"#" * level}\1 \2\n', text) |
| 27 |
%> |
| 28 |
|
| 29 |
<%def name="title(level, string, id=None)"> |
| 30 |
<% id = f' {{#id}}' if id is not None else '' %> |
| 31 |
${('#' * level) + ' ' + string + id} |
| 32 |
</%def> |
| 33 |
|
| 34 |
<%def name="funcdef(f)"> |
| 35 |
<% |
| 36 |
params = f.params(annotate=show_type_annotations) |
| 37 |
returns = show_type_annotations and f.return_annotation() or '' |
| 38 |
if returns: |
| 39 |
returns = ' \N{non-breaking hyphen}> ' + returns |
| 40 |
%> |
| 41 |
%if params: |
| 42 |
> ${f.funcdef()} ${f.name}( |
| 43 |
> ${',\n> '.join(params)} |
| 44 |
> )${returns} |
| 45 |
%else: |
| 46 |
> ${f.funcdef()} ${f.name}()${returns} |
| 47 |
%endif |
| 48 |
</%def> |
| 49 |
|
| 50 |
<%def name="classdef(c)"> |
| 51 |
<% params = c.params(annotate=show_type_annotations) %> |
| 52 |
%if params: |
| 53 |
> class ${c.name}( |
| 54 |
> ${',\n> '.join(params)} |
| 55 |
> ) |
| 56 |
%else: |
| 57 |
> class ${c.name} |
| 58 |
%endif |
| 59 |
</%def> |
| 60 |
|
| 61 |
<%def name="vartype(v)"> |
| 62 |
<% annot = show_type_annotations and v.type_annotation() or '' %> |
| 63 |
%if annot: |
| 64 |
Type: `${annot}` |
| 65 |
%endif |
| 66 |
</%def> |
| 67 |
|
| 68 |
--- |
| 69 |
description: | |
| 70 |
API documentation for modules: ${', '.join(m.name for m in modules)}. |
| 71 |
|
| 72 |
lang: en |
| 73 |
|
| 74 |
classoption: oneside |
| 75 |
geometry: margin=1in |
| 76 |
papersize: a4 |
| 77 |
|
| 78 |
linkcolor: blue |
| 79 |
links-as-notes: true |
| 80 |
... |
| 81 |
% for module in modules: |
| 82 |
<% |
| 83 |
submodules = module.submodules() |
| 84 |
variables = module.variables(sort=sort_identifiers) |
| 85 |
functions = module.functions(sort=sort_identifiers) |
| 86 |
classes = module.classes(sort=sort_identifiers) |
| 87 |
|
| 88 |
def to_md(text): |
| 89 |
return _to_md(text, module) |
| 90 |
%> |
| 91 |
${title(1, ('Namespace' if module.is_namespace else 'Module') + f' `{module.name}`', module.refname)} |
| 92 |
${module.docstring | to_md} |
| 93 |
|
| 94 |
% if submodules: |
| 95 |
${title(2, 'Sub-modules')} |
| 96 |
% for m in submodules: |
| 97 |
* [${m.name}](#${m.refname}) |
| 98 |
% endfor |
| 99 |
% endif |
| 100 |
|
| 101 |
% if variables: |
| 102 |
${title(2, 'Variables')} |
| 103 |
% for v in variables: |
| 104 |
${title(3, f'Variable `{v.name}`', v.refname)} |
| 105 |
${vartype(v)} |
| 106 |
${v.docstring | to_md, subh, subh} |
| 107 |
% endfor |
| 108 |
% endif |
| 109 |
|
| 110 |
% if functions: |
| 111 |
${title(2, 'Functions')} |
| 112 |
% for f in functions: |
| 113 |
${title(3, f'Function `{f.name}`', f.refname)} |
| 114 |
|
| 115 |
${funcdef(f)} |
| 116 |
|
| 117 |
${f.docstring | to_md, subh, subh} |
| 118 |
% endfor |
| 119 |
% endif |
| 120 |
|
| 121 |
% if classes: |
| 122 |
${title(2, 'Classes')} |
| 123 |
% for cls in classes: |
| 124 |
${title(3, f'Class `{cls.name}`', cls.refname)} |
| 125 |
|
| 126 |
${classdef(cls)} |
| 127 |
|
| 128 |
${cls.docstring | to_md, subh} |
| 129 |
<% |
| 130 |
class_vars = cls.class_variables(show_inherited_members, sort=sort_identifiers) |
| 131 |
static_methods = cls.functions(show_inherited_members, sort=sort_identifiers) |
| 132 |
inst_vars = cls.instance_variables(show_inherited_members, sort=sort_identifiers) |
| 133 |
methods = cls.methods(show_inherited_members, sort=sort_identifiers) |
| 134 |
mro = cls.mro() |
| 135 |
subclasses = cls.subclasses() |
| 136 |
%> |
| 137 |
% if mro: |
| 138 |
${title(4, 'Ancestors (in MRO)')} |
| 139 |
% for c in mro: |
| 140 |
* [${c.refname}](#${c.refname}) |
| 141 |
% endfor |
| 142 |
% endif |
| 143 |
|
| 144 |
% if subclasses: |
| 145 |
${title(4, 'Descendants')} |
| 146 |
% for c in subclasses: |
| 147 |
* [${c.refname}](#${c.refname}) |
| 148 |
% endfor |
| 149 |
% endif |
| 150 |
|
| 151 |
% if class_vars: |
| 152 |
${title(4, 'Class variables')} |
| 153 |
% for v in class_vars: |
| 154 |
${title(5, f'Variable `{v.name}`', v.refname)} |
| 155 |
${vartype(v)} |
| 156 |
${v.docstring | to_md, subh, subh} |
| 157 |
% endfor |
| 158 |
% endif |
| 159 |
|
| 160 |
% if inst_vars: |
| 161 |
${title(4, 'Instance variables')} |
| 162 |
% for v in inst_vars: |
| 163 |
${title(5, f'Variable `{v.name}`', v.refname)} |
| 164 |
${vartype(v)} |
| 165 |
${v.docstring | to_md, subh, subh} |
| 166 |
% endfor |
| 167 |
% endif |
| 168 |
|
| 169 |
% if static_methods: |
| 170 |
${title(4, 'Static methods')} |
| 171 |
% for f in static_methods: |
| 172 |
${title(5, f'`Method {f.name}`', f.refname)} |
| 173 |
|
| 174 |
${funcdef(f)} |
| 175 |
|
| 176 |
${f.docstring | to_md, subh, subh} |
| 177 |
% endfor |
| 178 |
% endif |
| 179 |
|
| 180 |
% if methods: |
| 181 |
${title(4, 'Methods')} |
| 182 |
% for f in methods: |
| 183 |
${title(5, f'Method `{f.name}`', f.refname)} |
| 184 |
|
| 185 |
${funcdef(f)} |
| 186 |
|
| 187 |
${f.docstring | to_md, subh, subh} |
| 188 |
% endfor |
| 189 |
% endif |
| 190 |
% endfor |
| 191 |
% endif |
| 192 |
|
| 193 |
##\## for module in modules: |
| 194 |
% endfor |
| 195 |
|
| 196 |
----- |
| 197 |
Generated by *pdoc* ${pdoc.__version__} (<https://pdoc3.github.io>). |