-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustdoc: Add a custom callback for codespan to collapse whitespace #24116
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
Conversation
Because the current style for `code` in rustdoc is to prewrap whitespace, code spans that are hard wrapped in the source documentation are prematurely wrapped when rendered in HTML. CommonMark 0.18 [[1]] specifies "interior spaces and line endings are collapsed into single spaces" for code spans, which would actually prevent this issue, but hoedown does not currently conform to the CommonMark spec. The added span-level callback attempts to adhere to how whitespace is handled as described by CommonMark, fixing the issue of early, unintentional wrapping of code spans in rendered HTML. [1]: http://spec.commonmark.org/0.18/
c26b66e
to
b6c2e82
Compare
Ouch! We don't strictly follow CommonMark, but I like this. |
} | ||
} | ||
|
||
buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this would be a little clearer leveraging iterators?
s.split(|c: char| c.is_whitespace()).filter(|s| {
!s.is_empty()
}).collect::<Vec<_>>().connect(" ")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's clean, thanks! I didn't know str::split
could take a closure.
Nice fix! |
4a78e81
to
46cc6e5
Compare
Because the current style for `code` in rustdoc is to prewrap whitespace, code spans that are hard wrapped in the source documentation are prematurely wrapped when rendered in HTML. [For example][2], ``` /// ... /// type can be borrowed as multiple different types. In particular, `Vec<T>: /// Borrow<Vec<T>>` and `Vec<T>: Borrow<[T]>`. ``` renders as  because "`Vec<T>: Borrow<Vec<T>>`" wraps to the next line in the source. CommonMark 0.18 [[1]] specifies "interior spaces and line endings are collapsed into single spaces" for code spans, which would actually prevent this issue, but hoedown does not currently conform to the CommonMark spec. The added span-level callback attempts to adhere to how whitespace is handled as described by CommonMark, fixing the issue of early, unintentional wrapping of code spans in rendered HTML. [1]: http://spec.commonmark.org/0.18/ [2]: https://doc.rust-lang.org/std/borrow/trait.Borrow.html
⌛ Testing commit 46cc6e5 with merge de51bbe... |
Because the current style for
code
in rustdoc is to prewrap whitespace, code spans that are hard wrapped in the source documentation are prematurely wrapped when rendered in HTML. For example,renders as
because "
Vec<T>: Borrow<Vec<T>>
" wraps to the next line in the source.CommonMark 0.18 [1] specifies "interior spaces and line endings are collapsed into single spaces" for code spans, which would actually prevent this issue, but hoedown does not currently conform to the
CommonMark spec.
The added span-level callback attempts to adhere to how whitespace is handled as described by CommonMark, fixing the issue of early, unintentional wrapping of code spans in rendered HTML.