Skip to content

Commit

Permalink
完善节点渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaoGongBra committed Jun 7, 2022
1 parent fee8886 commit a3a5aec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 10 additions & 0 deletions components/HtmlView.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,22 @@
.html-b {
font-weight: bold;
}
.html-i,
.html-em {
font-style: italic;
}
.html-u {
text-decoration: underline;
}
.html-b,
.html-strong {
font-weight: bold;
}
.html-del,
.html-s,
.html-strike {
text-decoration: line-through;
}

.html-img {
max-width: 750px;
Expand Down
6 changes: 4 additions & 2 deletions components/HtmlView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const View = ({
className
}) => {
const [viewStyle, textStyle] = getTextStyle(style)
// 判断内容是否是纯文本
// 判断内容是否是纯文本 或者是否是 文本组件
const isText = children?.every?.(item => typeof item === 'string')
// 是否是纯文本组件
const isTextComp = !isText && children?.every?.(item => item?.props?.nodeName === 'Text')
Expand Down Expand Up @@ -231,10 +231,12 @@ export default function HtmlView({

const getNodes = (() => {
const nodeArr = {
span: 'Text',
img: 'Image',
video: 'Video'
}
'span,font,b,strong,i,em,u,sup,sub,h1,h2,h3,h4,h5,h6,font,q,s,strike,del,big,small'.split(',').forEach(key => {
nodeArr[key] = 'Text'
})
/**
* 定义节点支持的style
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taro-html-view",
"version": "1.0.3",
"version": "1.0.4",
"description": "支持渲染由富文本编辑器编辑的html文本内容,支持小程序、h5、ReactNative,复杂的内容可能并不能正确渲染",
"main": "index.js",
"author": "[email protected]",
Expand Down

0 comments on commit a3a5aec

Please sign in to comment.