moyf_easy-copy/src/type.ts

127 lines
5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export enum LinkFormat {
OBSIDIAN = 'obsidian',
MDLINK = 'markdown-link',
WIKILINK = 'wiki-link'
}
export enum CodeBlockBehavior {
COPY_CONTENT = 'copy-content', // 复制代码块纯文本(不含 ``` 行)
COPY_WITH_FENCES = 'copy-with-fences', // 复制代码块(含前后 ``` 行)
GENERATE_BLOCK_LINK = 'generate-block-link', // 给代码块生成块链接
DISABLED = 'disabled', // 禁用(不做任何操作)
}
export enum BlockIdInsertPosition {
END_OF_BLOCK = 'end-of-block', // 当前块的末尾
NEXT_LINE = 'next-line', // 当前块的下方一行
// NEXT_LINE_WITH_GAP = 'next-line-with-gap' // 当前块的下方两行(中间隔一个空行)
}
export enum ContextType {
NULL = 'null',
HEADING = 'heading',
INLINECODE = 'inline-code',
BOLD = 'bold',
ITALIC = 'italic',
HIGHLIGHT = 'highlight',
STRIKETHROUGH = 'strikethrough',
BLOCKID = 'block-id',
INLINELATEX = 'inline-latex',
LINKTITLE = 'link-title',
LINEURL = 'line-url',
WIKILINK = 'wiki-link', // 光标在 [[双链]] 内
CALLOUT = 'callout', // 光标在 callout 区块内
CODEBLOCK = 'code-block', // 光标在代码块内
}
export type BuiltinCopyMatcherId =
| 'bold'
| 'italic'
| 'highlight'
| 'strikethrough'
| 'inline-code'
| 'inline-latex'
| 'wiki-link';
export interface ContextData {
type: ContextType;
curLine: string;
match: string | null;
range: [number, number] | null;
}
export interface EasyCopySettings {
useFrontmatterAsDisplay: boolean; // 是否使用 frontmatter 属性作为显示文本
frontmatterKey: string; // frontmatter 属性名
addToMenu: boolean;
addExtraCommands: boolean;
showNotice: boolean;
useHeadingAsDisplayText: boolean;
headingLinkSeparator: string; // 文件名和标题间的连接符
simplifiedHeadingToNoteLink: boolean; // 是否简化标题到笔记链接
strictHeadingMatch: boolean; // 标题与文件名简化匹配时是否使用严格匹配
linkFormat: LinkFormat;
resolveLinkPathOnPaste: boolean; // 粘贴时根据目标文件重新解析链接路径OBSIDIAN 格式支持完整路径风格,明确 Wiki/Markdown 仅支持最短唯一路径)
customizeTargets: boolean;
enableInlineCode: boolean;
enableBold: boolean;
enableHighlight: boolean;
enableItalic: boolean;
enableStrikethrough: boolean;
enableInlineLatex: boolean;
enableLink: boolean;
enableWikiLink: boolean; // 是否启用 Wiki 链接复制
matcherOrder: BuiltinCopyMatcherId[]; // 复制对象匹配优先级
keepWikiBrackets: boolean; // 复制 wiki-link 时保留 [[ ]]
autoEmbedBlockLink: boolean; // 复制块链接时自动添加 !(嵌入块)
enableCalloutCopy: boolean; // 是否启用复制 Callout 内文本
calloutCopyPriority: boolean; // Callout 与块ID冲突时优先复制 Callout
codeBlockBehavior: CodeBlockBehavior; // 代码块内的复制行为
autoAddBlockId: boolean; // 是否自动添加 Block ID
allowManualBlockId: boolean; // 是否允许手动输入 Block ID
blockIdInsertPosition: BlockIdInsertPosition; // 块ID的插入位置
autoBlockDisplayText: boolean; // 自动为 Block 添加显示文本
blockDisplayWordLimit: number; // Block 显示文本英文单词限制(按空格分隔)
blockDisplayCharLimit: number; // Block 显示文本字符限制(非英文语言)
enableDisplayNameRegex: boolean; // 是否启用正则替换显示名称
displayNameRegexFrom: string; // 正则替换from 模式
displayNameRegexTo: string; // 正则替换to 内容(支持 $1 等捕获组)
}
export const DEFAULT_SETTINGS: EasyCopySettings = {
useFrontmatterAsDisplay: false,
frontmatterKey: 'title',
addToMenu: true,
addExtraCommands: true,
showNotice: true,
useHeadingAsDisplayText: true,
headingLinkSeparator: '#',
simplifiedHeadingToNoteLink: true,
strictHeadingMatch: false,
linkFormat: LinkFormat.OBSIDIAN,
resolveLinkPathOnPaste: false,
customizeTargets: false,
enableInlineCode: true,
enableBold: true,
enableHighlight: true,
enableItalic: true,
enableStrikethrough: true,
enableInlineLatex: true,
enableLink: true,
enableWikiLink: true,
matcherOrder: ['bold', 'italic', 'highlight', 'strikethrough', 'inline-code', 'inline-latex', 'wiki-link'],
keepWikiBrackets: true,
autoEmbedBlockLink: false,
enableCalloutCopy: true,
calloutCopyPriority: true,
codeBlockBehavior: CodeBlockBehavior.COPY_CONTENT, // 默认复制代码块纯文本
autoAddBlockId: false, // 默认关闭
allowManualBlockId: false, // 默认关闭
blockIdInsertPosition: BlockIdInsertPosition.END_OF_BLOCK, // 默认在块末尾插入
autoBlockDisplayText: true,
blockDisplayWordLimit: 3, // 英文单词限制3个单词
blockDisplayCharLimit: 5, // 字符限制5个字符
enableDisplayNameRegex: false,
displayNameRegexFrom: '',
displayNameRegexTo: '',
}