schemars icon indicating copy to clipboard operation
schemars copied to clipboard

Handling of newline in RustDoc

Open ralpha opened this issue 4 years ago • 4 comments

Should or should we not change the default parsing behavior from the current (removing single \n in RustDoc) to just leaving the newline in.

To clarify for everyone we are talking about:

/// Some documentation
/// on multiple lines
/// right here.
/// 
/// This is a new paragraph.
struct Test{
   // ...
}

Should this result in:

"Some documentation on multiple lines right here.\n\nThis is a new paragraph." // Current (2021/11/25)
// or
"Some documentation\non multiple lines\nright here.\n\nThis is a new paragraph." // If we change is back

This question came up in: https://github.com/GREsau/schemars/issues/38

The intention is that it removes extraneous newlines from simple text doc comments, since they may be spread across multiple lines just to keep the line length of the original Rust source reasonable, which ideally wouldn't affect any generated schema. However, this does indeed mangle more complex markdown e.g. code blocks and lists, so it might be doing more harm than good... I'm definitely considering removing this behaviour, and passing down the docstring unaltered as you suggest

https://github.com/GREsau/schemars/issues/38#issuecomment-826395307

A Visitor can be created to do this behavior and users can enable or disable it as they want. But the default has to be one way or the other. (to be decided in this issue)

ralpha avatar Nov 25 '21 18:11 ralpha

As I described in #129, I would personally like the default behaviour to use the raw doc comment. It should definitely be an option at least. For my project I am currently working off of a fork to get this functionality: diff

I'd be happy to submit a PR for this. Please let me know what you'd like to see implemented

blake-mealey avatar Feb 02 '22 16:02 blake-mealey

There's really no good reason to strip excess newlines. By the CommonMark spec, these should already be treated as soft line breaks and handled during rendering: https://spec.commonmark.org/0.30/#softbreak

abonander avatar Apr 19 '22 19:04 abonander

What about if we want the new lines? For instance, I have the following in my docs:

/// HTTP API scope definition.
/// It is a list of URLs that can be accessed by the webview when using the HTTP APIs.
/// The scoped URL is matched against the request URL using a glob pattern.
///
/// Examples:
/// 
///  - "https://**": allows all HTTPS urls
///  - "https://*.github.com/tauri-apps/tauri": allows any subdomain of "github.com" with the "tauri-apps/api" path
///  - "https://myapi.service.com/users/*": allows access to any URLs that begins with "https://myapi.service.com/users/"

and I want to explicitly have the new lines come through so the bullet points get rendered out correctly. Would there be a keyword per line I could use to "opt-in" for a new line?

lorenzolewis avatar May 18 '22 11:05 lorenzolewis