-
Notifications
You must be signed in to change notification settings - Fork 10
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
A way to avoid interpolating escaped $s (e.g htl" \$NOinterp "
) to match Julia interpolation
#30
base: master
Are you sure you want to change the base?
Conversation
Jack,
Thanks for this suggestion. I struggled a lot with this issue and opted to not implement what you have suggested at that time:
1. Julia a string literals already have their own escape peculiarities and I wasn't sure if I could implement something that would deal with all of the edge cases.
2. The lack of '\' as an escape character may be advantageous, for example, usage within a path.
3. Escaping '$' but not other characters seems a bit strange to me. What should '\\$' mean, for example. In early releases I escaped everything. Alas, this hit a few unsettling edge cases with non-standard string literal's escaping.
4. In the end, I think I settled with "SQL" style escaping, e.g. double up the '$' to escape. This seemed the least-worst option.
I'm not opposed to what you suggest in lieu of doubling up '$'. I think edge cases may need some work (have not looked at PR code yet). Importantly, what exactly is the use case where this particular compromise would be advantageous?
Cheers,
Clark
…On Wed, Jun 22, 2022, at 9:06 PM, Jack Snoeyink wrote:
Julia does not interpolate escaped $ in strings, so ***@***.***(" \$NOinterp ")` and `htl" \$NOinterp "` have different behavior.
By replacing findnext('$' with a regexp for the next $ that is not preceded by an odd number of , I think brings `htl" "` get closer to the expected Julia string interpolation behavior.
Existing behavior
Note the extra interpolations for the 3rd and 4th.
julia> using HypertextLiteral
julia> NOinterp = "YES_I'm interpolated! ";
julia> @htl("$(NOinterp) $NOinterp \$(NOinterp) \$NOinterp \\$(NOinterp) \\NOinterp")
YES_I'm interpolated! YES_I'm interpolated! $(NOinterp) $NOinterp \YES_I'm interpolated! \NOinterp
julia> htl"$(NOinterp) $NOinterp \$(NOinterp) \$NOinterp \\$(NOinterp) \\NOinterp"
YES_I'm interpolated! YES_I'm interpolated! \YES_I'm interpolated! \YES_I'm interpolated! \\YES_I'm interpolated! \\NOinterp
New behavior
Note that the escaped dollar signs still show the raw $ -- this is the expected difference from the cooked string from @htl <https://github.com/htl>.
julia> htl"$(NOinterp) $NOinterp \$(NOinterp) \$NOinterp \\$(NOinterp) \NOinterp"
YES_I'm interpolated! YES_I'm interpolated! \$(NOinterp) \$NOinterp \\YES_I'm interpolated! \NOinterp
You can view, comment on, or merge this pull request online at:
#30
Commit Summary
* 0a00742 <0a00742> debugging test fucn fh for escaping $ for htl_str.
* 7621db1 <7621db1> Interpolate only unescaped $ by findnext regexp.
* b81e47c <b81e47c> htl_str interpolate only unesc $ : rm debug code
File Changes
(1 file <https://github.com/JuliaPluto/HypertextLiteral.jl/pull/30/files>)
* *M* src/macro.jl <https://github.com/JuliaPluto/HypertextLiteral.jl/pull/30/files#diff-5e84de38fb08a2615207f16bf896e93ccb8c58bbfa50e6420fc8d54d88daca84> (8)
Patch Links:
* https://github.com/JuliaPluto/HypertextLiteral.jl/pull/30.patch
* https://github.com/JuliaPluto/HypertextLiteral.jl/pull/30.diff
—
Reply to this email directly, view it on GitHub <#30>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAQ7IUWMVVF65ENAEMSKDLVQPBEBANCNFSM5ZSTHIZQ>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
SummaryThe scenario is MarkdownLiteral.jl:
Responses to your points
DetailsI've used I'm converting slides & textbook for my Discrete Mathematic course to Julia CommonMark, and want to be able to switch
So, your options:
Examples
|
Jack,
Your proposal sounds very well thought out. It's good with me. There are few string literal users, so, I think there is little community impact. So, let's merge the pull request then and release?
Did you want to keep $$ as escape (is it even still implemented). I like it because it is an error in the regular macro context so there is no confusion.
Clark
|
That would be great. I'm fine with the |
Julia does not interpolate escaped $ in strings, so
@htl(" \$NOinterp ")
andhtl" \$NOinterp "
have different behavior.Replacing findnext('$' with a regexp for the next $ that is not preceded by an odd number of \, I think brings
htl" "
closer to the expected Julia string interpolation behavior.Existing behavior
Note the extra interpolations for the 3rd and 4th.
New behavior
Note that the escaped dollar signs still show the raw \$ -- this is the expected difference to the cooked string from @htl.