当前位置:网站首页>去除富文本标签样式

去除富文本标签样式

2022-08-10 17:39:00 凡小多

可以通过正则匹配式,去除简单的富文本的标签样式,返回纯内容格式

// 去除富文本标签样式
const removeHtmlStyle = (html) => {
    
  const relStyle = /style\s*?=\s*?(['"])[\s\S]*?\1/g
  const relTag = /<.+?>/g
  const relClass = /class\s*?=\s*?(['"])[\s\S]*?\1/g
  let newHtml = ''
  if (html) {
    
    newHtml = html.replace(relStyle, '')
    newHtml = newHtml.replace(relTag, '')
    newHtml = newHtml.replace(relClass, '')
  }
  return newHtml
}
原网站

版权声明
本文为[凡小多]所创,转载请带上原文链接,感谢
https://blog.csdn.net/wgh4318/article/details/126221526