I am trying to make a snippet that will take clipboard contents (the text of a heading in a markdown
document) and transform it into a link to that section. For example, if my clipboard contains: Some Heading - 20191107
then I want the following to be output:
[Some Heading - 20191107](filename.md#some-heading---20191107)
Here is my snippet VS Code
for markdown
so far:
"link to this section": {
"prefix": "isection",
"body": [
"[${1:${CLIPBOARD}}](${TM_FILENAME}#${CLIPBOARD/ /-/g})"
],
"description": "Insert link to section whose heading text is in the clipboard"
}
This has the first transform, but what I cannot figure out is how to nest multiple transforms:
- Replace all space with a hyphen.
- Change all to lower case.
- Remove any characters matching
[^a-z0-9-]
Test Case
To clarify my test case for @Mark, in a markdown
document in VS Code
, I make a section heading such as:
# 20191107 - @#$%^& This is a section - 20191107
I then copy the text 20191107 - @#$%^& This is a section - 20191107
and run the snippet you fixed up for me. What it outputs is:
[20191107 - @#$%^& This is a section - 20191107](tips.tech.git.md#20191107----this-is-a-section---20191107)
Which is a valid link to the heading!