feat: add option to generate embeded block

This commit is contained in:
Moy 2025-05-19 13:36:53 +08:00
parent d43141e6c5
commit 6b317b7b48
4 changed files with 26 additions and 2 deletions

View file

@ -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<Language, Record<TranslationKey, string>> = {
'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<Language, Record<TranslationKey, string>> = {
'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<Language, Record<TranslationKey, string>> = {
'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 連結時保留兩側 [[ ]] 括號',

View file

@ -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) {

View file

@ -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)

View file

@ -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, // 默认关闭
}