SOURCE

var content = "<p>富文本1-1富文本1-1富文本1-1富文本1-1富文本1-1富文本1-1<img src=\"/adc-static/imagemgt/images/2016/CollaborationpPlatform_DigitalDevelopment/project_web/$system/43f2a7b8-608b-4b4b-a8f7-4afedff99a78.jpg\" alt width=\"100\" height=\"59\"></p>\n<p><img src=\"/adc-static/imagemgt/images/2016/CollaborationpPlatform_DigitalDevelopment/project_web/$system/61ce9a82-ea24-47b2-95aa-1361d628db2a.jpg\" alt width=\"200\" height=\"145\">富文本1-1富文本1-1富文本1-1富文本1-1富文本1-1富文本1-1</p>\n<p><img src=\"/adc-static/imagemgt/images/2016/CollaborationpPlatform_DigitalDevelopment/project_web/$system/a51ca5d8-a9d4-4931-898f-b22cc96e0840.jpg\" alt width=\"300\" height=\"180\"></p>";
var content1 = "<p>随着NSA和SA 组网标准在2017年年底及2018年中的冻结,5G的网络规划建设的序幕逐渐拉开。5G网络,凭借其强大、开放、灵活的网络能力,将给全社会的发展提供有力的支撑,对网络运营商也将带来更广阔的业务空间。<br>在准备5G的同时,我们意识到新技术的应用、新网络的运维、新业务的开发、新商业模式的创新,也将是运营商面临的巨大挑战。要应对这些挑战,观念的转变、运维能力的更新升级,商业运营能力的转型发展,都需要提前构筑和准备。</p><p><img src=\"/adc-static/imagemgt/images/2014/CollaborationpPlatform_DigitalDevelopment/Images/2020/376eeb8a54cf4f5c913fc055f9f51857.png\" style=\"max-width: 100%;\">&nbsp;&nbsp;</p><p>随着5G业务的发展,运营商的业务从原来的ToC业务开始向ToB ToC演进,而ToB业务相比ToC业务,<span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt;\">与场景结合更紧密,更关注用户</span><span lang=\"EN-US\" style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt;\">SLA</span><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt;\">如何保障,如何实现</span><span lang=\"EN-US\" style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt;\">2B</span><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt;\">业务的可管、可视、可控。为了更好地支撑5G ToB业务的开展,我们认为,运营商人员需要构筑以下三方面的能力:第一,</span><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt;\">面向</span><span lang=\"EN-US\" style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt;\">5G</span><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt;\">各个网络子域的规建维优能力;</span><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt; text-indent: 22pt;\">第二,面向典型应用的设计、开通与运维能力;</span><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt;\">第三,是面向垂直行业场景的设计、开通与运维能力。</span></p><p><img src=\"/adc-static/imagemgt/images/2014/CollaborationpPlatform_DigitalDevelopment/Images/2020/92bddfaab1684f0f978a89aabc652898.png\" style=\"max-width:100%;\"><span style=\"color: rgb(51, 51, 51); font-family: 微软雅黑, sans-serif; font-size: 11pt;\"><br></span></p>\n<!--[if gte mso 9]><![endif]-->\n\n\n<!--[if gte mso 9]><![endif]--><!--[if gte mso 9]><![endif]-->\n\n<!--[if gte mso 10]>\n\n<![endif]-->\n\n\n\n\n\n<p style=\"margin: 0cm 0cm 0.0001pt; text-indent: 22pt; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;\"><span style=\"font-size:11.0pt;\nmso-bidi-font-size:12.0pt;font-family:&quot;微软雅黑&quot;,sans-serif;color:#333333\"><span lang=\"EN-US\"><o:p></o:p></span></span></p>\n<!--[if gte mso 9]><![endif]-->\n\n\n<!--[if gte mso 9]><![endif]--><!--[if gte mso 9]><![endif]-->\n\n<!--[if gte mso 10]>\n\n<![endif]-->\n\n\n\n\n<!--[if gte mso 9]><![endif]-->\n\n\n<!--[if gte mso 9]><![endif]--><!--[if gte mso 9]><![endif]-->\n\n<!--[if gte mso 10]>\n\n<![endif]-->\n\n\n\n\n\n<p style=\"margin: 0cm 0cm 0.0001pt; text-indent: 22pt; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;\"><span style=\"font-size:11.0pt;\nmso-bidi-font-size:12.0pt;font-family:&quot;微软雅黑&quot;,sans-serif;color:#333333\"><span lang=\"EN-US\"><o:p></o:p></span></span></p>\n<!--[if gte mso 9]><![endif]-->\n\n\n<!--[if gte mso 9]><![endif]--><!--[if gte mso 9]><![endif]-->\n\n<!--[if gte mso 10]>\n\n<![endif]-->\n\n\n\n\n<!--[if gte mso 9]><![endif]-->\n\n\n<!--[if gte mso 9]><![endif]--><!--[if gte mso 9]><![endif]-->\n\n<!--[if gte mso 10]>\n\n<![endif]-->\n\n\n\n"
var img_url_list = []
var list = subsection(content1);
console.debug(list)



