MCPcopy Index your code
hub / github.com/TruthHun/BookStack / getResult

Function getResult

static/wangEditor/js/wangEditor.js:2510–2566  ·  view source on GitHub ↗
(elem)

Source from the content-addressed store, hash-verified

2508
2509 // 获取元素的结果
2510 function getResult(elem) {
2511 var nodeName = elem.nodeName.toLowerCase();
2512 var $elem;
2513 var htmlForP = '';
2514 var htmlForLi = '';
2515
2516 if (['blockquote'].indexOf(nodeName) >= 0) {
2517
2518 // 直接取出元素text即可
2519 $elem = $(elem);
2520 return '<' + nodeName + '>' + $elem.text() + '</' + nodeName + '>';
2521
2522 } else if (['p', 'h1', 'h2', 'h3', 'h4', 'h5'].indexOf(nodeName) >= 0) {
2523
2524 //p head 取出 text 和链接
2525 elem = removeAttrs(elem);
2526 $elem = $(elem);
2527 htmlForP = $elem.html();
2528
2529 // 剔除 a img 之外的元素
2530 htmlForP = htmlForP.replace(/<.*?>/ig, function (tag) {
2531 if (tag === '</a>' || tag.indexOf('<a ') === 0 || tag.indexOf('<img ') === 0) {
2532 return tag;
2533 } else {
2534 return '';
2535 }
2536 });
2537
2538 return '<' + nodeName + '>' + htmlForP + '</' + nodeName + '>';
2539
2540 } else if (['ul', 'ol'].indexOf(nodeName) >= 0) {
2541
2542 // ul ol元素,获取子元素(li元素)的text link img,再拼接
2543 $elem = $(elem);
2544 $elem.children().each(function () {
2545 var $li = $(removeAttrs(this));
2546 var html = $li.html();
2547
2548 html = html.replace(/<.*?>/ig, function (tag) {
2549 if (tag === '</a>' || tag.indexOf('<a ') === 0 || tag.indexOf('<img ') === 0) {
2550 return tag;
2551 } else {
2552 return '';
2553 }
2554 });
2555
2556 htmlForLi += '<li>' + html + '</li>';
2557 });
2558 return '<' + nodeName + '>' + htmlForLi + '</' + nodeName + '>';
2559
2560 } else {
2561
2562 // 其他元素,移除元素属性
2563 $elem = $(removeAttrs(elem));
2564 return $('<div>').append($elem).html();
2565 }
2566 }
2567

Callers 1

handleFunction · 0.85

Calls 3

removeAttrsFunction · 0.85
textMethod · 0.80
$Function · 0.50

Tested by

no test coverage detected