Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program content component rich-text


May 18, 2021 WeChat Mini Program Development Document


Table of contents


rich-text

Base library 1.4.0 starts to support, and low versions need to be compatible

Rich text.

Property Type The default Description The lowest version
nodes Array / String [] List of nodes / HTML String 1.4.0

Supports default events, tap touchstart touchmove touchcancel touchend longtap

The nodes property recommends the Array type, which is reduced because the component converts the String type to the Array type


nodes

There are two types of nodes supported, distinguished by type, namely element nodes and text nodes, the default is element nodes, HTML nodes displayed in the rich text area

Element node: type s node

Property Description Type Required Note
name The label name String Is Supports partially trusted HTML nodes
attrs Property Object Whether Partially trusted properties are supported, following the Pascal nomenclat
children The list of child nodes Array Whether The structure is the same as the nodes

Text node: type s text

Property Description Type Required Note
text Text String Is Support for entity

Trusted HTML nodes and properties

Class and style properties are globally supported, and id properties are not supported.

Node Property
A
abbr
B
blockquote
Br
code
col span,width
colgroup span,width
Dd
Del
Div
Dl
Dt
Em
fieldset
h1
h2
h3
h4
h5
h6
hr
Img alt,src,height,width
Ins
label
legend
li
Ol start,type
P
Q
span
strong
sub
sup
table width
tbody
Td colspan,height,rowspan,width
tfoot
th colspan,height,rowspan,width
thead
Tr
Ul

Example:

<!-- rich-text.wxml -->
<rich-text nodes="{{nodes}}" bindtap="tap"></rich-text>
// rich-text.js
Page({
  data: {
    nodes: [{
      name: 'div',
      attrs: {
        class: 'div_class',
        style: 'line-height: 60px; color: red;'
      },
      children: [{
        type: 'text',
        text: 'Hello&nbsp;World!'
      }]
    }]
  },
  tap() {
    console.log('tap')
  }
})

Bug & Tip

  1. tip Nodes does not recommend the String type and performance decreases.
  2. tip Events that mask all nodes within the rich-text component.
  3. tip The attrs property does not support id, support class.
  4. tip Name property case is insensitive.
  5. tip If an untrusted HTML node is used, the node and all its children are removed.
  6. tip : The img tab only supports web images.