forked from microsoft/roosterjs
-
Notifications
You must be signed in to change notification settings - Fork 0
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
6d0f724
commit 9cd4ec6
Showing
2 changed files
with
23 additions
and
0 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
21 changes: 21 additions & 0 deletions
21
...oosterjs-editor-plugins/lib/plugins/Paste/teamsConverter/convertPastedContentFromTeams.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,21 @@ | ||
import { changeElementTag, getTagOfNode, toArray } from 'roosterjs-editor-dom'; | ||
|
||
/** | ||
* @internal | ||
* Convert content copied from Teams to be well-formed | ||
*/ | ||
export default function convertPastedContentFromTeams(fragment: DocumentFragment) { | ||
const firstChild = fragment.firstChild; | ||
|
||
// When copy from Teams, it is possible that we get LI nodes directly under DIV. | ||
// In that case we need to convert DIV to UL. It is also possible to be OL, but we don't know it. | ||
// So always assume it is UL here, and later user can change it. | ||
if ( | ||
firstChild && | ||
!firstChild.nextSibling && | ||
getTagOfNode(firstChild) == 'DIV' && | ||
!toArray(firstChild.childNodes).some(node => getTagOfNode(node) != 'LI') | ||
) { | ||
changeElementTag(firstChild as HTMLElement, 'UL'); | ||
} | ||
} |