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

Add option to escape_string to avoid already escaped characters #34042

Closed
ronisbr opened this issue Dec 7, 2019 · 3 comments · Fixed by #38597
Closed

Add option to escape_string to avoid already escaped characters #34042

ronisbr opened this issue Dec 7, 2019 · 3 comments · Fixed by #38597
Labels
good first issue Indicates a good issue for first-time contributors to Julia

Comments

@ronisbr
Copy link
Member

ronisbr commented Dec 7, 2019

Hi!

In PrettyTables.jl, sometimes it happens that a string has already some characters escaped, like \\cdot, but others not, like \n. However, I need to call escape_string every time to handle the other non-escaped characters (like \n), otherwise the output will break badly.

For example, if I try to pass to PrettyTables.jl a cell that has a LaTeX equation:

data = [ "\$ 10 \\cdot 20$" ]

then it will print:

$ 10 \\cdot 20 $"

because escape_string always treat \\ as two backslashes instead of one escaped backslash.

To solve this problem, I needed to copy the entire escape_string function and remove the line that transform \\ into \\\\. It would be nice, IMHO, if Julia's escape_string has a keyword option to assume \\ as an already escaped backslash.

If this is accepted, I can submit a PR.

@JeffBezanson JeffBezanson added the good first issue Indicates a good issue for first-time contributors to Julia label Feb 29, 2020
@rohanxyzg
Copy link

Hi,
I would like to work on this issue.
Thanks

@ronisbr
Copy link
Member Author

ronisbr commented Nov 25, 2020

Hi @rohanxyzg !

I was about to submit a PR addressing this issue :)

I did not do this earlier because I was working on preparing PrettyTables.jl to be used in DataFrames.jl and I thought I would not need this anymore. I was wrong.

@ronisbr
Copy link
Member Author

ronisbr commented Nov 28, 2020

Done!

Keno pushed a commit that referenced this issue Dec 25, 2020
* Arg. to avoid escaping backslahes (escape_string)

This commit adds an argument to `escape_string` to assume that all
backslashes (`\\`) are already escaped. Hence, `\\cdot` becomes `\\cdot`
instead of `\\\\cdot`.

The default value to this argument is `false`. Hence, this does not
break any existing code since `escape_string` behaves exactly the same
as before if no additional option is passed.

Closes #34042

* Replace `bsescaped` arg. with `keep` keyword

* Update NEWS.md

* Fix doc tests

* Add compat annotation

Co-authored-by: Ronan Arraes Jardim Chagas <ronan.arraes@MacBook-Pro-de-Ronan.local>
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this issue May 4, 2021
* Arg. to avoid escaping backslahes (escape_string)

This commit adds an argument to `escape_string` to assume that all
backslashes (`\\`) are already escaped. Hence, `\\cdot` becomes `\\cdot`
instead of `\\\\cdot`.

The default value to this argument is `false`. Hence, this does not
break any existing code since `escape_string` behaves exactly the same
as before if no additional option is passed.

Closes JuliaLang#34042

* Replace `bsescaped` arg. with `keep` keyword

* Update NEWS.md

* Fix doc tests

* Add compat annotation

Co-authored-by: Ronan Arraes Jardim Chagas <ronan.arraes@MacBook-Pro-de-Ronan.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants