I modified my earlier answer to favour the app Scriptable (used in conjunction with Shortcuts; run it as Inline Script), where is no need to use semi-colons on line ends and we can use return(newStr)
on the last line. In the following step in Shortcuts, set the Output to a variable, which we can do whatever we want with.
Javascript code
const str = "<Provided Input>"
const regex = /(.*?#)(.*)/
const newStr = str.replace(regex, "[[$1$2]]\t\t$1$2\t$2")
return(newStr)
- I put Provided Input to show it can be a text you manually input to try out the code. If it works (it does, for me), you can embed the code into your shortcut. If you target text selection, you'll need Shortcut Input, or a variable with that value.
- Should you want extra aliases, combine the Shortcut Input with Provided Input (ask for input), and just add those with
\tExtraAlias1\tExtraAlias2
.
Thread found here:
https://forum.obsidian.md/t/aliases-for-headings-with-the-various-complements-plugin/58733
Another, more elaborate way with lowercase versions included:
// Input-string
let inputString = "Shortcut Input";
// Regex pattern
let pattern = /(.*?#)(.*?)(?:\||$)/;
// Replace function
let replaceFunction = (match, p1, p2) => {
let lowercaseP1 = p1.toLowerCase();
let lowercaseP2 = p2.toLowerCase();
return `[[${p1}${p2}]]\t\t${p1}${p2}\t${p2}\n[[${p1}${p2}|${lowercaseP2}]]\t\t${lowercaseP1}${lowercaseP2}\t${lowercaseP2}`;
}
// Replace using regular expression and function
let exchangeString = inputString.replace(pattern, replaceFunction);
//Add Customaliases
const str = exchangeString;
const regex = /(.*)/;
const newStr = str.replace(regex, "$1\tExtraAlias1\tExtraAlias2")
return(newStr)
Output of my example
"[[Greek#Pre-Greek Pre-Indo-European Languages]] Greek#Pre-Greek Pre-Indo-European Languages Pre-Greek Pre-Indo-European Languages"
- Mind you, in my editor, the tabs are correctly shown, but once my answer is rendered out in HTML on this site, they are substituted by single whitespace characters.