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

prost-build: do not escape brackets followed by parenthesis in comments #851

Merged
merged 6 commits into from
Aug 28, 2023

Conversation

pgimalac
Copy link
Contributor

@pgimalac pgimalac commented Apr 23, 2023

A proposal to fix #850.

Allows linking to items in doc comments by not escaping brackets followed by parenthesis.

  • Before (brackets always escaped):
    // Some comment with a [Link] -> /// Some comment with a \[Link\]
    // Some comment with a [Link](Link) -> /// Some comment with a \[Link\](Link)
  • After (brackets not escaped if followed by parenthesis):
    // Some comment with a [Link] -> /// Some comment with a \[Link\]
    // Some comment with a [Link](Link) -> /// Some comment with a [Link](Link)

EDIT: I also implemented the case with brackets following brackets [Link][Link] since it appears in some of the tests.
EDIT: I also implemented not escaping brackets which are already escaped, it happens when using the cleanup-markdown feature, or if the user manually escapes brackets.

@pgimalac pgimalac force-pushed the pgimalac/fix-bracket-comments branch from e3aafa8 to 621f4ed Compare April 23, 2023 20:24
@pgimalac
Copy link
Contributor Author

pgimalac commented Apr 23, 2023

I'm seeing some weird behaviors on the bootstrap test, it looks like the input is escaped twice sometimes (there are times where the brackets in the input of sanitize_line is already escaped)... I'll look into it when I have more time.

@pgimalac
Copy link
Contributor Author

Some lines are escaped both by ast::get_lines (which reads some file using pulldown_cmark_to_cmark) and then by sanitize_input, resulting in the double escaping I mentioned before.

Note that it's already the case, for example here where the regex only matched the outer brackets.

It seems like the cleanup-markdown feature (which is enabled for the tests) already escapes brackets.

I'll update the regex to avoid double escaping, since anyway if the user escapes the brackets then we don't want to do it again.

@pgimalac
Copy link
Contributor Author

The diff of prost-types/src/protobuf.rs is really nice:

  • removes double escaping (eg. line 1259)
  • escapes brackets which weren't escaped before (eg. line 1987)
  • do not escape brackets which are a link (eg. line 2288)

@pgimalac pgimalac force-pushed the pgimalac/fix-bracket-comments branch from 51db66c to 0c49d54 Compare April 26, 2023 10:17
@baxterjo
Copy link

baxterjo commented Aug 7, 2023

Hoping to bump this thread. Would be nice to have intra-doc linking in rustdocs.

@LucioFranco
Copy link
Member

@pgimalac if you want to get the conflicts resolved we can get this merged.

@pgimalac
Copy link
Contributor Author

pgimalac commented Aug 26, 2023

@LucioFranco I fixed the conflicts but there is a build error (unrelated to this PR) in the CI
EDIT: opened #899 to fix that.

@LucioFranco LucioFranco merged commit 1d74058 into tokio-rs:master Aug 28, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linking to items in doc comment is not possible because brackets are always escaped
3 participants