当前位置:网站首页>富文本样式文字图片处理
富文本样式文字图片处理
2022-07-25 08:45:00 【Moran墨染】
export default const clearStyle = (input) => {
var stringStripper = /(\n|\r| class=(")?Mso[a-zA-Z]+(")? ^p)/g;
var output = input.replace(stringStripper, ' ');
// 2. strip Word generated HTML comments
var commentSripper = new RegExp('<!--(.*?)-->','g');
var output = output.replace(commentSripper, '');
// 3. remove tags leave content if any
var tagStripper = new RegExp('<(/)*(meta|link|span|\\?xml:|st1:|o:|font)(.*?)>','gi');
output = output.replace(tagStripper, '');
// 4. Remove everything in between and including tags '<style(.)style(.)>'
var badTags = ['style', 'script','applet','embed','noframes','noscript'];
for (var i=0; i< badTags.length; i++) {
tagStripper = new RegExp('<'+badTags[i]+'.*?'+badTags[i]+'(.*?)>', 'gi');
output = output.replace(tagStripper, '');
}
// 5. remove attributes ' style="..."'
var badAttributes = ['style', 'start'];
for (var i=0; i< badAttributes.length; i++) {
var attributeStripper = new RegExp(' ' + badAttributes[i] + '="(.*?)"','gi');
output = output.replace(attributeStripper, '');
}
output = output.replace(/<\/?html.*?>/ig,'')
output = output.replace(/<\/?body.*?>/ig,'')
output = output.replace(/<\/?title.*?>/ig,'')
output = output.replace(/<\/?head.*?>/ig,'')
output = output.replace(/<\/?b>/ig,'')
output = output.replace(/<\/?i.*?>/ig,'')
output = output.replace(/[\s]+class=MsoNormal/ig,'')
output = output.replace(/&#[0-9]+;/ig,'')
output = output.replace(/ /ig,'')
output = output.replace(/<p\s+><\/p>/ig,'')
// output = output.replace(/<a .*?>/ig,'')
output = output.replace(/<\/a.*?>/ig,'')
output = output.replace(/<\/?u>/ig,'')
output = output.replace(/<\/pre>/ig,'')
output = output.replace(/<\/?divcourier.*?>?/ig,'')
return output;
}
边栏推荐
猜你喜欢

Wechat reservation of small program completion works (5) assignment book of small program graduation project

Redis best practices

PHP reports an error: classes\phpexcel\cell php Line(594) Invalid cell coordinate ESIGN1

How to do the game plug-in?

阿里云服务的网络解决方案

R language error

递归调用实现打印一个整数的每一位
![[Sesame Street family] & Bert Bart Roberta](/img/ff/c685065cd413bd4cffd996fd9afeaa.png)
[Sesame Street family] & Bert Bart Roberta

Phpexcel reports an error: err_ INVALID_ RESPONSE

51单片机内部外设:定时器和计数器
随机推荐
OpenGL es to realize the visualization of real-time audio
本周大新闻|FCC曝光Pico 4 VR一体机,雷朋母公司建立智能眼镜实验室
How can hospitals achieve efficient and low-cost operation and maintenance? Is there any software that can meet it?
@The difference and use of value and configurationproperties
Wechat sports field reservation of the finished works of the applet graduation project (4) opening report
Intelligent operation and maintenance scenario analysis: how to detect abnormal business system status through exception detection
Chapter 3 business function development (modifying clues, data echo and modifying data)
R language error
ip命令使用详解
Wechat Reservation Reservation of applet completion works applet graduation project (8) graduation project thesis template
Sun Tzu's art of war
Wechat reservation of small program completion works (5) assignment book of small program graduation project
C # introductory series (30) -- exception handling
Phpexcel reports an error: err_ INVALID_ RESPONSE
Redis best practices
华为设备远程登录(Telnet、SSH)配置
【黑马程序员】Redis学习笔记001:Redis简介+五种基本数据类型
Huawei device remote login (Telnet, SSH) configuration
[dark horse programmer] redis learning notes 005: enterprise level solutions
Graduation project of wechat small program ordering system of small program completion works (4) opening report