html转换

import org.apache.commons.lang.StringUtils;

 public static String convertToHtml(String content){
  content = StringUtils.replace(content,"/t","    ");//替换跳格
  content = StringUtils.replace(content," "," ");//替换空格
  content = StringUtils.replace(content,"/n","<br>");//替换换行
  return content;
 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
插件地址:https://github.com/kevenfeng/html-to-wxml如果前端技术比较牛,可以直接看github上面的demo。可以更好的理解用法。使用方法:1.引用插件var R_htmlToWxml = require(‘../../util/htmlToWxml.js’);//引入公共方法2.将html内容转成json数据R_htmlToWxml.html2json(“html内容”);转换后的json格式类型大概如下:3.吐到页面中显示<block wx:for="{{content}}"  wx:for-index="idy"  wx:for-item="cellData">         <block  wx:if="{{cellData.type == 'view'}}">             <view class="p">                 <block  wx:for="{{cellData.child}}" wx:key="text">                     <block  wx:if="{{item.type == 'a'}}">                         <text class="a" data-seccode="{{item.attr['data-seccode']}}" data-secname="{{item.attr['data-secname']}}" bindtap="stockClick">{{item.text}}</text>                     </block>                     <block  wx:else>                         <text>{{item.text}}</text>                     </block>                 </block>             </view>         </block>         <block wx:if="{{cellData.type == 'img'}}">             <image class="img" data-index="{{idy}}" style="height: {{cellData.attr.height?cellData.attr.height:0}}px"  mode="aspectFit" src="{{cellData.attr.src}}" bindload="imageLoad"></image>         </block>     </block>demo效果:由于小程序图片的高度没法自适应,需要给图片设置高度,所以需要在图片加载完以后,获取图片高度,等比算出显示图片高度,赋值给对应图片通常我们抓取的内容是html页面,特别是像资讯这一类的,如果在小程序里面显示文章内容,此插件提供了一种解决方案,希望对大家有用。在客户端中用native显示html页面体验上面没有native的好,htmlToWxml插件给客户端中用native的方式显示html内容提供了一种解决方案

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值