Skip to content

Commit

Permalink
feat: support additional doc comment markdown
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adalinesimonian committed Jan 18, 2025
1 parent 7461251 commit a842f82
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 62 deletions.
1 change: 1 addition & 0 deletions godot-codegen/src/generator/central_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn make_sys_central_code(api: &ExtensionApi) -> TokenStream {
// This will need refactoring if VariantType is changed to a real enum.
#[doc(hidden)]
pub fn from_sys(enumerator: crate::GDExtensionVariantType) -> Self {
#[allow(clippy::unnecessary_cast)]
Self { ord: enumerator as i32 }
}

Expand Down
10 changes: 9 additions & 1 deletion godot-macros/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,17 @@ fn xml_escape(value: String) -> String {
/// Calls [`siphon_docs_from_attributes`] and converts the result to BBCode
/// for Godot's consumption.
fn make_docs_from_attributes(doc: &[Attribute]) -> Option<String> {
let doc = siphon_docs_from_attributes(doc)
let lines: Vec<String> = siphon_docs_from_attributes(doc).collect();

let doc = lines
.iter()
// Strips the line of the first leading space if it exists. This space
// is commonly used to separate the comment from the `///` that precedes
// it, but interferes with the formatting of the resulting Markdown.
.map(|line| line.strip_prefix(" ").unwrap_or(line))
.collect::<Vec<_>>()
.join("\n");

(!doc.is_empty()).then(|| markdown_converter::to_bbcode(&doc))
}

Expand Down
Loading

0 comments on commit a842f82

Please sign in to comment.