-
Notifications
You must be signed in to change notification settings - Fork 269
Change write_to_html to allow fmt::Write
#870
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
Change write_to_html to allow fmt::Write
#870
Conversation
|
This must be reviewed and analyzed, but yes, it is a breaking change, and yes, it means an increment of the version number and indeed it is planned for the 0.11 milestone (#492). Also, this pull request should be created against the branch 'branch_0.11', that is the branch where all breaking changes for the 0.11 version are being merged. Thanks! |
56fcf0e to
4a79f63
Compare
4a79f63 to
42b8274
Compare
|
Interesting approach, it seems the only inconvenience is having to manually create a IoWrapper or a FmtWrapper... And I think it could be solved implementing |
Do you mean
Fixed and rebased. |
42b8274 to
081a4d2
Compare
|
I see, so this seems OK for me, but I would like considering other options and the opinion from other reviewers before merging it. Thanks! |
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.
API-wise I definitely prefer the idea of just having separate entry functions write_html_io/fmt. Having to use the name write_html_fmt for strings (the most common case) is a little obtuse. Maybe we could keep push_html anyway. Although it is technically redundant, the name is a bit clearer and keeping it would reduce breakage.
Internally using a trait with an associated error type for writing looks good to me.
Co-authored-by: Roope Salmi <rpsalmi@gmail.com>
|
I agree with @ollpu. Less complex API with less surface area is better. |
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.
Great!
It would be even better if we didn't have to expose StrWrite and the wrappers in pulldown-cmark-escape. I guess one way to do it would be to have structs that impl Display, e.g. EscapeHtml, and always using write!() or similar. That's something for a later PR though.
|
Perfect, merge! Adding the The other remaining issue for the 0.11 is #67. |
|
I'm trying to hide Respect to the My implementation for those structs (example only with pub struct EscapedHtml<'a> {
html: &'a str,
}
impl<'a> fmt::Display for EscapedHtml<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut buffer = String::new();
escape_html(&mut buffer, self.html)?;
write!(f, "{}", buffer)
}
} |
|
On the first point, to be able to hide For the struct Display approach, you can do this with the current The internal functions could just take |
|
I would leave as public the trait and the structs in the pulldown_cmark_escape crate, since it is more low-level, instead of duplicating them in pulldown_cmark. But this approach would not avoid the use of But I'm probably missing something... |
Hm, these simple forwarding calls almost certainly should be zero cost and either get inlined to where they're called or inline internal writer call into them (whatever compiler decides based on heuristics). |
|
@Martin1887 If the escaping works through Display impls, then it can be used with either fmt or io writers by using There's definitely more for the optimizer to chew on, and I'm also vary of having extra layers of And yes, something similar to |
|
I think it is worthy for an easier interface to escape HTML strings, and we could even using them in the Could you create the pull request? Thanks! |
This PR upgrades `pulldown_cmark` to v0.12. There were a few breaking changes that needed to be accounted for: - The `BlockQuote` variant now has a `kind` attached. Right now we're ignoring it. - `pulldown_cmark` now emits tags for definition lists. This codepath has been left unimplemented, for now. ### Release Notes <details> <summary>raphlinus/pulldown-cmark (pulldown-cmark)</summary> ### [`v0.12.1`](https://redirect.github.com/pulldown-cmark/pulldown-cmark/releases/tag/v0.12.1): 0.12.1 [Compare Source](https://redirect.github.com/raphlinus/pulldown-cmark/compare/v0.12.0...v0.12.1) ##### Security - Fix O(n\*\*2) comment parser by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/941](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/941) ##### New features - impl From<CowStr> for String by [@​oconnor663](https://redirect.github.com/oconnor663) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/943](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/943) ##### Developers - Make dos-fuzzer part of the workspace by [@​kdarkhan](https://redirect.github.com/kdarkhan) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/945](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/945) ##### New Contributors - [@​oconnor663](https://redirect.github.com/oconnor663) made their first contribution in [https://github.com/pulldown-cmark/pulldown-cmark/pull/943](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/943) - [@​kdarkhan](https://redirect.github.com/kdarkhan) made their first contribution in [https://github.com/pulldown-cmark/pulldown-cmark/pull/945](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/945) **Full Changelog**: pulldown-cmark/pulldown-cmark@v0.12.0...v0.12.1 ### [`v0.12.0`](https://redirect.github.com/pulldown-cmark/pulldown-cmark/releases/tag/v0.12.0): 0.12.0 [Compare Source](https://redirect.github.com/raphlinus/pulldown-cmark/compare/v0.11.3...v0.12.0) Thanks to all contributors! This release mainly adds the long awaited commonmark-hs description lists (under a flag) and enables the blockquote kind in `TagEnd` reverted in 0.11.2. #### Breaking changes - feat: re-add kind for BlockQuote in TagEnd by [@​Martin1887](https://redirect.github.com/Martin1887) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/940](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/940) - Refactor TextMergeStream by [@​ollpu](https://redirect.github.com/ollpu) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/931](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/931) #### New features - Implement commonmark-hs compatible definition lists by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/915](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/915) #### Other changes - Rename superlinear time fuzzer to `dos-fuzzer` by [@​ollpu](https://redirect.github.com/ollpu) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/938](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/938) **Full Changelog**: pulldown-cmark/pulldown-cmark@v0.11.2...v0.12.0 ### [`v0.11.3`](https://redirect.github.com/pulldown-cmark/pulldown-cmark/releases/tag/v0.11.3): 0.11.3 [Compare Source](https://redirect.github.com/raphlinus/pulldown-cmark/compare/v0.11.2...v0.11.3) #### Security - Fix O(n\*\*2) comment parser by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/944](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/944) **Full Changelog**: pulldown-cmark/pulldown-cmark@v0.11.2...v0.11.3 ### [`v0.11.2`](https://redirect.github.com/pulldown-cmark/pulldown-cmark/releases/tag/v0.11.2) [Compare Source](https://redirect.github.com/raphlinus/pulldown-cmark/compare/v0.11.1...v0.11.2) Revert BlockQuote kind to avoid breaking change. ### [`v0.11.1`](https://redirect.github.com/pulldown-cmark/pulldown-cmark/releases/tag/v0.11.1) [Compare Source](https://redirect.github.com/raphlinus/pulldown-cmark/compare/v0.11.0...v0.11.1) Thanks to all people involved in this release! The main change of this release is the reduction of the MSRV to 1.71.1, but it also includes a lot of bug fixes and a new mdBook for user-friendly documentation. #### Breaking changes - Add BlockQuoteKind to BlockQuote TagEnd by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/926](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/926) (reverted in v0.11.2) #### What's Changed - fix: CowStr deserialization when escaping by [@​aatifsyed](https://redirect.github.com/aatifsyed) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/895](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/895) - fix(test): fix generating spec tests doesn't work on Windows due to line-endings by [@​rhysd](https://redirect.github.com/rhysd) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/903](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/903) - feat: add `-G` CLI option to enable GFM support by [@​rhysd](https://redirect.github.com/rhysd) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/905](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/905) - feat: set `DefaultBrokenLinkCallback` as the default broken link callback of `OffsetIter` by [@​rhysd](https://redirect.github.com/rhysd) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/901](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/901) - chore(doc): use `cargo add` to instruct how to install this crate as dependency by [@​rhysd](https://redirect.github.com/rhysd) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/904](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/904) - fix typo by [@​jmbhughes](https://redirect.github.com/jmbhughes) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/909](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/909) - Fix parsing blocks inside alert body by [@​rhysd](https://redirect.github.com/rhysd) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/908](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/908) - fuzz: fix building fuzzer and improve fuzzing coverage by enabling more parse options by [@​rhysd](https://redirect.github.com/rhysd) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/910](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/910) - fix: fix warnings reported from nightly rustc by [@​rhysd](https://redirect.github.com/rhysd) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/911](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/911) - fix: fix infinite loop when metadata delimiter is indented by [@​rhysd](https://redirect.github.com/rhysd) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/913](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/913) - Raise the link cutoff from 5 to 32 by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/917](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/917) - Reduce MSRV to 1.71.1 by separating benchmarks into a new crate with CI enhancements by [@​rhysd](https://redirect.github.com/rhysd) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/916](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/916) - Add guide book and deploy script for it by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/883](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/883) - ci: fix deploying the document to GitHub Pages and make the deploy job faster by [@​rhysd](https://redirect.github.com/rhysd) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/920](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/920) - Fix lone task list item bug by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/924](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/924) - Fix offset range around footnotes that look like images by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/925](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/925) - Update old footnote format to interrupt paragraph by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/928](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/928) - Fix confusing bug with back-to-back footnotes by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/930](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/930) - Add reproduction cases for [#​927](https://redirect.github.com/raphlinus/pulldown-cmark/issues/927) by [@​zoni](https://redirect.github.com/zoni) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/929](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/929) - Add regression test for [#​655](https://redirect.github.com/raphlinus/pulldown-cmark/issues/655) by [@​ollpu](https://redirect.github.com/ollpu) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/932](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/932) - Renovate the superlinear time fuzzer by [@​ollpu](https://redirect.github.com/ollpu) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/935](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/935) #### New Contributors - [@​aatifsyed](https://redirect.github.com/aatifsyed) made their first contribution in [https://github.com/pulldown-cmark/pulldown-cmark/pull/895](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/895) - [@​jmbhughes](https://redirect.github.com/jmbhughes) made their first contribution in [https://github.com/pulldown-cmark/pulldown-cmark/pull/909](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/909) - [@​zoni](https://redirect.github.com/zoni) made their first contribution in [https://github.com/pulldown-cmark/pulldown-cmark/pull/929](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/929) **Full Changelog**: pulldown-cmark/pulldown-cmark@v0.11.0...v0.11.1 ### [`v0.11.0`](https://redirect.github.com/pulldown-cmark/pulldown-cmark/releases/tag/v0.11.0): 0.11.0 [Compare Source](https://redirect.github.com/raphlinus/pulldown-cmark/compare/v0.10.3...v0.11.0) ##### Finally, the so long awaited math mode is here! Enable the option to use it. This release also includes other improvements and bugfixes, please see the changelog below for more details. Thanks to all contributors that has made possible this release! #### Breaking changes - Change `write_to_html` to allow `fmt::Write` by [@​stepantubanov](https://redirect.github.com/stepantubanov) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/870](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/870) #### New features - Math mode #### Bugfixes - \[0.11] Don't exit `scan_attribute` with the ix pointing at block quote by [@​notriddle](https://redirect.github.com/notriddle) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/873](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/873) - (Re)introduce simd feature to pulldown-cmark-escape by [@​ollpu](https://redirect.github.com/ollpu) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/880](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/880) - fix: remove unnecessary end_newline set by [@​tomcur](https://redirect.github.com/tomcur) in [https://github.com/pulldown-cmark/pulldown-cmark/pull/885](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/885) #### New Contributors - [@​duskmoon314](https://redirect.github.com/duskmoon314) made their first contribution in [https://github.com/pulldown-cmark/pulldown-cmark/pull/874](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/874) - [@​stepantubanov](https://redirect.github.com/stepantubanov) made their first contribution in [https://github.com/pulldown-cmark/pulldown-cmark/pull/870](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/870) - [@​tomcur](https://redirect.github.com/tomcur) made their first contribution in [https://github.com/pulldown-cmark/pulldown-cmark/pull/885](https://redirect.github.com/pulldown-cmark/pulldown-cmark/pull/885) **Full Changelog**: pulldown-cmark/pulldown-cmark@v0.10.3...v0.11.0 </details> Release Notes: - N/A
Previous attempt:
std::fmt::Writeinstead of customStrWritetrait #493In this version I've just added an associated type on
StrWriteso thatio::Errorisn't lost. Let me know if that makes sense.Other alternatives: Instead of exposing
StrWrite,IoWriterandFmtWriterwe can expose two functions:write_html_ioandwrite_html_fmtthat acceptio::Writeandfmt::Write(push_htmlcan be removed then).NOTE. This is a breaking change (should this PR bump version?)Changed base to 0.11