Skip to content

Commit

Permalink
Adds embed toggle for all internal links on a line (#3)
Browse files Browse the repository at this point in the history
* Adds embed toggle for all internal links on a line
* Default hotkey is `Ctrl`/`Cmd` + `Shift` + `1`.

Closes #2
  • Loading branch information
lynchjames authored Oct 28, 2020
1 parent 441a6ae commit f48de61
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ export default class HotkeysPlus extends Plugin {
},
],
});

this.addCommand({
id: "toggle-embed",
name: "Toggle line to embed internal links",
callback: () => this.toggleEmbed(),
hotkeys: [
{
modifiers: ["Mod", "Shift"],
key: "1",
},
],
});
}

onunload() {
Expand Down Expand Up @@ -122,6 +134,11 @@ export default class HotkeysPlus extends Plugin {
return this.toggleElement(re, this.replaceBlockQuote);
}

toggleEmbed() {
var re = /\S*\[\[/gim;
return this.toggleElement(re, this.replaceEmbed);
}

replaceListElement(startText: string) {
if (startText === "- ") {
return "1. ";
Expand All @@ -144,6 +161,18 @@ export default class HotkeysPlus extends Plugin {
}
}

replaceEmbed(startText: string) {
if (startText === "![[") {
return "[[";
}
else if (startText === "[[") {
return "![[";
}
else {
return "";
}
}

replaceTodoElement(startText: string) {
if (startText === "- [ ] ") {
return "- [x] ";
Expand Down

0 comments on commit f48de61

Please sign in to comment.