Escaped backslashes (2 consecutive backslashes) not appearing correctly in HTML output
sambody opened this issue · comments
Hello. I noticed that when I create a new snippet, a dollar $ sign (or a variable starting with dollar) is removed, not preserved. Could you make so that a variable starting with dollar is preserved, and the dollar sign is escaped?
Example: right now, when I want to create a snippet out of this line:
$statement = ->pdo->prepare($sql);
I get this (notice that I loose the variables):
"= ->pdo->prepare();",
Instead, I would like it to automatically look like this:
"\\$statement = ->pdo->prepare(\\$sql);",
thank you.
Hi,
This is a bug.
Let me clarify the expectation of the extension so that we are on the same page. This extension should show the contents of the body
of a snippet verbatim.
For example, if I want an interpolated string snippet in JavaScript. I would write a snippet like this to get my desired result:
"interpolated string":{
"prefix": "interpolated string",
"body": ["let string = `\\${var} is in a string`;"],
"description": "Set variable to interpolated string"
}
It is my responsibility to escape the dollar sign in the body
to have it treated as a string rather than as a snippet variable.
Using this snippet in a JavaScript file will result in the following output:
Currently Snippet Ranger reports the snippet as this:
It shows 1 backslash instead of 2. This is the bug.
This issue is fixed in version 0.22.2.
If you are happy with the extension: please star the repo, and leave a favourable review to help others find it. 🌟
The bug is not fixed.
I updated to version 0.22.2 just now and restarted the app. And the bug is still there.
I was referring to the process of creating a new snippet out of a selection, not the process of showing an existing snippet.
When trying out with your example
let string = `${var} is in a string`;
then doing the command Snippet Ranger - Make new snippet, I still get the following code in the snippets file, where as you can see, the variable (and the dollar) is missing:
"enter a name" : {
"prefix": "",
"body": ["let string = ` is in a string`;"],
"description": ""
},
When the result should include the dollar, and have it escaped:
let string = `\${var} is in a string`;
Can you look into this? Thank you.
I was referring to the process of creating a new snippet out of a selection, not the process of showing an existing snippet.
Please raise a separate issue. The bug is fixed. It is a different issue than your original description. Provide the exact steps you took in the issue please.
Thanks
OK, I'll file a separate issue. Thanks.