rich-text
富文本。
属性 |
类型 |
默认值 |
必填 |
说明 |
最低版本 |
space |
String |
|
否 |
显示连续空格 |
|
nodes |
Array/String |
[] |
否 |
节点列表/HTML String |
|
space 的合法值
值 |
说明 |
最低版本 |
ensp |
中文字符空格一半大小 |
|
emsp |
中文字符空格大小 |
|
nbsp |
根据字体设置的空格大小 |
|
nodes
现支持两种节点,通过type来区分,分别是元素节点和文本节点,默认是元素节点,在富文本区域里显示的HTML节点
元素节点:type = node
属性 |
类型 |
必填 |
说明 |
最低版本 |
name |
String |
是 |
标签名, 支持绝大部分部分 HTML 节点 |
|
attrs |
Object |
否 |
节点属性, 遵循 Pascal 命名法 |
|
children |
Array |
否 |
子节点列表,结构和 nodes 一致 |
|
文本节点:type = text
属性 |
类型 |
必填 |
说明 |
最低版本 |
text |
文本 |
String |
是 |
|
受信任的HTML节点及属性
全局支持class和style属性
注意:不支持id属性,节点详细说明查看 HTML 元素参考。
节点 |
属性 |
最低版本 |
address |
|
|
article |
|
|
aside |
|
|
footer |
|
|
header |
|
|
main |
|
|
nav |
|
|
section |
|
|
h1 |
|
|
h2 |
|
|
h3 |
|
|
h4 |
|
|
h5 |
|
|
h6 |
|
|
blockquote |
|
|
dd |
|
|
div |
|
|
dl |
|
|
dt |
|
|
figcaption |
|
|
figure |
|
|
hr |
|
|
li |
|
|
ol |
reversed, start, type |
|
p |
|
|
pre |
|
|
ul |
|
|
a |
|
|
abbr |
|
|
b |
|
|
bdi |
dir |
|
bdo |
dir |
|
br |
|
|
cite |
|
|
code |
|
|
data |
value |
|
dfn |
|
|
em |
|
|
i |
|
|
kbd |
|
|
mark |
|
|
q |
|
|
rb |
|
|
rp |
|
|
rt |
|
|
rtc |
|
|
ruby |
|
|
s |
|
|
samp |
|
|
small |
|
|
span |
|
|
strong |
|
|
sub |
|
|
sup |
|
|
time |
datetime, pubdate |
|
u |
|
|
var |
|
|
wbr |
|
|
img |
src, alt, width, height |
|
audio |
src, autoplay, controls, currentTime, loop, muted, preload, controlslist |
|
video |
src, autoplay, controls, currentTime, loop, muted, preload, controlslist, poster, webkit-playsinline, playsinline, width, height |
|
track |
src, default, kind, label, srclang |
|
iframe |
width, height, src, frameborder, marginheight, marginwidth, sandbox, scrolling, seamless |
|
object |
codebase, data, type, width, height |
|
picture |
|
|
source |
src, type, srcset, media |
|
del |
|
|
ins |
|
|
caption |
|
|
col |
span, width |
|
colgroup |
span, width |
|
table |
width, border, cellpadding, cellspacing |
|
tbody |
rowspan, colspan, width, height |
|
tfoot |
rowspan, colspan, width, height |
|
thead |
rowspan, colspan, width, height |
|
label |
|
|
fieldset |
|
|
legend |
|
|
progress |
max, value |
|
meter |
min, max, low, high, optimum, value |
|
details |
open |
|
summary |
|
|
font |
color, face, size |
|
big |
|
|
示例代码:
<view class="container">
<view class="statement">富文本。</view>
<view class="cssname">nodes:array, space:nbsp</view>
<view>
<rich-text nodes="{{nodes_array}}" space="nbsp"></rich-text>
</view>
<view class="cssname">nodes:string, space:emsp</view>
<view>
<rich-text nodes="{{nodes_html}}" space="emsp">abc</rich-text>
</view>
</view>
// pages/component/pages/rich-text/rich-text.js
Page({
data: {
nodes_html: '<div style="background-color:#eee">HTML 元素参考</div><table style="width:100%"><colgroup><col width="90px"></col><col></col></colgroup><thead><tr><th>元素</th><th>示例</th></tr></thead><tbody><tr><td colspan="2" class="classify">内容分区</td></tr><tr><td><address><br/><article><br/><aside><br/><footer><br/><header><br/><h1><br/><h2><br/><h3><br/><h4><br/><h5><br/><h6><br/><main><br/><nav><br/><section><br/></td><td><article><header><h1>Choosing an Apple</h1></header><nav><ol><li><a href="#">Introduction</a></li><li>Criteria</li></ol></nav><main><p>Choosing an Apple</p></main><section><h2>Introduction</h2><aside><p>This document provides a guide to help with the important task of choosing the correct Apple.</p></aside></section><section><h2>Criteria</h2><aside><p>There are many different criteria to be considered when choosing an Apple — size, color, firmness, sweetness, tartness...</p></aside></section><footer><p><address><a href="mailto:example@example">example@example.com</a></address></p><p>© 2020 Gandalf</p></footer></article></td></tr><tr><td colspan="2" class="classify">文本内容</td></tr><tr><td><blockquote><br/><dd><br/><div><br/><dl><br/><dt><br/><figcaption><br/><figure><br/><hr><br/><li><br/><ol><br/><p><br/><pre><br/><ul><br/></td><td><ul><li>first item</li><li>second item</li><li>third item</li></ul><hr><p>§1: The first rule of Fight Club is: You do not talk about Fight Club.</p><hr><p>§2: The second rule of Fight Club is: Always bring cupcakes.</p><hr><figure><blockquote cite="https://www.huxley.net/bnw/four.html"><div><p>Words can be like X-rays, if you use them properly—they’ll go through anything. You read and you’re pierced.</p></div></blockquote><figcaption>—Aldous Huxley, <cite>Brave New World</cite></figcaption></figure><hr><dl><dt>Firefox</dt><dd>A free, open source, cross-platform, graphical web browserdeveloped by the Mozilla Corporation and hundreds of volunteers.</dd></dl><hr><pre><pre></pre></td></tr><tr><td colspan="2" class="classify">内联文本语义</td></tr><tr><td><a><br/><abbr><br/><b><br/><bdi><br/><bdo><br/><br><br/><cite><br/><code><br/><data><br/><dfn><br/><i><br/><kbd><br/><mark><br/><q><br/><rb><br/><rp><br/><rt><br/><rtc><br/><ruby><br/><s><br/><samp><br/><small><br/><span><br/><strong><br/><sub><br/><sup><br/><time><br/><u><br/><var><br/><wbr><br/></td><td><a href="https://www.morecross.cn">morecross.cn</a><hr><p>You can use <b>CSS</b> to style your <abbr title="HyperText Markup Language">HTML</abbr>.</p><hr><ul><li><bdi class="name">Evil Steven</bdi>: 1st place</li><li><bdi class="name">François fatale</bdi>: 2nd place</li><li><span class="name">تیز سمی</span>: 3rd place</li><li><bdi class="name">الرجل القوي إيان</bdi>: 4th place</li><li><span class="name" dir="auto">تیز سمی</span>: 5th place</li></ul><p>In the computer\'s memory, <br> this is stored as <bdo dir="ltr">אה, אני אוהב להיות ליד חוף הים</bdo></p><hr><p>Regular text. <code>This is code.</code> Regular text.</p><hr><p>New Products:</p><ul><li><data value="398">Mini Ketchup</data></li><li><data value="399">Jumbo Ketchup</data></li><li><data value="400">Mega Jumbo Ketchup</data></li></ul><hr><p><i>In HTML 5, what was previously called</i><em>block-level</em> content is now called <em>flow</em> content.</p><hr><p><mark>Save</mark> the document by pressing <kbd>Ctrl</kbd> + <kbd>S</kbd></p><hr><p>Everytime Kenny is killed, Stan will announce<q cite="http://en.wikipedia.org/wiki/Kenny_McCormick#Cultural_impact">Oh my God, you/they killed Kenny!</q>.</p><hr><ruby><rb>漢</rb>字<rp>(</rp><rt>han</rt>zi<rp>)</rp><rtc>San Francisco</rtc></ruby><hr><s>Today\'s Special: Salmon</s> SOLD OUT<br><hr><p>Regular text. <samp>This is sample text.</samp> Regular text.</p><hr><p><small>The content is licensed under a Creative Commons Attribution-ShareAlike 2.5 Generic License.</small></p><p>When doing x it is <strong>imperative</strong> to do y before proceeding.</p><hr><p>The chemical formula of water: H<sub>2</sub>O</p><p>This text is <sup>superscripted</sup></p><hr><p>The concert took place on <time datetime="2001-05-15 19:00">May 15</time>.</p><hr><p>You could use this element to highlight <u>speling</u> mistakes, so the writer can <u>corect</u> them.</p><hr><p> A simple equation: <var>x</var> = <var>y</var> + 2 </p><hr><p>https://www<wbr>.morecross<wbr>.cn<wbr>/home</p></td></tr><tr><td colspan="2" class="classify">图片和多媒体</td></tr><tr><td><audio><br/><img><br/><track><br/><video><br/></td><td><img class="fit-picture" width="100%" src="https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg" alt="Grapefruit slice atop a pile of other slices"><hr><audio style="width:100%" controls src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3">Your browser does not support the<code>audio</code> element.</audio><hr><video controls playsinline webkit-playsinline width="100%"><source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm" type="video/webm"><source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4" type="video/mp4">Sorry, your browser doesn\'t support embedded videos.</video></td></tr><tr><td colspan="2" class="classify">内嵌内容</td></tr><tr><td><iframe><br/><object><br/><picture><br/><source><br/></td><td><iframe id="inlineFrameExample" title="Inline Frame Example" width="100%" height="200" src="https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg"></iframe><hr><object type="application/pdf" data="https://interactive-examples.mdn.mozilla.net/media/examples/In-CC0.pdf" width="200" height="200"></object><hr><picture><source srcset="https://interactive-examples.mdn.mozilla.net/media/cc0-images/surfer-240-200.jpg" media="(min-width: 80px)"><img src="https://interactive-examples.mdn.mozilla.net/media/cc0-images/painted-hand-298-332.jpg" alt="" /></picture><hr></td></tr><tr><td colspan="2" class="classify">编辑标识</td></tr><tr><td><del><br/><ins><br/></td><td><p>“You\'re late!”</p><del><p>“I apologize for the delay.”</p></del><ins cite="../howtobeawizard.html" datetime="2018-05"><p>“A wizard is never late …”</p></ins></td></tr><tr><td colspan="2" class="classify">表单</td></tr><tr><td><fieldset><br/><legend><br/><label><br/><meter><br/><progress><br/></td><td><fieldset><legend>Choose your favorite monster</legend><input type="radio" id="kraken" name="monster"><label for="kraken">Kraken</label><br/><input type="radio" id="sasquatch" name="monster"><label for="sasquatch">Sasquatch</label><br/><input type="radio" id="mothman" name="monster"><label for="mothman">Mothman</label></fieldset><hr><div class="preference"><label for="cheese">Do you like cheese?</label><input type="checkbox" name="cheese" id="cheese"></div><hr><p>Heat the oven to <meter min="200" max="500" value="350">350 degrees</meter>.</p><hr><progress value="70" max="100">70 %</progress></td></tr><tr><td colspan="2" class="classify">交互</td></tr><tr><td><details><br/><summary><br/></td><td><details open><p>Requires a computer running an operating system. The computermust have some memory and ideally some kind of long-term storage.An input device as well as some form of output device isrecommended.</p></details></td></tr><tr><td colspan="2" class="classify">过时的和弃用的元素</td></tr><tr><td><big><br/></td><td><p>This is the first sentence. <span style="font-size:1.2em">This wholesentence is in bigger letters.</span></p></td></tr></tbody><tfoot><tr><td>footer td 1</td><td>footer td 2</td></tr></tfoot></table>',
nodes_array: [],
},
onLoad: function (options) {
var array = [{
name: 'div',
attrs:{
class: 'rich-text'
},
children: [{
name: 'h1'
}, {
name: 'p',
children: [{
type: 'text',
text: 'Hello '
}, {
type: 'node',
name: 'i',
attrs: {
style: 'color:red;'
},
children: [{
type: 'text',
text: 'MoreCross'
}]
}, {
type: 'text',
text: ' !'
}]
}]
}];
this.setData({
nodes_array: array,
nodes_array_string: JSON.stringify(array, null, 2)
})
}
})
.rich-text{
color: blue;
}
.rich-text h1{
color: red;
}
.classify{
text-align: center;
background-color: #eee;
}