Skip to content

Commit

Permalink
refactor(*): remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
Natumsol committed Nov 15, 2022
1 parent 04b4225 commit 0644655
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
21 changes: 3 additions & 18 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
import { App, Plugin, PluginSettingTab, Setting, MarkdownView } from 'obsidian';
// @ts-ignore
import prettier from 'prettier/esm/standalone';
// @ts-ignore
import markdownParser from 'prettier/esm/parser-markdown';

const { format } = prettier;
import { format } from './util';

export default class Pangu extends Plugin {
format(cm: CodeMirror.Editor): void {
let cursor = cm.getCursor();
let cursorContent = cm.getRange({ ...cursor, ch: 0 }, cursor);
const { top } = cm.getScrollInfo();

// cursorContent = formatUtil.formatContent(cursorContent);
cursorContent = format(cursorContent, {
parser: 'markdown',
plugins: [markdownParser]
});

cursorContent = format(cursorContent);
let content = cm.getValue().trim();
// content = formatUtil.formatContent(content);
content = format(content, {
parser: 'markdown',
plugins: [markdownParser]
})
content = format(content)

cm.setValue(content);

cm.scrollTo(null, top);

// 保持光标格式化后不变
Expand Down
11 changes: 11 additions & 0 deletions util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @ts-ignore
import prettier from 'prettier/esm/standalone';
// @ts-ignore
import markdownParser from 'prettier/esm/parser-markdown';

export function format(content: string): string {
return prettier.format(content, {
parser: 'markdown',
plugins: [markdownParser]
});
}

0 comments on commit 0644655

Please sign in to comment.