Skip to content

Commit

Permalink
adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaroldi committed Apr 1, 2024
1 parent f9a11a0 commit 1f105ff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
1 change: 1 addition & 0 deletions demo/scripts/controlsV2/mainPane/MainPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ export class MainPane extends React.Component<{}, MainPaneState> {
bold: true,
italic: true,
strikethrough: true,
codeFormat: {},
}),
pluginList.emoji && createEmojiPlugin(),
pluginList.pasteOption && createPasteOptionPlugin(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import type {
} from 'roosterjs-content-model-types';

/**
*
* Options for Markdown plugin
* - strikethrough: If true text between ~ will receive strikethrough format.
* - bold: If true text between * will receive bold format.
* - italic: If true text between _ will receive italic format.
* - codeFormat: If provided, text between ` will receive code format. If equal to {}, it will set the default code format.
*/
export interface MarkdownOptions {
strikethrough?: boolean;
bold?: boolean;
italic?: boolean;
code?: ContentModelCodeFormat;
codeFormat?: ContentModelCodeFormat;
}

/**
Expand All @@ -41,10 +46,10 @@ export class MarkdownPlugin implements EditorPlugin {

/**
* @param options An optional parameter that takes in an object of type MarkdownOptions, which includes the following properties:
* - strikethrough: If true text between ~ will receive strikethrough format. Defaults to true.
* - bold: If true text between * will receive bold format. Defaults to true.
* - italic: If true text between _ will receive italic format. Defaults to true.
* - code: If provided, text between ` will receive code format. Defaults to { format: {} }.
* - strikethrough: If true text between ~ will receive strikethrough format. Defaults to false.
* - bold: If true text between * will receive bold format. Defaults to false.
* - italic: If true text between _ will receive italic format. Defaults to false.
* - codeFormat: If provided, text between ` will receive code format. Defaults to undefined.
*/
constructor(private options: MarkdownOptions = DefaultOptions) {}

Expand Down Expand Up @@ -141,9 +146,9 @@ export class MarkdownPlugin implements EditorPlugin {
}
break;
case '`':
if (this.options.code) {
if (this.options.codeFormat) {
if (this.shouldCode) {
setFormat(editor, '`', {} /* format */, this.options.code);
setFormat(editor, '`', {} /* format */, this.options.codeFormat);
this.shouldCode = false;
} else {
this.shouldCode = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as setFormat from '../../lib/markdown/utils/setFormat';
import { MarkdownOptions, MarkdownPlugin } from '../../lib/markdown/MarkdownPlugin';
import {
ContentChangedEvent,
ContentModelCode,
ContentModelCodeFormat,
ContentModelSegmentFormat,
EditorInputEvent,
IEditor,
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('MarkdownPlugin', () => {
options?: MarkdownOptions,
expectedChar?: string,
expectedFormat?: ContentModelSegmentFormat,
expectedCode?: ContentModelCode
expectedCode?: ContentModelCodeFormat
) {
const plugin = new MarkdownPlugin(options);
plugin.initialize(editor);
Expand Down Expand Up @@ -206,10 +206,10 @@ describe('MarkdownPlugin', () => {
} as EditorInputEvent,
],
true,
{ bold: true, italic: true, strikethrough: true, code: { format: {} } },
{ bold: true, italic: true, strikethrough: true, codeFormat: {} },
'`',
{},
{ format: {} }
{}
);
});

Expand All @@ -230,7 +230,7 @@ describe('MarkdownPlugin', () => {
} as EditorInputEvent,
],
false,
{ bold: true, italic: true, strikethrough: true, code: undefined }
{ bold: true, italic: true, strikethrough: true, codeFormat: undefined }
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setFormat } from '../../../lib/markdown/utils/setFormat';
import {
ContentModelCode,
ContentModelCodeFormat,
ContentModelDocument,
ContentModelSegmentFormat,
} from 'roosterjs-content-model-types';
Expand All @@ -12,7 +12,7 @@ describe('setFormat', () => {
format: ContentModelSegmentFormat,
expectedModel: ContentModelDocument,
expectedResult: boolean,
code: ContentModelCode | undefined = undefined
code: ContentModelCodeFormat | undefined = undefined
) {
const formatWithContentModelSpy = jasmine
.createSpy('formatWithContentModel')
Expand Down Expand Up @@ -249,18 +249,14 @@ describe('setFormat', () => {
{
blockType: 'Paragraph',
segments: [
{
segmentType: 'Text',
text: '',
format: {},
},
{
segmentType: 'Text',
text: 'test',
format: {},
code: {
format: {},
},
isSelected: undefined,
},
{
segmentType: 'SelectionMarker',
Expand All @@ -273,7 +269,7 @@ describe('setFormat', () => {
],
format: {},
};
runTest(input, '`', {}, expectedModel, true, { format: {} });
runTest(input, '`', {}, expectedModel, true, {});
});

it('should set code with format', () => {
Expand Down Expand Up @@ -305,11 +301,6 @@ describe('setFormat', () => {
{
blockType: 'Paragraph',
segments: [
{
segmentType: 'Text',
text: '',
format: {},
},
{
segmentType: 'Text',
text: 'test',
Expand All @@ -319,6 +310,7 @@ describe('setFormat', () => {
fontFamily: 'arial',
},
},
isSelected: undefined,
},
{
segmentType: 'SelectionMarker',
Expand All @@ -331,7 +323,7 @@ describe('setFormat', () => {
],
format: {},
};
runTest(input, '`', {}, expectedModel, true, { format: { fontFamily: 'arial' } });
runTest(input, '`', {}, expectedModel, true, { fontFamily: 'arial' });
});

it('should set bold in multiple words', () => {
Expand Down

0 comments on commit 1f105ff

Please sign in to comment.