Skip to content

Commit

Permalink
support #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Benature committed Mar 18, 2024
1 parent b9d32b6 commit 31ea232
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 67 deletions.
7 changes: 7 additions & 0 deletions Makefile
@@ -0,0 +1,7 @@
push:
@git tag "$(tag)"
@git push origin "$(tag)"

del:
@git tag -d "$(tag)"
@git push origin --delete "$(tag)"
98 changes: 33 additions & 65 deletions 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"],
Expand All @@ -53,48 +18,51 @@ export default class Underline extends Plugin {
this.addCommand({
id: "toggle-center-tag",
name: "Toggle center tag",
callback: () => this.urlIntoSelection("<center>", "</center>"),
hotkeys: [
{
modifiers: ["Mod", "Shift"],
key: "c",
},
],
editorCallback: (editor: Editor, view: MarkdownView) =>
this.wrapper(editor, view, "<center>", "</center>"),
// 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 = "<u>", suffix: string = "</u>"): void {
wrapper(editor: Editor, view: MarkdownView, prefix: string = "<u>", suffix: string = "</u>"): 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() : "";

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
@@ -1,7 +1,7 @@
{
"id": "obsidian-underline",
"name": "Underline",
"version": "1.2.2",
"version": "1.3.0",
"description": "Add underline(`<u>xxx</u>`) with shortcut, and `<center>xxx</center>`, `[[#xxx]]`, `[[#^xxx]]`",
"author": "Benature",
"authorUrl": "https://github.com/Benature",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down

0 comments on commit 31ea232

Please sign in to comment.