Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let contentModelToText accepts readonly types #2947

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>;
}
Loading