Skip to content

Commit

Permalink
fix 113409 (microsoft#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Apr 9, 2021
1 parent 6d0f724 commit 9cd4ec6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/roosterjs-editor-plugins/lib/plugins/Paste/Paste.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import convertPastedContentFromExcel from './excelConverter/convertPastedContentFromExcel';
import convertPastedContentFromTeams from './teamsConverter/convertPastedContentFromTeams';
import convertPastedContentFromWord from './wordConverter/convertPastedContentFromWord';
import handleLineMerge from './lineMerge/handleLineMerge';
import { EditorPlugin, PluginEvent, PluginEventType } from 'roosterjs-editor-types';
Expand Down Expand Up @@ -83,6 +84,7 @@ export default class Paste implements EditorPlugin {
} else if (fragment.querySelector(GOOGLE_SHEET_NODE_NAME)) {
sanitizingOption.additionalTagReplacements[GOOGLE_SHEET_NODE_NAME] = '*';
} else {
convertPastedContentFromTeams(fragment);
handleLineMerge(fragment);
}

Expand Down
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');
}
}

0 comments on commit 9cd4ec6

Please sign in to comment.