summaryrefslogtreecommitdiff
path: root/doc/tools/make_rst.py
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-05-12 21:13:21 +0200
committerGitHub <noreply@github.com>2022-05-12 21:13:21 +0200
commit826f5358a124c8f0645a9536c32545cf4a5bc364 (patch)
treecff58ab800c88ff7bdedeb53d5032e7199e0381c /doc/tools/make_rst.py
parentff30a0999374309eca206e7e45185549ef7f3c93 (diff)
parent38cf07b768074b9f9fd5e9081cce9af2dc8b089f (diff)
Merge pull request #60771 from snailrhymer/enum-indentation-doc-fix
Indent bullet points in enum descriptions
Diffstat (limited to 'doc/tools/make_rst.py')
-rwxr-xr-xdoc/tools/make_rst.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/doc/tools/make_rst.py b/doc/tools/make_rst.py
index 1b98699c44..2e227ce578 100755
--- a/doc/tools/make_rst.py
+++ b/doc/tools/make_rst.py
@@ -677,7 +677,8 @@ def make_rst_class(class_def, state, dry_run, output_dir): # type: (ClassDef, S
for value in e.values.values():
f.write("- **{}** = **{}**".format(value.name, value.value))
if value.text is not None and value.text.strip() != "":
- f.write(" --- " + rstize_text(value.text.strip(), state))
+ # If value.text contains a bullet point list, each entry needs additional indentation
+ f.write(" --- " + indent_bullets(rstize_text(value.text.strip(), state)))
f.write("\n\n")
@@ -904,7 +905,7 @@ def rstize_text(text, state): # type: (str, State) -> str
pre_text = text[:pos]
indent_level = 0
- while text[pos + 1] == "\t":
+ while pos + 1 < len(text) and text[pos + 1] == "\t":
pos += 1
indent_level += 1
post_text = text[pos + 1 :]
@@ -1440,5 +1441,24 @@ def sanitize_operator_name(dirty_name, state): # type: (str, State) -> str
return clear_name
+def indent_bullets(text): # type: (str) -> str
+ # Take the text and check each line for a bullet point represented by "-".
+ # Where found, indent the given line by a further "\t".
+ # Used to properly indent bullet points contained in the description for enum values.
+ # Ignore the first line - text will be prepended to it so bullet points wouldn't work anyway.
+ bullet_points = "-"
+
+ lines = text.splitlines(keepends=True)
+ for line_index, line in enumerate(lines[1:], start=1):
+ pos = 0
+ while pos < len(line) and line[pos] == "\t":
+ pos += 1
+
+ if pos < len(line) and line[pos] in bullet_points:
+ lines[line_index] = line[:pos] + "\t" + line[pos:]
+
+ return "".join(lines)
+
+
if __name__ == "__main__":
main()