Skip to content

Commit

Permalink
Merge pull request #2549 from microsoft/u/juliaroldi/auto-format-demo…
Browse files Browse the repository at this point in the history
…-site

Fix AutorFormat
  • Loading branch information
juliaroldi authored Apr 2, 2024
2 parents f362e01 + 13543b9 commit 9460c0c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const initialState: OptionState = {
imageMenu: true,
tableMenu: true,
listMenu: true,
autoFormatOptions: {
autoBullet: true,
autoLink: true,
autoNumbering: true,
autoUnlink: false,
},
markdownOptions: {
bold: true,
italic: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MarkdownOptions } from 'roosterjs-content-model-plugins';
import { AutoFormatOptions, MarkdownOptions } from 'roosterjs-content-model-plugins';
import type { ContentEditFeatureSettings } from 'roosterjs-editor-types';
import type { SidePaneElementProps } from '../SidePaneElement';
import type { ContentModelSegmentFormat } from 'roosterjs-content-model-types';
Expand Down Expand Up @@ -36,6 +36,7 @@ export interface OptionState {
tableMenu: boolean;
imageMenu: boolean;
watermarkText: string;
autoFormatOptions: AutoFormatOptions;
markdownOptions: MarkdownOptions;

// Legacy plugin options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class OptionsPane extends React.Component<OptionPaneProps, OptionState> {
listMenu: this.state.listMenu,
tableMenu: this.state.tableMenu,
imageMenu: this.state.imageMenu,
autoFormatOptions: { ...this.state.autoFormatOptions },
markdownOptions: { ...this.state.markdownOptions },
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AutoFormatOptions } from 'roosterjs-content-model-plugins';
import { CodeElement } from './CodeElement';

export class AutoFormatCode extends CodeElement {
constructor(private options: AutoFormatOptions) {
super();
}

getCode() {
return `new roosterjs.AutoFormatPlugin({
autoBullet: ${this.options.autoBullet},
autoLink: ${this.options.autoLink},
autoNumbering: ${this.options.autoNumbering},
autoUnlink: ${this.options.autoUnlink},
})`;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AutoFormatCode } from './AutoFormatCode';
import { CodeElement } from './CodeElement';
import { ContentEditCode } from './ContentEditCode';
import { HyperLinkCode } from './HyperLinkCode';
import { MarkdownCode } from './MarkdownCode';
import { OptionState } from '../OptionState';
import { WatermarkCode } from './WatermarkCode';
import {
AutoFormatPluginCode,
CustomReplaceCode,
EditPluginCode,
ImageEditCode,
Expand Down Expand Up @@ -39,7 +39,7 @@ export class PluginsCode extends PluginsCodeBase {
const pluginList = state.pluginList;

super([
pluginList.autoFormat && new AutoFormatPluginCode(),
pluginList.autoFormat && new AutoFormatCode(state.autoFormatOptions),
pluginList.edit && new EditPluginCode(),
pluginList.paste && new PastePluginCode(),
pluginList.tableEdit && new TableEditPluginCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ class SimplePluginCode extends CodeElement {
}
}

export class AutoFormatPluginCode extends SimplePluginCode {
constructor() {
super('AutoFormatPlugin');
}
}

export class EditPluginCode extends SimplePluginCode {
constructor() {
super('EditPlugin');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function getListTypeStyle(
listMarkerSegment &&
listMarkerSegment.segmentType == 'Text'
) {
const listMarker = listMarkerSegment.text;
const listMarker = listMarkerSegment.text.trim();
const bulletType = bulletListType[listMarker];

if (bulletType && shouldSearchForBullet) {
Expand Down Expand Up @@ -125,7 +125,7 @@ const bulletListType: Record<string, number> = {
};

const isNewList = (listMarker: string) => {
const marker = listMarker.replace(/[^\w\s]/g, '').trim();
const marker = listMarker.replace(/[^\w\s]/g, '');
const pattern = /^[1aAiI]$/;
return pattern.test(marker);
};

0 comments on commit 9460c0c

Please sign in to comment.