feat(editor): support text highlight html adapter (#9632)

[BS-2061](https://linear.app/affine-design/issue/BS-2061/html-adapter-支持-text-highlight-样式)
This commit is contained in:
donteatfriedrice
2025-01-13 02:20:58 +00:00
parent 76895e29d8
commit 5c4e87ddb5
38 changed files with 216 additions and 144 deletions
@@ -1,6 +1,7 @@
import {
createIdentifier,
type ServiceIdentifier,
type ServiceProvider,
} from '@blocksuite/global/di';
import type { DeltaInsert } from '@blocksuite/inline';
import type { ExtensionType } from '@blocksuite/store';
@@ -62,7 +63,8 @@ export class HtmlDeltaConverter extends DeltaASTConverter<
constructor(
readonly configs: Map<string, string>,
readonly inlineDeltaMatchers: InlineDeltaToHtmlAdapterMatcher[],
readonly htmlASTToDeltaMatchers: HtmlASTToDeltaMatcher[]
readonly htmlASTToDeltaMatchers: HtmlASTToDeltaMatcher[],
readonly provider: ServiceProvider
) {
super();
}
@@ -84,7 +86,7 @@ export class HtmlDeltaConverter extends DeltaASTConverter<
};
for (const matcher of this.inlineDeltaMatchers) {
if (matcher.match(delta)) {
hast = matcher.toAST(delta, context);
hast = matcher.toAST(delta, context, this.provider);
context.current = hast;
}
}
@@ -132,6 +132,7 @@ export class HtmlAdapter extends BaseAdapter<Html> {
configs: this.configs,
job: this.job,
deltaConverter: this.deltaConverter,
provider: this.provider,
textBuffer: { content: '' },
assets,
updateAssetIds: (assetsId: string) => {
@@ -155,6 +156,7 @@ export class HtmlAdapter extends BaseAdapter<Html> {
configs: this.configs,
job: this.job,
deltaConverter: this.deltaConverter,
provider: this.provider,
textBuffer: { content: '' },
assets,
};
@@ -172,7 +174,10 @@ export class HtmlAdapter extends BaseAdapter<Html> {
readonly blockMatchers: BlockHtmlAdapterMatcher[];
constructor(job: Transformer, provider: ServiceProvider) {
constructor(
job: Transformer,
readonly provider: ServiceProvider
) {
super(job);
const blockMatchers = Array.from(
provider.getAll(BlockHtmlAdapterMatcherIdentifier).values()
@@ -187,7 +192,8 @@ export class HtmlAdapter extends BaseAdapter<Html> {
this.deltaConverter = new HtmlDeltaConverter(
job.adapterConfigs,
inlineDeltaToHtmlAdapterMatchers,
htmlInlineToDeltaMatchers
htmlInlineToDeltaMatchers,
provider
);
}