MCPcopy
hub / github.com/textAngular/textAngular / processpaste

Function processpaste

src/taBind.js:529–709  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

527 var _processingPaste = false;
528 /* istanbul ignore next: phantom js cannot test this for some reason */
529 var processpaste = function(text) {
530 var _isOneNote = text!==undefined? text.match(/content=["']*OneNote.File/i): false;
531 /* istanbul ignore else: don't care if nothing pasted */
532 //console.log(text);
533 if(text && text.trim().length){
534 // test paste from word/microsoft product
535 if(text.match(/class=["']*Mso(Normal|List)/i) || text.match(/content=["']*Word.Document/i) || text.match(/content=["']*OneNote.File/i)){
536 var textFragment = text.match(/<!--StartFragment-->([\s\S]*?)<!--EndFragment-->/i);
537 if(!textFragment) textFragment = text;
538 else textFragment = textFragment[1];
539 textFragment = textFragment.replace(/<o:p>[\s\S]*?<\/o:p>/ig, '').replace(/class=(["']|)MsoNormal(["']|)/ig, '');
540 var dom = angular.element("<div>" + textFragment + "</div>");
541 var targetDom = angular.element("<div></div>");
542 var _list = {
543 element: null,
544 lastIndent: [],
545 lastLi: null,
546 isUl: false
547 };
548 _list.lastIndent.peek = function(){
549 var n = this.length;
550 if (n>0) return this[n-1];
551 };
552 var _resetList = function(isUl){
553 _list.isUl = isUl;
554 _list.element = angular.element(isUl ? "<ul>" : "<ol>");
555 _list.lastIndent = [];
556 _list.lastIndent.peek = function(){
557 var n = this.length;
558 if (n>0) return this[n-1];
559 };
560 _list.lastLevelMatch = null;
561 };
562 for(var i = 0; i <= dom[0].childNodes.length; i++){
563 if(!dom[0].childNodes[i] || dom[0].childNodes[i].nodeName === "#text"){
564 continue;
565 } else {
566 var tagName = dom[0].childNodes[i].tagName.toLowerCase();
567 if(tagName !== 'p' &&
568 tagName !== 'ul' &&
569 tagName !== 'h1' &&
570 tagName !== 'h2' &&
571 tagName !== 'h3' &&
572 tagName !== 'h4' &&
573 tagName !== 'h5' &&
574 tagName !== 'h6' &&
575 tagName !== 'table'){
576 continue;
577 }
578 }
579 var el = angular.element(dom[0].childNodes[i]);
580 var _listMatch = (el.attr('class') || '').match(/MsoList(Bullet|Number|Paragraph)(CxSp(First|Middle|Last)|)/i);
581
582 if(_listMatch){
583 if(el[0].childNodes.length < 2 || el[0].childNodes[1].childNodes.length < 1){
584 continue;
585 }
586 var isUl = _listMatch[1].toLowerCase() === 'bullet' || (_listMatch[1].toLowerCase() !== 'number' && !(/^[^0-9a-z<]*[0-9a-z]+[^0-9a-z<>]</i.test(el[0].childNodes[1].innerHTML) || /^[^0-9a-z<]*[0-9a-z]+[^0-9a-z<>]</i.test(el[0].childNodes[1].childNodes[0].innerHTML)));

Callers 1

taBind.jsFile · 0.85

Calls 3

_resetListFunction · 0.85
_unwrapElementFunction · 0.85
_compileHtmlFunction · 0.85

Tested by

no test coverage detected