Skip to content

Commit

Permalink
Allow one level of sub-lists in node docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzBrueckner committed May 21, 2021
1 parent 40b09be commit 860b41a
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions make_node_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ def get_nodetype(typename: str):
return bpy.types.bpy_struct.bl_rna_get_subclass_py(typename)


def format_desc(description_text: str):
"""Format the raw description string."""
# Remove spaces, tabs and carriage returns left/right of each line
lines = [l.strip(" \t\r") for l in description_text.split("\n")]

# Replace empty lines with \n
lines = list(map(lambda l: l.replace("", "\n") if l == "" else l, lines))

# Remove empty lines from the end of the list
for idx, line in enumerate(reversed(lines)):
if line != "\n":
# [:0] would empty the list, instead ignore it
if idx != 0:
lines = lines[0:-idx]
break # We reached the actual content

# Indent sub-lists (one level only, more is not required right now)
# Indentation is 2 spaces per markdown standard in this case, one
# is added by " ".join() later
lines = [(" " + line if line.startswith("- ") else line) for line in lines]

return " ".join(lines)


def generate_node_documentation(nodeitem: NodeItem, category: arm_nodes.ArmNodeCategory):
nodetype = get_nodetype(nodeitem.nodetype)
doc: str = nodetype.__doc__
Expand Down Expand Up @@ -114,7 +138,7 @@ def generate_node_documentation(nodeitem: NodeItem, category: arm_nodes.ArmNodeC
Document.add(UnorderedList(input_list))

socket_name, description = part[6:].split(":", 1)
description = " ".join(description.split()).replace("\n", "")
description = format_desc(description)
input_list.append(f"{InlineCode(socket_name)}: {description}")

# Output sockets
Expand All @@ -125,7 +149,7 @@ def generate_node_documentation(nodeitem: NodeItem, category: arm_nodes.ArmNodeC
Document.add(UnorderedList(output_list))

socket_name, description = part[7:].split(":", 1)
description = " ".join(description.split()).replace("\n", "")
description = format_desc(description)
output_list.append(f"{InlineCode(socket_name)}: {description}")

# Other UI options
Expand All @@ -136,7 +160,7 @@ def generate_node_documentation(nodeitem: NodeItem, category: arm_nodes.ArmNodeC
Document.add(UnorderedList(option_list))

option_name, description = part[7:].split(":", 1)
description = " ".join(description.split()).replace("\n", "")
description = format_desc(description)
option_list.append(f"{InlineCode(option_name)}: {description}")

elif part.startswith("deprecated "):
Expand Down

0 comments on commit 860b41a

Please sign in to comment.