首页前端开发HTMLuni vue 替换接口 v-html的图片

uni vue 替换接口 v-html的图片

时间2023-07-07 13:20:02发布访客分类HTML浏览962
导读:formatRichText (html { let newContent= html.replace(/<img[^>]*>/gi,function(match,capture { match...
formatRichText (html) {
     
    let newContent= html.replace(/img[^>
    ]*>
/gi,function(match,capture){
    
        match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
    
        match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
    
        match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
    
        return match;

    }
    );

    newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){
    
        match = match.replace(/width:[^;
    ]+;
    /gi, 'max-width:100%;
    ').replace(/width:[^;
    ]+;
    /gi, 'max-width:100%;
    ');
    
        return match;

    }
    );
    
    newContent = newContent.replace(/br[^>
    ]*\/>
    /gi, '');
    
    newContent = newContent.replace(/\img/gi, 'img style="max-width:100%;
    height:auto;
    display:inline-block;
    margin:10rpx auto;
    "');
    
    return newContent;

}
    

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

JavaScript

若转载请注明出处: uni vue 替换接口 v-html的图片
本文地址: https://pptw.com/jishu/294144.html
Java实现多用户即时通信系统 PHP 过滤html和img

游客 回复需填写必要信息