Commit 22f89011 authored by Nic's avatar Nic
Browse files

improve autodoc

parent 078ce63a
......@@ -73,21 +73,23 @@ def _include(filename, relative_to=False, relative_prefix=None, literal=False):
# slugification and label forger
# =============================================================================
ROLES = re.compile(":\w+:")
DUPLICATED = re.compile("(_){2,}")
DUPLICATED_UNDERSCORE = re.compile("(_){2,}")
DUPLICATED_DASH = re.compile("(-){2,}")
REMAINS = re.compile("\W")
def _slugify(text):
text = ROLES.sub("", text)
text = REMAINS.sub("_", text)
text = DUPLICATED.sub("_", text)
return text.strip("_").strip("=").lower()
text = ROLES.sub("", text) # ":orange:" -> ""
text = REMAINS.sub("-", text) # everything not ASCII or DIGIT -> "-"
text = DUPLICATED_DASH.sub("-", text) # ---- -> -
text = DUPLICATED_UNDERSCORE.sub("-", text) # _____ -> -
return text.strip("-").strip("=").lower()
def _make_label(text, prefix=""):
text = _slugify(text)
if prefix:
return f"\n.. _{prefix}_{text}:\n"
return f"\n.. _{prefix}-{text}:\n"
return f"\n.. _{text}:\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment