mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 12:36:24 +08:00
24448659a4
Fix #12284 Close [BS-3517](https://linear.app/affine-design/issue/BS-3517/微软新注音输入法无法使用markdown语法) This PR refactor the markdown transform during inputting, including: - Transfrom markdown syntax input in `inlineEditor.slots.inputting`, where we can detect the space character inputed by IME like Microsoft Bopomofo, but `keydown` event can't. - Remove `markdown-input.ts` which was used in `KeymapExtension` of paragraph, and refactor with `InlineMarkdownExtension` - Adjust existing `InlineMarkdownExtension` since the space is included in text. - Add two `InlineMarkdownExtension` for paragraph and list to impl Heading1-6, number, bullet, to-do list conversion. Other changes: - Improve type hint for parameter of `store.addBlock` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit - **New Features** - Added markdown shortcuts for creating code blocks and dividers in the rich text editor. - Introduced enhanced paragraph markdown support for headings and blockquotes with inline markdown patterns. - Integrated new list markdown extension supporting numbered, bulleted, and todo lists with checked states. - **Improvements** - Updated markdown formatting patterns to require trailing spaces for links, LaTeX, and inline styles, improving detection accuracy. - Markdown transformations now respond to input events instead of keydown for smoother editing experience. - Added focus management after markdown transformations to maintain seamless editing flow. - **Bug Fixes** - Removed unnecessary prevention of default behavior on space and shift-space key presses in list and paragraph editors. - **Refactor** - Enhanced event handling and typing for editor input events, improving reliability and maintainability. - Refined internal prefix text extraction logic for markdown processing. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import {
|
|
type ViewExtensionContext,
|
|
ViewExtensionProvider,
|
|
} from '@blocksuite/affine-ext-loader';
|
|
import { SlashMenuConfigExtension } from '@blocksuite/affine-widget-slash-menu';
|
|
import {
|
|
BlockViewExtension,
|
|
FlavourExtension,
|
|
WidgetViewExtension,
|
|
} from '@blocksuite/std';
|
|
import { literal, unsafeStatic } from 'lit/static-html.js';
|
|
|
|
import { getCodeClipboardExtensions } from './clipboard/index.js';
|
|
import { CodeBlockConfigExtension } from './code-block-config';
|
|
import {
|
|
CodeBlockInlineManagerExtension,
|
|
CodeBlockUnitSpecExtension,
|
|
} from './code-block-inline.js';
|
|
import { CodeBlockHighlighter } from './code-block-service.js';
|
|
import { CodeKeymapExtension } from './code-keymap.js';
|
|
import { AFFINE_CODE_TOOLBAR_WIDGET } from './code-toolbar/index.js';
|
|
import { codeSlashMenuConfig } from './configs/slash-menu.js';
|
|
import { effects } from './effects.js';
|
|
import { CodeBlockMarkdownExtension } from './markdown.js';
|
|
|
|
const codeToolbarWidget = WidgetViewExtension(
|
|
'affine:code',
|
|
AFFINE_CODE_TOOLBAR_WIDGET,
|
|
literal`${unsafeStatic(AFFINE_CODE_TOOLBAR_WIDGET)}`
|
|
);
|
|
|
|
export class CodeBlockViewExtension extends ViewExtensionProvider {
|
|
override name = 'affine-code-block';
|
|
|
|
override effect() {
|
|
super.effect();
|
|
effects();
|
|
}
|
|
|
|
override setup(context: ViewExtensionContext) {
|
|
super.setup(context);
|
|
context.register([
|
|
FlavourExtension('affine:code'),
|
|
CodeBlockHighlighter,
|
|
BlockViewExtension('affine:code', literal`affine-code`),
|
|
SlashMenuConfigExtension('affine:code', codeSlashMenuConfig),
|
|
CodeKeymapExtension,
|
|
CodeBlockMarkdownExtension,
|
|
...getCodeClipboardExtensions(),
|
|
]);
|
|
context.register([
|
|
CodeBlockInlineManagerExtension,
|
|
CodeBlockUnitSpecExtension,
|
|
]);
|
|
if (!this.isMobile(context.scope)) {
|
|
context.register(codeToolbarWidget);
|
|
} else {
|
|
context.register(
|
|
CodeBlockConfigExtension({
|
|
showLineNumbers: false,
|
|
})
|
|
);
|
|
}
|
|
}
|
|
}
|