mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(core): wrap code in ai chat (#10108)
[BS-2540](https://linear.app/affine-design/issue/BS-2540/ai-chat-中-code-block-需要默认换行)
This commit is contained in:
@@ -9,7 +9,9 @@ import type {
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
CodeBlockComponent,
|
||||
codeBlockWrapMiddleware,
|
||||
defaultBlockMarkdownAdapterMatchers,
|
||||
defaultImageProxyMiddleware,
|
||||
DividerBlockComponent,
|
||||
InlineDeltaToMarkdownAdapterExtensions,
|
||||
ListBlockComponent,
|
||||
@@ -213,12 +215,12 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
|
||||
provider = container.provider();
|
||||
}
|
||||
if (latestAnswer && schema) {
|
||||
markDownToDoc(
|
||||
provider,
|
||||
schema,
|
||||
latestAnswer,
|
||||
this.options.additionalMiddlewares
|
||||
)
|
||||
const middlewares = [
|
||||
defaultImageProxyMiddleware,
|
||||
codeBlockWrapMiddleware(true),
|
||||
...(this.options.additionalMiddlewares ?? []),
|
||||
];
|
||||
markDownToDoc(provider, schema, latestAnswer, middlewares)
|
||||
.then(doc => {
|
||||
this.disposeDoc();
|
||||
this._doc = doc.doc.getStore({
|
||||
|
||||
@@ -206,17 +206,13 @@ export async function markDownToDoc(
|
||||
provider: ServiceProvider,
|
||||
schema: Schema,
|
||||
answer: string,
|
||||
additionalMiddlewares?: TransformerMiddleware[]
|
||||
middlewares?: TransformerMiddleware[]
|
||||
) {
|
||||
// Should not create a new doc in the original collection
|
||||
const collection = new WorkspaceImpl({
|
||||
schema,
|
||||
});
|
||||
collection.meta.initialize();
|
||||
const middlewares = [defaultImageProxyMiddleware];
|
||||
if (additionalMiddlewares) {
|
||||
middlewares.push(...additionalMiddlewares);
|
||||
}
|
||||
const transformer = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from '@blocksuite/affine/block-std';
|
||||
import type { AffineAIPanelWidget } from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
defaultImageProxyMiddleware,
|
||||
deleteTextCommand,
|
||||
isInsideEdgelessEditor,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
@@ -151,7 +152,8 @@ export const copyText = async (host: EditorHost, text: string) => {
|
||||
const previewDoc = await markDownToDoc(
|
||||
host.std.provider,
|
||||
host.std.store.schema,
|
||||
text
|
||||
text,
|
||||
[defaultImageProxyMiddleware]
|
||||
);
|
||||
const models = previewDoc
|
||||
.getBlocksByFlavour('affine:note')
|
||||
|
||||
Reference in New Issue
Block a user