feat: support escape slash in wikilinks
Ref: https://github.com/artempyanykh/marksman/issues/288
The pipe operator used in WikiLinks can now be escaped with a backwards slash \.
Thanks for submitting this PR! I'll have a look shortly.
Hi sorry for the fails, I should have ran the tests locally but I am not familiar with this particular stack. I managed to set up dotnet on my macbook and I'm now taking a look at the tests.
The problem with the runs above is that the slash | was being encoded before \\|, so swapping the order of those two fixed that issue.
There is another problem, on Tests/MiscTests.fs:100 there is an expect that decoded actual and compares it to original. With the current implementation, this will not work because the escape slashes are lost during the encoding process, and during decoding on line 100 there is no way to know whether the escaped or non-escaped version of | should be used.
So my thinking is, we can maybe remove that expect on line 100 because line 99 is the actual test, and it looks to me like line 100 is just an extra precaution. While I think such an extra precaution is nice, it makes this change a bit harder. On the other hand, I am unfamiliar with the codebase so my thinking could be a bit shortsighted here so I would value your opinion on the matter. Thanks.
Hi @pprotas! If I understood correctly #288, you wanted | to be escaped \| rather than url-encoded. With you current change, auto-completion would still produce a string with url-encoded pipe, which defeats the purpose.
EncodeForWiki probably needs to look like this:
member this.EncodeForWiki() : string =
- let replacement = [| "#", "%23"; "[", "%5B"; "]", "%5D"; "|", "%7C" |]
+ let replacement = [| "#", "%23"; "[", "%5B"; "]", "%5D"; "|", "\\|" |]
And, you'd also need to implement DecodeFromWiki to do the reverse, rather than piggy-backing on UrlDecode.
In terms of tests, I expect encoding to be lossless, iow decode(encode(original) should be equal to original. It can stay this way if you modify DecodeFromWiki appropriately.