Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support additional doc comment markdown #1017

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adalinesimonian
Copy link

@adalinesimonian adalinesimonian commented Jan 18, 2025

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.

Markup
/// *documented* ~ **documented** ~ [AABB] < [pr](https://github.com/godot-rust/gdext/pull/748)
/// 
/// This is a paragraph. It has some text in it. It's a paragraph. It's quite
/// long, and wraps multiple lines. It is describing the struct `Player`. Or
/// maybe perhaps it's describing the module. It's hard to say, really. It even
/// has some code in it: `let x = 5;`. And some more code: `let y = 6;`. And a
/// bunch of **bold** and *italic* text with _different_ ways to do it. Don't
/// forget about [links](https://example.com).
///
/// a few tests:
///
/// headings:
///
/// # Some heading
///
/// lists:
///
/// - lists
/// - like this
///   - with sublists  
///     that are multiline
///     - and subsublists
/// - and list items
/// * maybe with `*` as well
/// 
/// [reference-style link][somelink]
///
/// links with back-references:
///
/// Blah blah[^foo] Also same reference[^foo]
/// [^foo]: https://example.org
///
/// footnotes:
///
/// We cannot florbinate the glorb[^florb]
/// [^florb]: because the glorb doesn't flibble.
/// 
/// Third note in order of use[^1] and fourth [^bignote]
/// 
/// [^1]: This is the third footnote in order of definition.
/// [^bignote]: Fourth footnote in order of definition.
/// [^biggernote]: This is the fifth footnote in order of definition.
/// 
/// Fifth note in order of use. [^someothernote]
/// 
/// [^someothernote]: sixth footnote in order of definition.
/// 
/// Sixth footnote in order of use. [^biggernote]
///
/// task lists:
///
/// We must ensure that we've completed
/// - [ ] task 1
/// - [x] task 2
///
/// tables:
///
/// | Header1 | Header2 |
/// |---------|---------|
/// | abc     | def     |
///
/// images:
///
/// ![Image](https://godotengine.org/assets/press/logo_small_color_light.png)
/// 
/// ![Image][image]
///
/// blockquotes:
///
/// > Some cool thing
///
/// ordered list:
///
/// 1. thing one
/// 2. thing two
///     1. thing two point one
///     2. thing two point two
///     3. thing two point three
///
///
/// Something here < this is technically header syntax
/// ---
/// And here
///
/// smart punctuation
///
/// codeblocks:
///
/// ```rust
/// #![no_main]
/// #[link_section=".text"]
/// #[no_mangle]
/// static main: u64 = 0x31c0678b10;
/// ```
/// 
/// ```gdscript
/// extends Node
/// 
/// func _ready():
///    print("Hello, world!")
/// ```
/// 
/// ```csharp
/// using Godot;
/// 
/// public class Player : Node2D
/// {
///     [Export]
///     public float Speed = 400.0f;
/// }
/// ```
///
/// Some HTML to make sure it's properly escaped:
///
/// <br/> <- this is inline HTML
///
/// &lt;br/&gt; <- not considered HTML (manually escaped)
///
/// `inline<br/>code`
///
/// ```html
/// <div>
///   code&nbsp;block
/// </div>
/// ```
///
/// [Google: 2 + 2 < 5](https://www.google.com/search?q=2+%2B+2+<+5)
///
/// connect
/// these
/// 
/// [somelink]: https://example.com
/// [image]: https://godotengine.org/assets/press/logo_small_color_dark.png
Output

Screenshot
Screenshot
Screenshot
Screenshot

Copy link
Member

@lilizoey lilizoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really nice to get done! i think overall it looks pretty good, largely just some style questions here and there. it's a bit unfortunate that the diff is confused here though

godot-macros/src/docs.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Show resolved Hide resolved
@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1017

@lilizoey lilizoey added documentation Improvements or additions to documentation c: register Register classes, functions and other symbols to GDScript feature Adds functionality to the library and removed documentation Improvements or additions to documentation labels Jan 18, 2025
Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for improving this part, really great work!

I also like how you emulate absent features like superscripts and list bullets 👍

godot-macros/src/docs.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
@adalinesimonian adalinesimonian force-pushed the better-docs branch 3 times, most recently from 8c6d678 to 2cfe302 Compare January 20, 2025 08:23
Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Upon closer look, the code is of really high quality, and the implementation looks very solid. I mostly pointed out some smaller formatting/readability issues. Could you also run rustfmt?

I'll also try to find some time to test it in action 🙂

godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
godot-macros/src/docs/markdown_converter.rs Outdated Show resolved Hide resolved
@adalinesimonian adalinesimonian force-pushed the better-docs branch 2 times, most recently from 52e0433 to 7e07fa1 Compare January 22, 2025 07:39
@adalinesimonian
Copy link
Author

Addressed the review comments and rebased onto the main branch.

@adalinesimonian
Copy link
Author

Apparently I borked the ordered list incremention. Whoops.

@adalinesimonian
Copy link
Author

Should be good now.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: register Register classes, functions and other symbols to GDScript feature Adds functionality to the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs comments do not follow usual markdown newline rules
4 participants