| 783 | |
| 784 | // 必需方法:告诉 Obsidian 这个视图可以接受哪些扩展名 |
| 785 | static canAcceptExtension(extension: string): boolean { |
| 786 | const ext = extension.toLowerCase(); |
| 787 | |
| 788 | // 检查用户是否在管理列表中添加了这个扩展名 |
| 789 | type WindowWithApp = Window & { app?: { plugins: { getPlugin(id: string): CodeSpacePlugin | undefined } } }; |
| 790 | const app = (window as unknown as WindowWithApp).app; |
| 791 | const plugin = app?.plugins?.getPlugin("code-space"); |
| 792 | if (plugin && plugin.settings) { |
| 793 | const extensions = plugin.settings.extensions |
| 794 | .split(',') |
| 795 | .map((s: string) => s.trim().toLowerCase()) |
| 796 | .filter((s: string) => s); |
| 797 | return extensions.includes(ext); |
| 798 | } |
| 799 | |
| 800 | // 默认支持常见的代码文件扩展名 |
| 801 | return ['py', 'c', 'cpp', 'h', 'hpp', 'js', 'ts', 'jsx', 'tsx', 'json', 'html', 'css', 'sql', 'php', 'r'].includes(ext); |
| 802 | } |
| 803 | |
| 804 | constructor(leaf: WorkspaceLeaf) { |
| 805 | super(leaf); |