Skip to content

Commit 7ad70e9

Browse files
committed
Increase readability of binding docs
Transforms some of the GDScript documentation markup to Rustdoc, using simple de-indentation and replacements. This makes bindings documentation, which has so far been a single huge code block, much more readable. Could be further improved using Regex and Rustdoc links. Adds the 'unindent' crate, which has no further dependencies.
1 parent f63ff79 commit 7ad70e9

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

bindings_generator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ proc-macro2 = "1.0.6"
2020
quote = "1.0.2"
2121
syn = { version = "1.0", features = ["full", "extra-traits", "visit"] }
2222
miniserde = "=0.1.13"
23+
unindent = "0.1.7"

bindings_generator/src/class_docs.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,12 @@ impl GodotXMLDocs {
110110
}
111111

112112
fn add_fn(&mut self, class: &str, method: &str, desc: &str, default_args: &[(&str, &str)]) {
113-
let doc = desc.trim();
113+
let mut doc = unindent::unindent(desc.trim());
114114

115115
if doc.is_empty() && default_args.is_empty() {
116116
return;
117117
}
118118

119-
let mut doc = if !doc.is_empty() {
120-
format!("```text\n{}\n```\n", doc)
121-
} else {
122-
String::new()
123-
};
124-
125119
if !default_args.is_empty() {
126120
doc.push_str("\n# Default Arguments");
127121

@@ -131,6 +125,18 @@ impl GodotXMLDocs {
131125
}
132126

133127
self.class_fn_desc
134-
.insert((class.into(), method.into()), doc);
128+
.insert((class.into(), method.into()), Self::reformat_as_rustdoc(doc));
129+
}
130+
131+
/// Takes the Godot documentation markup and transforms it to Rustdoc.
132+
/// Very basic approach with limitations, but already helps readability quite a bit.
133+
fn reformat_as_rustdoc(godot_doc: String) -> String {
134+
godot_doc
135+
.replace("[code]", "`")
136+
.replace("[/code]", "`")
137+
.replace("[codeblock]", "```gdscript")
138+
.replace("[/codeblock]", "```")
139+
.replace("[b]", "**")
140+
.replace("[/b]", "**")
135141
}
136142
}

0 commit comments

Comments
 (0)