doc: Add link to argument details

pull/11765/head
Xavier Claessens 2 years ago committed by Xavier Claessens
parent e94de2b872
commit 4ed5c0eefa
  1. 11
      docs/refman/generatormd.py
  2. 2
      docs/refman/templates/args.mustache

@ -161,6 +161,9 @@ class GeneratorMD(GeneratorBase):
# I know, this regex is ugly but it works.
return len(re.sub(r'\[\[(#|@)*([^\[])', r'\2', s))
def arg_anchor(arg: ArgBase) -> str:
return f'{func.name}_{arg.name.replace("<", "_").replace(">", "_")}'
def render_signature() -> str:
# Skip a lot of computations if the function does not take any arguments
if not any([func.posargs, func.optargs, func.kwargs, func.varargs]):
@ -184,12 +187,15 @@ class GeneratorMD(GeneratorBase):
max_name_len = max([len(x.name) for x in all_args])
# Generate some common strings
def prepare(arg: ArgBase) -> T.Tuple[str, str, str, str]:
def prepare(arg: ArgBase, link: bool = True) -> T.Tuple[str, str, str, str]:
type_str = render_type(arg.type, True)
type_len = len_stripped(type_str)
type_space = ' ' * (max_type_len - type_len)
name_space = ' ' * (max_name_len - len(arg.name))
name_str = f'<b>{arg.name.replace("<", "&lt;").replace(">", "&gt;")}</b>'
if link:
name_str = f'<a href="#{arg_anchor(arg)}">{name_str}</a>'
return type_str, type_space, name_str, name_space
for i in func.posargs:
@ -201,7 +207,7 @@ class GeneratorMD(GeneratorBase):
signature += f' {type_str}{type_space} [{name_str}],{name_space} # {self.brief(i)}\n'
if func.varargs:
type_str, type_space, name_str, name_space = prepare(func.varargs)
type_str, type_space, name_str, name_space = prepare(func.varargs, link=False)
signature += f' {type_str}{type_space} {name_str}...,{name_space} # {self.brief(func.varargs)}\n'
# Abort if there are no kwargs
@ -227,6 +233,7 @@ class GeneratorMD(GeneratorBase):
def gen_arg_data(arg: T.Union[PosArg, Kwarg, VarArgs], *, optional: bool = False) -> T.Dict[str, PlaceholderTypes]:
data: T.Dict[str, PlaceholderTypes] = {
'row-id': arg_anchor(arg),
'name': arg.name,
'type': render_type(arg.type),
'description': arg.description,

@ -13,7 +13,7 @@
</thead>
<tbody class="nomargin">
{{#args}}
<tr>
<tr id="{{row-id}}">
<td style="white-space: nowrap; text-align: center; padding: 6px;"><code class="language-meson">{{name}}</code></td>
<td style="white-space: revert; text-align: center; padding: 6px; word-wrap: break-word;">{{&type}}</td>
<!-- This suboptimal formatting is required to ensure hotdoc correctly generates the HTML -->

Loading…
Cancel
Save