Skip to content

Commit a307ec5

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 godot-rust#811 as paragraphs are correctly formatted, without excessive line breaks.
1 parent 7461251 commit a307ec5

File tree

5 files changed

+368
-62
lines changed

5 files changed

+368
-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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,17 @@ fn xml_escape(value: String) -> String {
149149
/// Calls [`siphon_docs_from_attributes`] and converts the result to BBCode
150150
/// for Godot's consumption.
151151
fn make_docs_from_attributes(doc: &[Attribute]) -> Option<String> {
152-
let doc = siphon_docs_from_attributes(doc)
152+
let lines: Vec<String> = siphon_docs_from_attributes(doc).collect();
153+
154+
let doc = lines
155+
.iter()
156+
// Strips the line of the first leading space if it exists. This space
157+
// is commonly used to separate the comment from the `///` that precedes
158+
// it, but interferes with the formatting of the resulting Markdown.
159+
.map(|line| line.strip_prefix(" ").unwrap_or(line))
153160
.collect::<Vec<_>>()
154161
.join("\n");
162+
155163
(!doc.is_empty()).then(|| markdown_converter::to_bbcode(&doc))
156164
}
157165

0 commit comments

Comments
 (0)