Skip to content

Commit

Permalink
basic support #80
Browse files Browse the repository at this point in the history
  • Loading branch information
Benature committed Mar 6, 2024
1 parent 8bf3125 commit e485a70
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
push:
@git tag "$(tag)"
@git push origin "$(tag)"

del:
@git tag -d "$(tag)"
@git push origin --delete "$(tag)"
27 changes: 26 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ export default class TextFormat extends Plugin {
this.textFormat(editor, view, "array2table");
},
});
this.addCommand({
id: "callout",
name: { en: "Callout format", zh: "Callout 格式", "zh-TW": "Callout 格式" }[lang],
editorCallback: (editor: Editor, view: MarkdownView) => {
this.textFormat(editor, view, "callout");
},
});


this.debounceUpdateCommandWrapper();
Expand Down Expand Up @@ -647,7 +654,25 @@ export default class TextFormat extends Plugin {
return;
})
return;

case "callout":
const wholeContent = editor.getValue();
let type = this.settings.calloutType;
if (type.startsWith("!")) {
type = type.substring(1, type.length);
} else {
const preCallouts = wholeContent.match(/(?<=\n\>\s*\[\!)\w+(?=\])/gm);
if (preCallouts) {
type = preCallouts[preCallouts.length - 1];
}
}
const lines = selectedText.replace(/$\n>/g, "").split("\n");
replacedText = `> [!${type}] ${lines[0]}`
if (lines.length > 1) {
for (let idx = 1; idx < lines.length; idx++) {
replacedText += `\n> ` + lines[idx];
}
}
break;
default:
return;
}
Expand Down
29 changes: 23 additions & 6 deletions src/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface FormatSettings {
ProperNoun: string;
OrderedListOtherSeparator: string;
isWikiLink2mdRelativePath: boolean;
calloutType: string;
}

export const DEFAULT_SETTINGS: FormatSettings = {
Expand All @@ -62,6 +63,7 @@ export const DEFAULT_SETTINGS: FormatSettings = {
ProperNoun: "",
OrderedListOtherSeparator: String.raw``,
isWikiLink2mdRelativePath: true,
calloutType: "NOTE",
};

export class TextFormatSettingTab extends PluginSettingTab {
Expand All @@ -83,8 +85,23 @@ export class TextFormatSettingTab extends PluginSettingTab {
href: "https://github.com/Benature/obsidian-text-format",
});

containerEl.createEl("h3", { text: "Words lower/title/toggle/capitalize case" });
new Setting(containerEl)
.setName("Callout type")
.setDesc(["Set the callout type for command `Callout format`. ",
"New callout block will use the last callout type in the current file by default. ",
"To disable this continuity, make the type begins with `!`, e.g. `!NOTE`."].join(""))
.addText((text) =>
text
.setPlaceholder("Callout type")
.setValue(this.plugin.settings.calloutType)
.onChange(async (value) => {
this.plugin.settings.calloutType = value;
await this.plugin.saveSettings();
})
);


containerEl.createEl("h3", { text: "Words lower/title/toggle/capitalize case" });
new Setting(containerEl)
.setName("Lowercase before capitalize/title case")
.setDesc(
Expand Down Expand Up @@ -284,7 +301,7 @@ export class TextFormatSettingTab extends PluginSettingTab {
});
this.plugin.settings.WrapperList.forEach((wrapperSetting, index) => {
const s = new Setting(this.containerEl)
.addSearch((cb) => {
.addText((cb) => {
cb.setPlaceholder("Wrapper Name (command name)")
.setValue(wrapperSetting.name)
.onChange(async (newValue) => {
Expand All @@ -293,7 +310,7 @@ export class TextFormatSettingTab extends PluginSettingTab {
this.plugin.debounceUpdateCommandWrapper();
});
})
.addSearch((cb) => {
.addText((cb) => {
cb.setPlaceholder("Prefix")
.setValue(wrapperSetting.prefix)
.onChange(async (newValue) => {
Expand All @@ -302,7 +319,7 @@ export class TextFormatSettingTab extends PluginSettingTab {
this.plugin.debounceUpdateCommandWrapper();
});
})
.addSearch((cb) => {
.addText((cb) => {
cb.setPlaceholder("Suffix")
.setValue(wrapperSetting.suffix)
.onChange(async (newValue) => {
Expand Down Expand Up @@ -346,7 +363,7 @@ export class TextFormatSettingTab extends PluginSettingTab {
})
this.plugin.settings.RequestList.forEach((requestSetting, index) => {
const s = new Setting(this.containerEl)
.addSearch((cb) => {
.addText((cb) => {
cb.setPlaceholder("Request Name (command name)")
.setValue(requestSetting.name)
.onChange(async (newValue) => {
Expand All @@ -355,7 +372,7 @@ export class TextFormatSettingTab extends PluginSettingTab {
this.plugin.debounceUpdateCommandRequest();
});
})
.addSearch((cb) => {
.addText((cb) => {
cb.setPlaceholder("Request URL")
.setValue(requestSetting.url)
.onChange(async (newValue) => {
Expand Down

0 comments on commit e485a70

Please sign in to comment.