wxmlify
v1.2.0
一个轻量快速的插件,帮助你在微信小程序中显示富文本编辑器生成的HTML。
<rich-text>
富文本组件,但其兼容性暂时没有保证,你可能还是需要第三方解析工具。font-size
, font-weight
等// pages/index/index.js
var Wxmlify = require('../../wxmlify/wxmlify.js')
Page({
onLoad() {
// 以任何方式获得要解析的Html代码
var html = getHTMLStringSomehow()
// new 一个 wxmlify 实例就好了
var wxmlify = new Wxmlify(html, this, {})
}
})
<!-- pages/index/index.wxml -->
<import src="../../wxmlify/wxmlify.wxml" />
<template is="wxmlify" data="{{nodes: wxmlified}}"></template>
new Wxmlify(html, page [, options])
this
的指向string
'wxmlified'
new Wxmlify(html, this, {
dataKey: 'myRichText'
})
相应地在wxml中:
<template is="wxmlify" data="{{nodes: myRichText}}"></template>
'all'
, 表示保留所有样式false
, 0
, null
,表示移除所有自带样式['fontSize', 'fontWeight', 'background']
'all'
(默认保留所有样式)boolean
false
function
function() {}
.wxmlified-element {
/* 修改段落块的样式 */
}
.wxmlified-element.h1 {
/* 修改原<h1>标签块的样式,其它块级标签同理 */
}
.wxmlified-image {
/* 修改图片的样式 */
}
.wxmlified-text {
/* 修改文字节点的样式 */
}
.wxmlified-table.table {
/* table 的样式 */
border: 1rpx solid #acacac;
}
.wxmlified-table.tr {
/* tr 的样式 */
border-bottom: 1rpx solid #acacac;
}
.wxmlified-table.tr:last-child {
border-bottom:0;
}
.wxmlified-table.th, .wxmlified-table.td {
/* th,td 的样式 */
border-right: 1rpx solid #acacac;
line-height: 2;
}
.wxmlified-table.th:last-child, .wxmlified-table.td:last-child {
border-right: none;
}
.wxmlified-table.th {
font-weight: bold;
}
? This little tool is made possible thanks to an open source HTML-to-JSON parser himalaya made by Chris Andrejewski.