{"id":1254,"date":"2020-09-19T11:44:08","date_gmt":"2020-09-19T03:44:08","guid":{"rendered":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=1254"},"modified":"2020-09-19T11:49:29","modified_gmt":"2020-09-19T03:49:29","slug":"%e5%af%8c%e6%96%87%e6%9c%ac%e9%80%82%e5%ba%94%e6%89%8b%e6%9c%ba%e7%ab%af%e7%9a%84%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=1254","title":{"rendered":"\u5bcc\u6587\u672c\u9002\u5e94\u624b\u673a\u7aef\u7684\u5904\u7406"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">\/**\n* \u5904\u7406\u5bcc\u6587\u672c\u91cc\u7684\u56fe\u7247\u5bbd\u5ea6\u81ea\u9002\u5e94\n* 1.\u53bb\u6389img\u6807\u7b7e\u91cc\u7684style\u3001width\u3001height\u5c5e\u6027\n* 2.img\u6807\u7b7e\u6dfb\u52a0style\u5c5e\u6027\uff1amax-width:100%;height:auto\n* 3.\u4fee\u6539\u6240\u6709style\u91cc\u7684width\u5c5e\u6027\u4e3amax-width:100%\n* 4.\u53bb\u6389&lt;br\/>\u6807\u7b7e\n* @param html\n* @returns {void|string|*}\n*\/\nformatRichText (html) { \/\/\u63a7\u5236\u5c0f\u7a0b\u5e8f\u4e2d\u56fe\u7247\u5927\u5c0f\nlet newContent= html.replace(\/&lt;img[^>]*>\/gi,function(match,capture){\nmatch = match.replace(\/style=\"[^\"]+\"\/gi, '').replace(\/style='[^']+'\/gi, '');\nmatch = match.replace(\/width=\"[^\"]+\"\/gi, '').replace(\/width='[^']+'\/gi, '');\nmatch = match.replace(\/height=\"[^\"]+\"\/gi, '').replace(\/height='[^']+'\/gi, '');\nreturn match;\n});\nnewContent = newContent.replace(\/style=\"[^\"]+\"\/gi,function(match,capture){\nmatch = match.replace(\/width:[^;]+;\/gi, 'max-width:100%;').replace(\/width:[^;]+;\/gi, 'max-width:100%;');\nreturn match;\n});\nnewContent = newContent.replace(\/&lt;br[^>]*\\\/>\/gi, '');\nnewContent = newContent.replace(\/\\&lt;img\/gi, '&lt;img style=\"max-width:100%;height:auto;display:inline-block;margin:10rpx auto;\"');\nreturn newContent;\n}\n\n\u53c2\u8003:<a href=\"https:\/\/blog.csdn.net\/qq_37682202\/article\/details\/100522172\">https:\/\/blog.csdn.net\/qq_37682202\/article\/details\/100522172<\/a>\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/** * \u5904\u7406\u5bcc\u6587\u672c\u91cc\u7684\u56fe\u7247\u5bbd\u5ea6\u81ea\u9002\u5e94 * 1.\u53bb\u6389img\u6807\u7b7e\u91cc\u7684style\u3001width\u3001height\u5c5e\u6027  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[73,71],"_links":{"self":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1254"}],"collection":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1254"}],"version-history":[{"count":3,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1254\/revisions"}],"predecessor-version":[{"id":1257,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1254\/revisions\/1257"}],"wp:attachment":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}