当前位置: 首页 > news >正文

保亭黎族苗族自治县网站建设_网站建设公司_测试上线_seo优化

网站的站点建设,辽宁建设厅查询网站,10元一年的虚拟主机,创建站点的方法文章目录 前言一、video的处理二、img的处理总结 前言 小程序中使用富文本编辑器#xff0c;由于rich-text受限 部分富文本内容无法渲染或排版错乱。以img和video为例#xff0c;处理起来让人头疼。网上各种长篇大论#xff0c;实际上没有任何帮助。接下来我们就一起聊聊im… 文章目录 前言一、video的处理二、img的处理总结 前言 小程序中使用富文本编辑器由于rich-text受限 部分富文本内容无法渲染或排版错乱。以img和video为例处理起来让人头疼。网上各种长篇大论实际上没有任何帮助。接下来我们就一起聊聊img和video。 一、video的处理 因为rich-text不识别video,所以小程序端无法渲染。网上看很多都是下载插件处理如果是一个单独视频 我个人觉得用正则匹配出来就行了如果是富文本里面还穿插其他内容可以试试插件。近期我们做的需求是把富文本里面的video拿出来单独渲染。 那么接下来我们就看看单独渲染如何处理吧。 此处是部分核心代码 并非完整案例代码 let htmlStr p测试题目解析的东西/p↵pvideo controlscontrols width300 height150↵source srchttps://scsf.oss-cn-shanghai.aliyuncs.com/tk/4d896a6e-f467-4a6d-bbc0-e30b5135db2f/bg.mp4 typevideo/mp4/video/p let videoList formatVideo(htmlStr ) const formatVideo (htmlStr ){if (!htmlStr ) return []let srcReg /(?(source[^]src))[^]*/glet videoList htmlStr.match(srcReg) || []return videoList }二、img的处理 说起img的处理 网上各种版本网上大部分都是直接暴力 设置max-width跟height auto;看到后只想吐槽一句‘兄弟你这是用到实战项目上吗’ 。 img处理 包含三种情况 第一种 不带style 例如 let htmlStr img src.... /第二种 带style不包含width 例如 let htmlStr img styletext-align:center src....第三种 带style并且有style 例如 let htmlStr img stylewidth:100px;height:30px; src.... /所以针对以上情况 分别进行处理就行。 第一步 判断是否包含style属性 let regExp new RegExp((i?)(img)(?!(.*?style[\](.*)[\])[^]), gmi)第二步 取出style属性值。 let srcReg /(?(img[^]style))[^]*/g第三步 判断是否包含width 完整代码 const formatRichTextInfo (str, width) {var regExp new RegExp((i?)(img)(?!(.*?style[\](.*)[\])[^]), gmi)let result if (regExp.test(str)) {result str.replace(/\img/gi, img stylemax-width:100%;height:auto;)} else {let srcReg /(?(img[^]style))[^]*/glet attributeList str.match(srcReg) || []if (attributeList attributeList .length) {if (attributeList [0].indexOf(width) ! -1) {result str.replace(/(img[^]*style[^]*?)(\bwidth\s*:\s*\d[^;]*?px;)(\s?height\s*:\s*\d[^;]*?px;)([^]*\/)/gi,function (match, p1, p2, p3, p4) {var widthValue parseInt(p2.match(/\d/)[0])// var heightValue parseInt(p3.match(/\d/)[0])if (widthValue width) {return p1 width: ${width}px; height: auto; p4}return match // 如果width小于等于375则不做替换保持原样})} else {result str.replace(/img[^]*/gi, function (match, capture) {match match.replace(/style[^]/gi, ).replace(/style[^]/gi, )return match})result result.replace(/\img/gi, img stylemax-width:100%;height:auto;)result result.replace(/\img/gi, img stylemax-width:100%;height:auto;)}} else {result str.replace(/img[^]*/gi, function (match, capture) {match match.replace(/style[^]/gi, ).replace(/style[^]/gi, )return match})//再设置新的样式result result.replace(/\img/gi, img stylemax-width:100%;height:auto;)result result.replace(/\img/gi, img stylemax-width:100%;height:auto;)}}return result }总结 不管是video还是img的处理 都是利用正则进行匹配。 img稍微麻烦一点 分为三种情况 没有style直接替换 有style则把style属性全部取出然后判断是否包含width属性 如果包含 则需要给一个最大值进行替换 如果不包含 则把style重置 然后再手动赋个最大值。
http://www.ihoyoo.com/news/132381.html

相关文章:

  • 怎么建网站 手机版建造师在建设部网站何时更新
  • 盘锦做网站哪家好温州做网站哪里好
  • 徐州网站优化推广网站首页 动画案例
  • 怎么创建网站?网站建设主要工作流程
  • 义乌建设局网站国家企业网官网查询
  • 搬瓦工如何搭建做网站辅导班培训机构
  • wordpress建站创业网站建设app开发合同
  • 亦庄公司做网站宁波网站优化建站公司
  • 便民网站开发如何制作网站后台
  • 做网页局域网站点配置办公室装修设计大概多少钱
  • vue做门户网站wordpress 4.3.18漏洞
  • 单页 网站模板手工制作粽子
  • 加强网站建设 基本措施什么是erp企业管理系统
  • 青岛建设局官方网站为成长持续赋能
  • sql网站源码公司网站可以做无形资产么
  • 兰州网站建设q479185700強网站数据库怎么做
  • 成都网站建设前十博物馆网站建设情况说明
  • 网站建设包含那些 内容网站建设与网页设计ppt
  • 企业门户网站的安全性怎么在word上做超链接网站
  • 邢台住房与城乡建设部网站青岛市建设监督管理局网站
  • php公司网站系统网站锚文本使用查询
  • fview网站开发海南住房建设厅定额网站
  • 广州网站开发公司友情链接平台广告
  • 挂号网站制作杭州高端响应式网站
  • 方案图网站阿里自助建站
  • 网站可以做哪些内容集团网站设计案例
  • 时网站建设公司管理wordpress分菜单
  • 临沂市经济开发区建设局网站win7不能运行wordpress
  • 湛江网站制作公司游戏开发平台
  • 深圳网站建设哪个公司号江门排名优化咨询