-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9022291
commit 973592a
Showing
43 changed files
with
2,141 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...sV2/sidePane/plainText/PlainTextPlugin.ts → ...dePane/MarkdownPane/MarkdownPanePlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
...ages/roosterjs-content-model-api/lib/modelApi/markdown/creators/createListFromMarkdown.ts
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
...ges/roosterjs-content-model-api/lib/modelApi/markdown/creators/createTableFromMarkdown.ts
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
packages/roosterjs-content-model-api/lib/modelApi/markdown/utils/applyTextFormatting.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { convertMarkdownToContentModel } from './markdownToModel/convertMarkdownToContentModel'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ages/roosterjs-content-model-markdown/lib/markdownToModel/appliers/applyTextFormatting.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createText } from 'roosterjs-content-model-dom'; | ||
import type { | ||
ContentModelLink, | ||
ContentModelSegmentFormat, | ||
ContentModelText, | ||
} from 'roosterjs-content-model-types'; | ||
|
||
const SPLIT_PATTERN = /(\*\*\*.*?\*\*\*|\*\*.*?\*\*|\*.*?\*)/; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function applyTextFormatting(textSegment: ContentModelText) { | ||
const texts = splitSegments(textSegment.text); | ||
const textSegments: ContentModelText[] = []; | ||
for (const text of texts) { | ||
textSegments.push(createFormattedSegment(text, textSegment.format, textSegment.link)); | ||
} | ||
return textSegments; | ||
} | ||
|
||
function splitSegments(text: string): string[] { | ||
return text.split(SPLIT_PATTERN).filter(s => s.trim().length > 0); | ||
} | ||
|
||
function createFormattedSegment( | ||
text: string, | ||
format: ContentModelSegmentFormat, | ||
link?: ContentModelLink | ||
): ContentModelText { | ||
if (text.startsWith('***') && text.endsWith('***')) { | ||
format = { ...format, fontWeight: 'bold', italic: true }; | ||
text = text.replace(/\*\*\*/g, ''); | ||
text = text + ' '; | ||
} else if (text.startsWith('**') && text.endsWith('**')) { | ||
format = { ...format, fontWeight: 'bold' }; | ||
text = text.replace(/\*\*/g, ''); | ||
text = text + ' '; | ||
} else if (text.startsWith('*') && text.endsWith('*')) { | ||
format = { ...format, italic: true }; | ||
text = text.replace(/\*/g, ''); | ||
text = text + ' '; | ||
} | ||
|
||
return createText(text, format, link); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...s/roosterjs-content-model-markdown/lib/markdownToModel/creators/createListFromMarkdown.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { createListItem, createListLevel } from 'roosterjs-content-model-dom'; | ||
import { createParagraphFromMarkdown } from './createParagraphFromMarkdown'; | ||
import type { ContentModelListItem } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function createListFromMarkdown(text: string, patternName: string): ContentModelListItem { | ||
const listType = patternName === 'ordered_list' ? 'OL' : 'UL'; | ||
const itemText = text.trim().substring(listType == 'OL' ? 2 : 1); | ||
const paragraph = createParagraphFromMarkdown(itemText.trim()); | ||
const levels = createLevels(text, listType); | ||
const listModel = createListItem(levels); | ||
listModel.blocks.push(paragraph); | ||
return listModel; | ||
} | ||
|
||
function createLevels(text: string, listType: 'OL' | 'UL') { | ||
const level = createListLevel(listType); | ||
const levels = [level]; | ||
if (isSubListItem(text)) { | ||
levels.push(level); | ||
} | ||
return levels; | ||
} | ||
|
||
function isSubListItem(item: string): boolean { | ||
return item.startsWith(' '); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.