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

WeChat small program form component editor


May 18, 2021 WeChat Mini Program Development Document


Table of contents


editor

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

Rich text editor, you can edit pictures and text.

Editor export content supports tagged html and plain text, and is stored internally in delta format.

When setting up content through the setContents interface, parsing inserted html may result in parsing errors due to some illegal tags, and developers are advised to insert it via delta when used in small programs.

Some basic styles have been introduced within the rich text component to allow the content to be displayed correctly and overwritten during development. It is important to note that when using html exported by rich text components in other components or environments, this style needs to be introduced additionally and the structure of the ql-container-gt;?ltl-editor>/ql-editor-gt;/ql-container-gt;

The picture control is set only when initialized.

Related api: EditorContext

Property Type The default Required Description The lowest version
read-only boolean false Whether Set the editor to read-only 2.7.0
placeholder string Whether Tips 2.7.0
show-img-size boolean false Whether Show picture size controls when you tap a picture 2.7.0
show-img-toolbar boolean false Whether Displays toolbar controls when you click on a picture 2.7.0
show-img-resize boolean false Whether The modified dimension control is displayed when the picture is clicked 2.7.0
bindready eventhandle no Trigger when the editor is initialized 2.7.0
bindfocus eventhandle no Trigger when the editor focuses, Event.detail = {HTML, Text, Delta} 2.7.0
bindblur eventhandle no Trigger when the editor loses focus, detail = {html, text, delta} 2.7.0
bindinput eventhandle no Trigger when the editor changes, detail = {html, text, delta} 2.7.0
bindstatuschange eventhandle no Trigger when changing the pattern in the editor by the Context method, return to the style set 2.7.0

The editor supports some HTML tags and inline style, and Class and ID are not supported.

Supported label

不满足的标签会被忽略,<div>会被转行为<p>储存。

type node
In-line elements <span> <strong> <b> <ins> <em> <i> <u> <a> <del> <s> <sub> <sup> <img>
Block element element <p> <h1> <h2> <h3> <h4> <h5> <h6> <hr> <ol> <ul> <li>

Supported inline style

The inline pattern can only be set on the line elements or block elements, and cannot be set at the same time.For example, Font-size is classified as within the line element properties, setting is invalid on the P tag.

type style
Block-level style text-align direction margin margin-top margin-left margin-right margin-bottom
padding padding-top padding-left padding-right padding-bottom line-height text-indent
In-line style font font-size font-style font-variant font-weight font-family
letter-spacing text-decoration color background-color

Tips:

  1. Binding events with catchtouchend does not cause the editor to lose focus (2.8.3)
  2. Event bindings are removed in the inserted html
  3. The color property in formats is returned uniformly in hex format
  4. Only plain text content is copied into the editor when pasted
  5. When you insert html into the editor, the editor removes unnecessary labels to ensure that the content is unified. For example, it will be rewritten to the example of lt;p>;span>xxx;/span<p;p;lt;p;xx;lt;p
  6. When the editor focuses, the page is pushed up and the system acts to ensure that the edit area is visible