// 分段
function subsection(data) {
    var arr = new Array();
    var new_arr = [];
    if (data != undefined && data != '') {
        data = data.replace(new RegExp('</p>', 'g'), '######');
        data = data.replace(new RegExp('<br>', 'g'), '######');
        data = data.replace(new RegExp('<img', 'g'), '######<img');
        // data = data.replace(new RegExp('\">', 'g'), '\">#'); // 分段
        if (data != undefined) {
            let arr = data.split('######');
            if (arr[arr.length - 1] == '') {
                arr = arr.slice(0, arr.length - 1)
            }
            if(arr.length > 0){
                arr.forEach(function(item){
                    console.debug(item)
                    if(item.match(/<img[^>]+src=['"]([^'"]+)['"][^>]*>/)){
                        var obj = {"img":getImgUrl(item)}
                        new_arr.push(obj);
                    } else {
                        var obj = {"content":getContent(item)};
                        new_arr.push(obj);
                    }
                })
            }
            return new_arr;
        }
    }
    return new_arr;
}


// 去除标签
function getContent(data) {
    if (data != undefined && data != '') {
        //去除html标签正则
        if (data != undefined) {
            data = data.replace(/<\/?[^>]*>/g, "");
        }
        data = unescapeHtml(data);
    }
    return data;
}

// 获取img
function getImgUrl(data) {
    // 匹配所有的img标签
    const patt = /<img[^>]+src=['"]([^'"]+)['"][^>]*>/g;
    const result = new Array();
    var temp = patt.exec(data)
    while (temp != null) {
        // 声明图片的url
        let imgUrl = JSON.parse(JSON.stringify(temp[1])) || "";
        // 声明图片的宽度
        let imgWidth = "";
        // 声明图片的高度
        let imgHeight = "";
        // 匹配到的单个img标签,包含标签内所有属性
        if (temp[0]) {
            // 匹配img标签的宽度属性
            let width_match = temp[0].match(/width=['"]([^'"]+)['"]/);
            imgWidth = width_match && width_match[1] || "";
            // 匹配img标签的高度属性
            let height_match = temp[0].match(/height=['"]([^'"]+)['"]/);
            imgHeight = height_match && height_match[1] || "";
        }
        if (imgUrl && imgUrl.substring(0, 1) == '/') {
            img_url_list.push(imgUrl);
            let arr = imgUrl.split("/");
            if (imgWidth && imgHeight) {
                // 当前图片的宽高比
                let aspect_ratio = imgWidth / imgHeight;
                // 设置word跟实际图片尺寸比例为3/4,word最大宽度为450
                let temp_width = Math.min(imgWidth * 0.75, 450);
                result.push({
                    img_name: arr[arr.length - 1],
                    width: temp_width,
                    height: temp_width / aspect_ratio
                });
            } else {
                result.push({
                    img_name: arr[arr.length - 1],
                    width: 450
                });
            }
        }
        temp = patt.exec(data)
    }
    return result;
}

function unescapeHtml(str) {
    if (!str || str == undefined) {
        return;
    }

    var results = str;
    results = results.replace(/&quot;/g, '"');
    results = results.replace(/&apos;/g, "'");
    results = results.replace(/&lt;/g, "<");
    results = results.replace(/&gt;/g, ">");
    results = results.replace(/&nbsp;/g, " ");
    results = results.replace(/&amp;/g, "&");
    results = results.replace(/&mdash;/g, "—");
    results = results.replace(/&middot;/g, "·");
    results = results.replace(/&hellip;/g, "…");
    results = results.replace(/&mdash;/g, "—");
    results = results.replace(/&ldquo;/g, "“").replace(/&rdquo;/g, "”");
    results = results.replace(/&lsquo;/g, "‘").replace(/&rsquo;/g, "’");
    results = results.replace(/&pound;/g, "£");
    results = results.replace(/&curren;/g, "¤");
    return results;
}
console 命令行工具 X clear

                    
>
console