Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function fragmentHandler(doc: HTMLDocument, source: string) {
let [html, before] = splitWithFragment(source);
let firstNode = doc && doc.body && (doc.querySelector('html') as HTMLElement);
if (getTagOfNode(firstNode) == 'HTML') {
if (firstNode.getAttribute(WORD_ATTRIBUTE_NAME) == WORD_ATTRIBUTE_VALUE) {
// Handle HTML copied from MS Word
doc.body.innerHTML = html;
convertPastedContentFromWord(doc);
} else if (isWAC(firstNode)) {
// The WAC converter only supports word for now.
convertPastedContentFromWac(doc);
} else if (firstNode.getAttribute(EXCEL_ATTRIBUTE_NAME) == EXCEL_ATTRIBUTE_VALUE) {
// Handle HTML copied from MS Excel
if (html.match(LAST_TD_END_REGEX)) {
let trMatch = before.match(LAST_TR_REGEX);
let tr = trMatch ? trMatch[0] : '';
html = tr + html + '';
}