diff --git a/main.ts b/main.ts index 719a13f..b216a2e 100644 --- a/main.ts +++ b/main.ts @@ -626,7 +626,7 @@ export default class TextFormat extends Plugin { case "Chinese-punctuation": replacedText = selectedText; replacedText = replacedText - .replace(/ ?, ?/g, ",") + .replace(/(?:[\u4e00-\u9fa5])( ?, ?)(?:[\u4e00-\u9fa5])/g,(t, t1) => t.replace(t1, ",")) .replace(/(?:[^\d])( ?\. ?)/g, (t, t1) => t.replace(t1, "。")) .replace(/ ?、 ?/g, "、") .replace(/;/g, ";") @@ -642,7 +642,9 @@ export default class TextFormat extends Plugin { } break; case "English-punctuation": - replacedText = selectedText.replace(/[(\(]([\w !\"#$%&'()*+,-./:;<=>?@\[\\\]^_`{\|}~]+)[)\)]/g, "($1)"); + replacedText = selectedText + .replace(/[(\(]([\w !\"#$%&'()*+,-./:;<=>?@\[\\\]^_`{\|}~]+)[)\)]/g, "($1)") + .replace(/(?:[a-zA-Z])(, ?)(?:[a-zA-Z])/g, (t, t1) => t.replace(t1, ", ")); break; case "decodeURI": replacedText = selectedText.replace( diff --git a/src/langs/langs.ts b/src/langs/langs.ts index 95e9e90..0814970 100644 --- a/src/langs/langs.ts +++ b/src/langs/langs.ts @@ -4,8 +4,8 @@ const EN = { "lowercase": "Lowercase", "capitalize-word": "Capitalize all words", "capitalize-sentence": "Capitalize only first word of sentence", - "title-case": "Titlecase", - "cycle-case": "Cycle case", + "title-case": "Title-case", + "cycle-case": "Cycle-case", "slugify": "Slugify", "snakify": "Snakify", "remove-trailing-spaces": "Remove trailing spaces", @@ -62,15 +62,17 @@ const EN = { "bullet-point-characters-desc": "The characters that will be regarded as bullet points.", "ordered-list-custom-separator": "Format ordered list custom separator RegExp", "ordered-list-custom-separator-desc": "Separated by `|`. e.g.: `\sand\s|\s?AND\s?`. Default as empty.", - "wrapper": "Wrapper", - "wrapper-desc": "Wrap the selection with prefix and suffix", - "wrapper-rule-desc1": " ", - "wrapper-rule-desc2": "Template for metadata (file properties) is supported with Handlebars syntax. For example, `{{link}}` will be replaced with the value of current file's property `link`.", - "add-new-wrapper": "Add new wrapper", - "new-wrapper-rule-tooltip": "Add new rule", - "wrapper-name-placeholder": "Wrapper Name (command name)", - "wrapper-prefix-placeholder": "Prefix", - "wrapper-suffix-placeholder": "Suffix", + wrapper: { + "header": "Wrapper", + "desc": "Wrap the selection with prefix and suffix", + "rule-desc1": " ", + "rule-desc2": "Template for metadata (file properties) is supported with Handlebars syntax. For example, `{{link}}` will be replaced with the value of current file's property `link`.", + "add-new-wrapper": "Add new wrapper", + "new-wrapper-rule-tooltip": "Add new rule", + "name-placeholder": "Wrapper Name (command name)", + "prefix-placeholder": "Prefix", + "suffix-placeholder": "Suffix", + }, "delete-tooltip": "Delete", "api-request": "API Request", "api-request-desc": "Send a request to an API and replace the selection with the return", @@ -132,7 +134,7 @@ const ZH = { "more-details": "在 Github 查看更多详情:", "others": "其他设置", "remove-spaces-when-converting": "转换中文标点时去除空格", - "remove-spaces-when-converting-desc": "适用于OCR场景", + "remove-spaces-when-converting-desc": "适用于 OCR 场景", "debug-logging": "Debug 日志", "debug-logging-desc": "在控制台中显示 Debug 详细日志", "word-cases": "文字大小写转换", @@ -160,33 +162,35 @@ const ZH = { "Wikilink2mdPathMode-absolute": "绝对路径", "path-mode": "转换 Wikilink 为 Markdown 链接时的路径模式", "result-format": "移除选中链接格式的结果", - "result-format-desc": "与`[{text}]({url})`匹配,使用`{text}`维持文本或`{url}`维持链接。", + "result-format-desc": "与 `[{text}]({url})` 匹配,使用 `{text}` 维持文本或 `{url}` 维持链接。", "remove-wikilink-url": "移除 WikiLink 时也移除 URL", "wiki-link-format-heading": "带标题的 WikiLink 格式化", - "wiki-link-format-heading-desc": "例如:[[title#heading]]", - "wiki-link-format-alias": "带别名的WikiLink格式化", - "wiki-link-format-alias-desc": "例如:[[title|alias]]", - "wiki-link-format-both": "同时带标题和别名的WikiLink格式化", - "wiki-link-format-both-desc": "例如:[[title#heading|alias]]", + "wiki-link-format-heading-desc": "如:[[title#heading]]", + "wiki-link-format-alias": "带别名的 WikiLink 格式化", + "wiki-link-format-alias-desc": "如:[[title|alias]]", + "wiki-link-format-both": "同时带标题和别名的 WikiLink 格式化", + "wiki-link-format-both-desc": "如:[[title#heading|alias]]", "list-format": "列表格式化", "list-format-desc": "检测并转换无序列表和有序列表。", "bullet-point-characters": "项目符号字符", "bullet-point-characters-desc": "被视为项目符号的字符。", "ordered-list-custom-separator": "有序列表自定义分隔符正则表达式", "ordered-list-custom-separator-desc": "使用`|`分隔,例如:`\sand\s|\s?AND\s?`。默认为空。", - "wrapper": "包装器", - "wrapper-desc": "在选中的文本前后添加前缀和后缀。", - "wrapper-rule-desc1": "包装器名称、前缀模板、后缀模板", - "wrapper-rule-desc2": "支持使用Handlebars语法的文件元数据属性模板。例如,`{{link}}`将替换为当前文件的`link`属性值。", - "add-new-wrapper": "添加新的包装器", - "new-wrapper-rule-tooltip": "添加新规则", - "wrapper-name-placeholder": "包装器名称(命令名)", - "wrapper-prefix-placeholder": "前缀", - "wrapper-suffix-placeholder": "后缀", + wrapper: { + "header": "包装器", + "desc": "在选中的文本前后添加前缀和后缀。", + "rule-desc1": "包装器名称、前缀模板、后缀模板", + "rule-desc2": "支持使用 Handlebars 语法的文件元数据属性模板。例如,`{{link}}` 将替换为当前文件的 `link` 属性值。", + "add-new-wrapper": "添加新的包装器", + "new-wrapper-rule-tooltip": "添加新规则", + "name-placeholder": "包装器名称(命令名)", + "prefix-placeholder": "前缀", + "suffix-placeholder": "后缀", + }, "delete-tooltip": "删除", - "api-request": "API请求", - "api-request-desc": "向API发送请求,并用返回值替换选择文本", - "api-request-url": "API请求URL", + "api-request": "API 请求", + "api-request-desc": "向 API 发送请求,并用返回值替换选择文本", + "api-request-url": "API 请求 URL", "api-request-url-desc": "插件将发送POST请求并用返回值替换选择文本。\n" + "返回的JSON应包含两个属性:`text` 和 `notification`。\n" + @@ -194,7 +198,7 @@ const ZH = { "如果存在 `notification`,则发送此字符串作为通知,否则不做任何操作。", "new-request-tooltip": "添加新请求", "request-name-placeholder": "请求名称(命令名称)", - "request-url-placeholder": "请求URL", + "request-url-placeholder": "请求 URL", "custom-replacement": "自定义替换", "custom-replacement-desc": "使用自定义字符串替换特定模式", "add-custom-replacement": "添加自定义替换", diff --git a/src/settings/settingTab.ts b/src/settings/settingTab.ts index db8f547..a29b963 100644 --- a/src/settings/settingTab.ts +++ b/src/settings/settingTab.ts @@ -320,23 +320,23 @@ export class TextFormatSettingTab extends PluginSettingTab { } addSettingsAboutWrapper(containerEl: HTMLElement) { let headerDiv = containerEl.createDiv({ cls: "header-div" }); - let headerEl = headerDiv.createEl("h3", { text: getString(["setting", "wrapper"]) }); - headerDiv.createEl("div", { text: getString(["setting", "wrapper-desc"]), cls: "setting-item-description heading-description" }); + let headerEl = headerDiv.createEl("h3", { text: getString(["setting", "wrapper", "header"]) }); + headerDiv.createEl("div", { text: getString(["setting", "wrapper", "desc"]), cls: "setting-item-description heading-description" }); this.contentEl = containerEl.createDiv(); this.makeCollapsible(headerEl, this.contentEl); const wrapperRuleDesc = document.createDocumentFragment(); wrapperRuleDesc.append( - getString(["setting", "wrapper-rule-desc1"]), + getString(["setting", "wrapper", "rule-desc1"]), document.createDocumentFragment().createEl("br"), - getString(["setting", "wrapper-rule-desc2"]) + getString(["setting","wrapper", "rule-desc2"]) ); new Setting(this.contentEl) - .setName(getString(["setting", "add-new-wrapper"])) + .setName(getString(["setting", "wrapper", "add-new-wrapper"])) .setDesc(wrapperRuleDesc) .addButton((button: ButtonComponent) => { button - .setTooltip(getString(["setting", "new-wrapper-rule-tooltip"])) + .setTooltip(getString(["setting","wrapper", "new-wrapper-rule-tooltip"])) .setButtonText("+") .setCta() .onClick(async () => { @@ -353,7 +353,7 @@ export class TextFormatSettingTab extends PluginSettingTab { this.plugin.settings.WrapperList.forEach((wrapperSetting, index) => { const s = new Setting(this.contentEl) .addText((cb) => { - cb.setPlaceholder(getString(["setting", "wrapper-name-placeholder"])) + cb.setPlaceholder(getString(["setting", "wrapper", "name-placeholder"])) .setValue(wrapperSetting.name) .onChange(async (newValue) => { this.plugin.settings.WrapperList[index].name = newValue; @@ -362,7 +362,7 @@ export class TextFormatSettingTab extends PluginSettingTab { }); }) .addText((cb) => { - cb.setPlaceholder(getString(["setting", "wrapper-prefix-placeholder"])) + cb.setPlaceholder(getString(["setting","wrapper", "prefix-placeholder"])) .setValue(wrapperSetting.prefix) .onChange(async (newValue) => { this.plugin.settings.WrapperList[index].prefix = newValue; @@ -371,7 +371,7 @@ export class TextFormatSettingTab extends PluginSettingTab { }); }) .addText((cb) => { - cb.setPlaceholder(getString(["setting", "wrapper-suffix-placeholder"])) + cb.setPlaceholder(getString(["setting","wrapper", "suffix-placeholder"])) .setValue(wrapperSetting.suffix) .onChange(async (newValue) => { this.plugin.settings.WrapperList[index].suffix = newValue; diff --git a/src/settings/types.ts b/src/settings/types.ts index 844325d..43dbb77 100644 --- a/src/settings/types.ts +++ b/src/settings/types.ts @@ -74,6 +74,10 @@ export interface FormatSettings { debugMode: boolean; headingLevelMin: number; calloutTypeDecider: CalloutTypeDecider; + formatOnSaveSettings: { + enabled: boolean; + commandsString: string; + } } export const DEFAULT_SETTINGS: FormatSettings = { @@ -102,4 +106,8 @@ export const DEFAULT_SETTINGS: FormatSettings = { debugMode: false, headingLevelMin: 0, calloutTypeDecider: CalloutTypeDecider.preContent, + formatOnSaveSettings: { + enabled: false, + commandsString: "", + } }; \ No newline at end of file diff --git a/styles.css b/styles.css index fb2018a..0531e76 100644 --- a/styles.css +++ b/styles.css @@ -3,6 +3,9 @@ margin-bottom: 0px; padding-bottom: 0px; } +.plugin-text-format H4{ + opacity: 0.7; +} .plugin-text-format .heading-description { padding-top: 0px; color: var(--text-faint);