Skip to content

Commit e00bd0c

Browse files
feat: support additional doc comment markdown
Simulates formatting that Godot does not natively support in its limited BBCode implementation, such as lists and footnotes, as best as possible. Also fixes #811 as paragraphs are correctly formatted, without excessive line breaks.
1 parent 7461251 commit e00bd0c

File tree

5 files changed

+378
-62
lines changed

5 files changed

+378
-62
lines changed

godot-codegen/src/generator/central_files.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub fn make_sys_central_code(api: &ExtensionApi) -> TokenStream {
3737
// This will need refactoring if VariantType is changed to a real enum.
3838
#[doc(hidden)]
3939
pub fn from_sys(enumerator: crate::GDExtensionVariantType) -> Self {
40+
#[allow(clippy::unnecessary_cast)]
4041
Self { ord: enumerator as i32 }
4142
}
4243

godot-macros/src/docs.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,29 @@ fn xml_escape(value: String) -> String {
146146
result
147147
}
148148

149+
/// Utility function that, given a line from a code comment, returns the line
150+
/// without the first leading space if it exists. This space is commonly used
151+
/// to separate the comment from the `///` that precedes it, but interferes
152+
/// with the formatting of the resulting Markdown.
153+
fn remove_initial_space(comment_line: &str) -> &str {
154+
if comment_line.starts_with(" ") {
155+
&comment_line[1..]
156+
} else {
157+
comment_line
158+
}
159+
}
160+
149161
/// Calls [`siphon_docs_from_attributes`] and converts the result to BBCode
150162
/// for Godot's consumption.
151163
fn make_docs_from_attributes(doc: &[Attribute]) -> Option<String> {
152-
let doc = siphon_docs_from_attributes(doc)
164+
let lines: Vec<String> = siphon_docs_from_attributes(doc).collect();
165+
166+
let doc = lines
167+
.iter()
168+
.map(|line| remove_initial_space(line))
153169
.collect::<Vec<_>>()
154170
.join("\n");
171+
155172
(!doc.is_empty()).then(|| markdown_converter::to_bbcode(&doc))
156173
}
157174

0 commit comments

Comments
 (0)