From 35bf8ef2d9b8d4d6f69f149e9d4c585e1da53370 Mon Sep 17 00:00:00 2001 From: yige Date: Mon, 5 Aug 2019 16:24:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9font=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 16 +- test/removeTagsHoldContent.html | 762 ++++++++++++++++++++++++++++++++ 2 files changed, 777 insertions(+), 1 deletion(-) create mode 100644 test/removeTagsHoldContent.html diff --git a/src/App.js b/src/App.js index b8f87dc..a134dda 100755 --- a/src/App.js +++ b/src/App.js @@ -23,6 +23,15 @@ function removeTags(tagName, el = document){ } } +// 移除指定标签但保留标签内容 +function removeTagsHoldContent(tagName, el = document) { + var tagElements = el.getElementsByTagName(tagName) + for (var m = tagElements.length - 1; m >= 0; m--) { + tagElements[m].parentNode.innerHTML = tagElements[m].parentNode.innerHTML.replace(tagElements[m].outerHTML, + tagElements[m].innerText.trim()) + } +} + // 移除所有CSS function removeAllCSS (el = document) { el.querySelectorAll('link').forEach(linkEl => linkEl.rel === 'stylesheet' && linkEl.remove()); @@ -35,6 +44,7 @@ function removeAllCSS (el = document) { node.removeAttribute('cellpadding') node.removeAttribute('cellspacing') node.removeAttribute('class') + node.removeAttribute('lang') } return node.removeAttribute && node.removeAttribute('style'); })(el.body); @@ -342,9 +352,13 @@ class App extends Component { // 移除多余标签 removeTags('col', p) + removeTags('o:p', p) removeTags('colgroup', p) - if (this.state.removeAllCSS) removeAllCSS(p) + if (this.state.removeAllCSS) { + removeAllCSS(p) + removeTagsHoldContent('font', p) + } if (this.state.removeTableWidth) removeTableWidth(p) // 转百分数 diff --git a/test/removeTagsHoldContent.html b/test/removeTagsHoldContent.html new file mode 100644 index 0000000..a38367c --- /dev/null +++ b/test/removeTagsHoldContent.html @@ -0,0 +1,762 @@ + + + + + + + + Document + + + + + + + + + + \ No newline at end of file