diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..66b876e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,7 @@
+push:
+ @git tag "$(tag)"
+ @git push origin "$(tag)"
+
+del:
+ @git tag -d "$(tag)"
+ @git push origin --delete "$(tag)"
diff --git a/main.ts b/main.ts
index 8a93027..5760c8d 100644
--- a/main.ts
+++ b/main.ts
@@ -1,47 +1,12 @@
-import { MarkdownView, Plugin, EditorPosition } from "obsidian";
-
-// Call this method inside your plugin's
-// `onload` function like so:
-// monkeyPatchConsole(this);
-// const monkeyPatchConsole = (plugin: Plugin) => {
-// // if (!Platform.isMobile) {
-// // return;
-// // }
-
-// const logFile = `${plugin.manifest.dir}/logs.txt`;
-// console.log(logFile);
-// const logs: string[] = [];
-// const logMessages = (prefix: string) => (...messages: unknown[]) => {
-// logs.push(`\n[${prefix}]`);
-// for (const message of messages) {
-// logs.push(String(message));
-// }
-// plugin.app.vault.adapter.write(logFile, logs.join(" "));
-// };
-
-// console.debug = logMessages("debug");
-// console.error = logMessages("error");
-// console.info = logMessages("info");
-// console.log = logMessages("log");
-// console.warn = logMessages("warn");
-// };
+import { Editor, MarkdownView, Plugin, EditorPosition } from "obsidian";
export default class Underline extends Plugin {
async onload() {
- // console.log(this.app);
-
- // this.app.workspace.on('layout-change', () => {
- // this.updateUnderline();
- // })
- // this.app.metadataCache.on('changed', (_file) => {
- // this.updateUnderline();
- // })
- // monkeyPatchConsole(this);
-
this.addCommand({
id: "toggle-underline-tag",
name: "Toggle underline tag",
- callback: () => this.urlIntoSelection(),
+ editorCallback: (editor: Editor, view: MarkdownView) =>
+ this.wrapper(editor, view),
hotkeys: [
{
modifiers: ["Mod"],
@@ -53,48 +18,51 @@ export default class Underline extends Plugin {
this.addCommand({
id: "toggle-center-tag",
name: "Toggle center tag",
- callback: () => this.urlIntoSelection("
", ""),
- hotkeys: [
- {
- modifiers: ["Mod", "Shift"],
- key: "c",
- },
- ],
+ editorCallback: (editor: Editor, view: MarkdownView) =>
+ this.wrapper(editor, view, "", ""),
+ // hotkeys: [
+ // {
+ // modifiers: ["Mod", "Shift"],
+ // key: "c",
+ // },
+ // ],
});
this.addCommand({
id: "toggle-link-heading",
name: "Toggle a link to heading in the same file",
- callback: () => this.urlIntoSelection("[[#", "]]"),
- hotkeys: [
- {
- modifiers: ["Mod"],
- key: "3",
- },
- ],
+ editorCallback: (editor: Editor, view: MarkdownView) =>
+ this.wrapper(editor, view, "[[#", "]]"),
+ // hotkeys: [
+ // {
+ // modifiers: ["Mod"],
+ // key: "3",
+ // },
+ // ],
});
this.addCommand({
id: "toggle-link-block",
name: "Toggle a link to block in the same file",
- callback: () => this.urlIntoSelection("[[#^", "]]"),
- hotkeys: [
- {
- modifiers: ["Mod"],
- key: "6",
- },
- ],
+ editorCallback: (editor: Editor, view: MarkdownView) =>
+ this.wrapper(editor, view, "[[#^", "]]"),
+ // hotkeys: [
+ // {
+ // modifiers: ["Mod"],
+ // key: "6",
+ // },
+ // ],
});
}
- urlIntoSelection(prefix: string = "", suffix: string = ""): void {
+ wrapper(editor: Editor, view: MarkdownView, prefix: string = "", suffix: string = ""): void {
const PL = prefix.length; // Prefix Length
const SL = suffix.length; // Suffix Length
- let markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
- if (!markdownView) {
- return;
- }
- let editor = markdownView.editor;
+ // let markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
+ // if (!markdownView) {
+ // return;
+ // }
+ // let editor = markdownView.editor;
let selectedText = editor.somethingSelected() ? editor.getSelection() : "";
diff --git a/manifest.json b/manifest.json
index 92ca39f..aad0bdf 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"id": "obsidian-underline",
"name": "Underline",
- "version": "1.2.2",
+ "version": "1.3.0",
"description": "Add underline(`xxx`) with shortcut, and `xxx`, `[[#xxx]]`, `[[#^xxx]]`",
"author": "Benature",
"authorUrl": "https://github.com/Benature",
diff --git a/package.json b/package.json
index f252b96..6314d58 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,7 @@
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/node": "^14.14.2",
- "obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master",
+ "obsidian": "^0.15.9",
"prettier": "2.1.2",
"rollup": "^2.32.1",
"standard-version": "^9.0.0",