Skip to content

Commit

Permalink
Let contentModelToText accepts readonly types
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Feb 13, 2025
1 parent ce1afbe commit 63620b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
ContentModelBlockGroup,
ContentModelDocument,
ModelToTextCallbacks,
ReadonlyContentModelBlockGroup,
ReadonlyContentModelDocument,
} from 'roosterjs-content-model-types';

const TextForHR = '________________________________________';
Expand All @@ -24,7 +24,7 @@ const defaultCallbacks: Required<ModelToTextCallbacks> = {
* @param callbacks Callbacks to customize the behavior of contentModelToText function
*/
export function contentModelToText(
model: ContentModelDocument,
model: ReadonlyContentModelDocument,
separator: string = '\r\n',
callbacks?: ModelToTextCallbacks
): string {
Expand All @@ -37,7 +37,7 @@ export function contentModelToText(
}

function contentModelToTextArray(
group: ContentModelBlockGroup,
group: ReadonlyContentModelBlockGroup,
textArray: string[],
callbacks: Required<ModelToTextCallbacks>
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { ContentModelBlockGroup } from '../contentModel/blockGroup/ContentModelBlockGroup';
import type { ContentModelDivider } from '../contentModel/block/ContentModelDivider';
import type { ReadonlyContentModelBlockGroup } from '../contentModel/blockGroup/ContentModelBlockGroup';
import type { ReadonlyContentModelDivider } from '../contentModel/block/ContentModelDivider';
import type { ContentModelEntity } from '../contentModel/entity/ContentModelEntity';
import type { ContentModelGeneralSegment } from '../contentModel/segment/ContentModelGeneralSegment';
import type { ContentModelImage } from '../contentModel/segment/ContentModelImage';
import type { ContentModelParagraph } from '../contentModel/block/ContentModelParagraph';
import type { ContentModelTable } from '../contentModel/block/ContentModelTable';
import type { ContentModelText } from '../contentModel/segment/ContentModelText';
import type { ReadonlyContentModelGeneralSegment } from '../contentModel/segment/ContentModelGeneralSegment';
import type { ReadonlyContentModelImage } from '../contentModel/segment/ContentModelImage';
import type { ReadonlyContentModelParagraph } from '../contentModel/block/ContentModelParagraph';
import type { ReadonlyContentModelTable } from '../contentModel/block/ContentModelTable';
import type { ReadonlyContentModelText } from '../contentModel/segment/ContentModelText';

/**
* Callback function type for converting a given Content Model object to plain text
Expand Down Expand Up @@ -36,35 +36,35 @@ export interface ModelToTextCallbacks {
/**
* Customize the behavior of converting general segment to plain text
*/
onGeneralSegment?: ModelToTextCallback<ContentModelGeneralSegment>;
onGeneralSegment?: ModelToTextCallback<ReadonlyContentModelGeneralSegment>;

/**
* Customize the behavior of converting text model to plain text
*/
onText?: ModelToTextCallback<ContentModelText>;
onText?: ModelToTextCallback<ReadonlyContentModelText>;

/**
* Customize the behavior of converting image model to plain text
*/
onImage?: ModelToTextCallback<ContentModelImage>;
onImage?: ModelToTextCallback<ReadonlyContentModelImage>;

/**
* Customize the behavior of converting divider model to plain text
*/
onDivider?: ModelToTextCallback<ContentModelDivider>;
onDivider?: ModelToTextCallback<ReadonlyContentModelDivider>;

/**
* Customize the check if we should convert a paragraph model to plain text
*/
onParagraph?: ModelToTextChecker<ContentModelParagraph>;
onParagraph?: ModelToTextChecker<ReadonlyContentModelParagraph>;

/**
* Customize the check if we should convert a table model to plain text
*/
onTable?: ModelToTextChecker<ContentModelTable>;
onTable?: ModelToTextChecker<ReadonlyContentModelTable>;

/**
* Customize the check if we should convert a block group model to plain text
*/
onBlockGroup?: ModelToTextChecker<ContentModelBlockGroup>;
onBlockGroup?: ModelToTextChecker<ReadonlyContentModelBlockGroup>;
}

0 comments on commit 63620b5

Please sign in to comment.