Skip to content

Commit

Permalink
feat: 1.emmet功能
Browse files Browse the repository at this point in the history
  • Loading branch information
JuckZ committed Apr 24, 2023
1 parent 68c3cdb commit ed41a24
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { MarkdownFileInfo, PluginManifest } from 'obsidian';

import { ref } from 'vue';
import type { Database } from 'sql.js';
import { expandEmmetAbbreviation } from './utils/emmet';
import Replacer from '@/Replacer';
import Process from '@/process/Process';
import { checkInDefaultPath, checkInList, customSnippetPath } from '@/utils/constants';
Expand All @@ -29,7 +30,6 @@ import { toggleCursorEffects, toggleMouseClickEffects } from '@/render/CursorEff
import LoggerUtil from '@/utils/logger';
import { getAllFiles, getCleanTitle, getNotePath } from '@/utils/file';
import { getWeather } from '@/utils/weather';
import { getTagsFromTask, getTaskContentFromTask } from '@/utils/common';
import { DBUtil } from '@/utils/db/db';
import { insertAfterHandler } from '@/utils/content';
import { getLocalRandomImg, searchPicture } from '@/utils/genBanner';
Expand All @@ -39,15 +39,13 @@ import { PluginDataIO } from '@/data';
import { eventTypes } from '@/types/types';
import type { ExtApp } from '@/types/types';
import { onCodeMirrorChange, toggleBlast, toggleShake } from '@/render/Blast';
import type { Pomodoro } from '@/schemas/spaces';
import { notifyNtfy } from '@/api';
import '@/main.scss';
import { NotifyUtil } from '@/utils/notify';
import { EditorUtil, EditorUtils } from '@/utils/editor';
import t from '@/i18n';
import { usePomodoroStore, useSystemStore } from '@/stores';
import { UpdateModal } from '@/ui/modal/UpdateModal';
import { generateMarkdownTable } from '@/utils/table';

export const OpenUrl = ref('https://baidu.com');
const media = window.matchMedia('(prefers-color-scheme: dark)');
Expand Down Expand Up @@ -580,16 +578,9 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
if (event.key === 'Tab') {
const editor = this.app.workspace.activeEditor?.editor as Editor;
if (editor) {
let triggerText = EditorUtils.getCurrentSelection(editor);
triggerText = triggerText.trim();
if (triggerText === 't') {
const targetText = '- [ ] ';
EditorUtils.replaceCurrentSelection(editor, targetText);
event.preventDefault();
}
const tableConfig = triggerText.match(/^t(\d+)\*(\d+)/);
if (tableConfig) {
const targetText = generateMarkdownTable(tableConfig[1], tableConfig[2]);
const triggerText = EditorUtils.getCurrentSelection(editor);
const targetText = expandEmmetAbbreviation(triggerText);
if (targetText) {
EditorUtils.replaceCurrentSelection(editor, targetText);
event.preventDefault();
}
Expand Down
109 changes: 109 additions & 0 deletions src/utils/emmet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { generateMarkdownTable } from '@/utils/table';

export function expandEmmetAbbreviation(syntax: string) {
syntax = syntax.trim().toUpperCase();
if (syntax === 'T') {
return '- [ ] ';
}
const tableConfig = syntax.match(/^T(\d+)\*(\d+)/);
if (tableConfig) {
return generateMarkdownTable(tableConfig[1], tableConfig[2]);
}
if (syntax === 'SMART') {
return SMART;
}
if (syntax === 'SWOT') {
return SWOT;
}
if (syntax === 'PROBLEM') {
return RESOLVE_PROBLEM_STEP;
}
return '';
}

const SMART = `
# 主题或目标
## Specific(具体性)
明确你的笔记中要包含哪些内容,这个主题或目标的具体细节是什么?你想实现什么?
## Measurable(可度量性)
如何测量这个主题或目标的成功?是否需要特定的指标?
## Achievable(可实现性)
此笔记是否可实现?是否需要更多资源或技能?
## Relevant(相关性)
这个主题或目标是否与你的整体目标相一致?它是否与你正在进行的专业、职业或学术项目有关?
## Time-bound(时限性)
设置一个截止时间以避免拖延,并使笔记尽快产生实际价值。
# 概念和细节
在这里,你可以编写关于主题或目标的详细信息、定义、例子和其他必要的细节。
# 行动计划
制定一份行动计划,以便在将笔记用于未来项目和目标时,能够更有效地指导你的行动。
# 总结
对于这个主题或目标,做出一个总结,并列出任何需要进一步研究或了解的问题。`;

const SWOT = `
# 主题或目标
在这里输入你要分析的主题或目标。
## Strengths(优势)
列出主题或目标的优势。
- 优势 1
- 优势 2
- 优势 3
## Weaknesses(劣势)
列出主题或目标的劣势。
- 劣势 1
- 劣势 2
- 劣势 3
## Opportunities(机会)
列出主题或目标的机会。
- 机会 1
- 机会 2
- 机会 3
## Threats(威胁)
列出主题或目标所面临的威胁。
- 威胁 1
- 威胁 2
- 威胁 3
# 总结
在这里对 SWOT 分析进行总结,包括你的结论、建议和下一步行动计划。`;

// TODO 如何成为解决问题的高手
const RESOLVE_PROBLEM_STEP = `
## 明确和理解问题
## 定位和拆分
## 猜想和验证
## 总结和反思
`;

0 comments on commit ed41a24

Please sign in to comment.