-
Notifications
You must be signed in to change notification settings - Fork 37
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
[Feature Request] Add option to allow users to turn off escaping special character #51
Comments
Awesome! Yes, I see why this would be useful and I'd love to see this crate help making To me it seems absolutely fair to have a special option to support this requirement, and I wouldn't mind to keep adding those to make this crate more suitable for A PR is definitely welcome, and you should find everything you need to write some unit tests for that as well. Regarding the suggested solution, I'd hope we can get around adding an option at all (which admittedly might not be possible, but here I go): this crate should ideally not alter any input, and I wonder why it feels the need to escape these characters anyway - they have not been escaped before and should automatically not be escaped when printing them. Doing so might be possible if the event in question provides enough information explicitly or implicitly, and it's definitely something you could study in greater detail one you have setup a test or two. Having an option for this specifically feels like a crutch that we can put on but only if there truly is no other way. |
Thanks for the quick reply! I also appreciate your willingness to accommodating some of rustfmt's needs 😁. I'll continue to look into what's going on with the special character escaping to see if we can avoid adding the additional option. I've written two test and here's what I've managed to figure out so far: #[test]
fn rustdoc_type_link_shortcut_code_links() {
assert_eq!(
fmts("[`Vec`]"),
(
"\\[`Vec`\\]".into(),
State {
newlines_before_start: 2,
..Default::default()
}
)
)
} And the input generates the following events:
When we modify the test to use #[test]
fn start_with_escaped_rustdoc_type_link_shortcut_code_links() {
assert_eq!(
fmts("\\[`Vec`\\]"),
(
"\\[`Vec`\\]".into(),
State {
newlines_before_start: 2,
..Default::default()
}
)
)
}
If the For my own curiosity, I was wondering if you could help me better understand the comment in
When it comes to adding other features that I'd like to use for rustfmt would you prefer that I open an issue first so we can have a discussion about it or would you prefer I just submit a PR? |
Great research right there! It looks like with the current version of the parser escaping of these isn't necessary, which might mean we can just remove the
Please feel free to submit a PR for making this work.
It's a great question. In theory these have a special meaning and if they appear as text they
It seems the formatting characters really have to be escaped along with Maybe you can conjure up more tests that break the assumption that
Submitting a PR will be preferable even as it allows to look at facts via tests from the start. Ideally GitHub would allow to turn issues into PRs easily when it's not your own repository. If this shows up for you, you might be able to convert this issue right away, otherwise, please feel free to submit a PR for it and start with PRs in the future. Whatever suits you best. |
I really appreciate the detailed explanation 🙏🏼. I'll continue to investigate and see what I can find, and I'll submit some PRs when I think they're ready for a review! |
Got bitten by the same issue, |
It is beneficial to preserve the original escapes (and not add more) if using as a formatter. I guess, by comparing the length of One idea would be at least to not escape |
Option to preserve special character escapes (for #51)
Summary
First, thanks for the project!
Currently, I'm trying to add support for formatting rust code blocks in markdown files to rustfmt (rust-lang/rustfmt#2036), and it's been nice to use
cmark_resume_with_options
to handle the markdown rendering. If you're curious you can check out my work on the proof of concept here.Ideally the feature I'm trying to add to rustfmt would only format the content of code blocks and leave the rest of the file as is (apart from some nice standardization of newlines between markdown items that
cmark_resume_with_options
provides 😁).My main concern is that linking to types like
[`Vec`]
when reformatted will turn into\[`Vec`\]
, and I'm not sure if that will prevent rustdoc from generating links when rustdoc renders the docs as HTML. The proof of concept linked above hacks around this (See theTypeLinkFormatter
if you're curious about the workaround.).I'm not sure if there are other scenarios where something the user typed would be escaped, but it would be great to have the option to turn off all escaping so that we can emit the same content the user originally wrote.
I'm not as versed in the world of generating markdown so please let me know if there are technical limitations that I don't fully understand.
Design
I think this could be implemented by adding another field to
Options
. Maybe call itescape_special_characters
and set it totrue
by default.Then we could make the following change to
escape_leading_special_characters
:Happy to open a PR for this!
The text was updated successfully, but these errors were encountered: