From 6b317b7b48588d30fd1e6307c51bea14d031cda1 Mon Sep 17 00:00:00 2001 From: Moy Date: Mon, 19 May 2025 13:36:53 +0800 Subject: [PATCH] feat: add option to generate embeded block --- src/i18n.ts | 7 +++++++ src/main.ts | 8 ++++++-- src/settingTab.ts | 11 +++++++++++ src/type.ts | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/i18n.ts b/src/i18n.ts index 810b63c..8749480 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -25,6 +25,7 @@ export type TranslationKey = | 'enable-wikilink' | 'enable-wikilink-desc' | 'keep-wiki-brackets' | 'keep-wiki-brackets-desc' | 'special-format' + | 'auto-embed-block-link' | 'auto-embed-block-link-desc' | 'auto-add-block-id' | 'auto-add-block-id-desc' | 'manual-block-id' | 'manual-block-id-desc' | 'modal-block-id' | 'modal-block-id-desc' @@ -93,6 +94,8 @@ export const translations: Record> = { 'enable-wikilink-desc': 'Enable copying of [[Wiki]] links', 'special-format': 'Special copy format options', + 'auto-embed-block-link': 'Block link: Add ! for embed', + 'auto-embed-block-link-desc': 'When copying block links, automatically add ! to embed the block', 'keep-wiki-brackets': 'Wikilink: Keep [[ ]] brackets', 'keep-wiki-brackets-desc': 'When copying wiki links, keep the surrounding [[ ]] brackets', @@ -158,6 +161,8 @@ export const translations: Record> = { 'enable-wikilink': '启用 Wiki 链接', 'enable-wikilink-desc': '启用复制 [[Wiki]] 链接', 'special-format': '特殊复制格式选项', + 'auto-embed-block-link': '块链接:自动添加 ! 符号(嵌入块)', + 'auto-embed-block-link-desc': '复制块链接时自动在前面添加 !,用于嵌入块', 'keep-wiki-brackets': 'Wiki 链接:保留 [[ ]] 括号', 'keep-wiki-brackets-desc': '复制 wiki 链接时保留两侧 [[ ]] 括号', @@ -224,6 +229,8 @@ export const translations: Record> = { 'enable-wikilink': '啟用 Wiki 連結', 'enable-wikilink-desc': '啟用複製 [[Wiki]] 連結', 'special-format': '特殊複製格式選項', + 'auto-embed-block-link': '塊連結:自動添加 ! 符號(嵌入塊)', + 'auto-embed-block-link-desc': '複製塊連結時自動在前面添加 !,用於嵌入塊', 'keep-wiki-brackets': 'Wiki連結:保留 [[ ]] 括號', 'keep-wiki-brackets-desc': '複製 wiki 連結時保留兩側 [[ ]] 括號', diff --git a/src/main.ts b/src/main.ts index b55f21a..b5fd668 100644 --- a/src/main.ts +++ b/src/main.ts @@ -474,9 +474,13 @@ export default class EasyCopy extends Plugin { // displayText = "^"+displayText; - const blockIdLink = this.settings.linkFormat === LinkFormat.WIKILINK + let blockIdLink = this.settings.linkFormat === LinkFormat.WIKILINK ? `[[${filename}#^${blockId}|${displayText}]]` - : `[^${displayText}](${filename}#^${blockId})`; + : `[^${displayText}](${filename}#^${blockId})`; + + if (this.settings.autoEmbedBlockLink) { + blockIdLink = `!${blockIdLink}`; + } navigator.clipboard.writeText(blockIdLink); if (this.settings.showNotice) { diff --git a/src/settingTab.ts b/src/settingTab.ts index b42f307..93e9a6f 100644 --- a/src/settingTab.ts +++ b/src/settingTab.ts @@ -194,6 +194,17 @@ export class EasyCopySettingTab extends PluginSettingTab { .setName(this.plugin.t('special-format')) .setHeading(); + // 块链接特殊格式选项 + new Setting(containerEl) + .setName(this.plugin.t('auto-embed-block-link')) + .setDesc(this.plugin.t('auto-embed-block-link-desc')) + .addToggle(toggle => toggle + .setValue(this.plugin.settings.autoEmbedBlockLink ?? false) + .onChange(async (value) => { + this.plugin.settings.autoEmbedBlockLink = value; + await this.plugin.saveSettings(); + })); + // 仅当启用 Wiki 链接复制时显示 if (this.plugin.settings.enableWikiLink) { new Setting(containerEl) diff --git a/src/type.ts b/src/type.ts index 0bd7e34..a68277b 100644 --- a/src/type.ts +++ b/src/type.ts @@ -40,6 +40,7 @@ export interface EasyCopySettings { enableLink: boolean; enableWikiLink: boolean; // 是否启用 Wiki 链接复制 keepWikiBrackets: boolean; // 复制 wiki-link 时保留 [[ ]] + autoEmbedBlockLink: boolean; // 复制块链接时自动添加 !(嵌入块) autoAddBlockId: boolean; // 是否自动添加 Block ID allowManualBlockId: boolean; // 是否允许手动输入 Block ID } @@ -59,6 +60,7 @@ export const DEFAULT_SETTINGS: EasyCopySettings = { enableLink: true, enableWikiLink: true, keepWikiBrackets: true, + autoEmbedBlockLink: false, autoAddBlockId: false, // 默认关闭 allowManualBlockId: false, // 默认关闭 } \ No newline at end of file