Skip to content

Commit 1d02868

Browse files
authored
Bug Fix render ol, ul error
1 parent 5ea8199 commit 1d02868

File tree

1 file changed

+48
-42
lines changed

1 file changed

+48
-42
lines changed

src/HTMLRenderers.js

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -67,51 +67,57 @@ export function ul (htmlAttribs, children, convertedCSSStyles, passProps = {}) {
6767
const { rawChildren, nodeIndex, key, baseFontStyle, listsPrefixesRenderers } = passProps;
6868
const baseFontSize = baseFontStyle.fontSize || 14;
6969

70-
children = children && children.map((child, index) => {
71-
const rawChild = rawChildren[index];
72-
let prefix = false;
73-
const rendererArgs = [
74-
htmlAttribs,
75-
children,
76-
convertedCSSStyles,
77-
{
78-
...passProps,
79-
index
70+
children = children && children
71+
.filter((child, index) => {
72+
const rawChild = rawChildren[index];
73+
74+
if (rawChild && rawChild.wrapper === 'Text'
75+
&& Array.isArray(rawChild.children)
76+
&& rawChild.children.every(x => !x.data) ) {
77+
return false
8078
}
81-
];
82-
83-
if (rawChild) {
84-
if (rawChild.parentTag === 'ul' && rawChild.tagName === 'li') {
85-
prefix = listsPrefixesRenderers && listsPrefixesRenderers.ul ? listsPrefixesRenderers.ul(...rendererArgs) : (
86-
<View style={{
87-
marginRight: 10,
88-
width: baseFontSize / 2.8,
89-
height: baseFontSize / 2.8,
90-
marginTop: baseFontSize / 2,
91-
borderRadius: baseFontSize / 2.8,
92-
backgroundColor: 'black'
93-
}} />
94-
);
95-
} else if (rawChild.parentTag === 'ol' && rawChild.tagName === 'li') {
96-
prefix = listsPrefixesRenderers && listsPrefixesRenderers.ol ? listsPrefixesRenderers.ol(...rendererArgs) : (
97-
<Text style={{ marginRight: 5, fontSize: baseFontSize }}>{ index + 1 })</Text>
98-
);
99-
}
100-
}
10179

102-
if (rawChild && rawChild.wrapper === 'Text'
103-
&& Array.isArray(rawChild.children)
104-
&& rawChild.children.every(x => !x.data) ) {
105-
return null
106-
}
80+
return true
81+
})
82+
.map((child, index) => {
83+
const rawChild = rawChildren[index];
84+
let prefix = false;
85+
const rendererArgs = [
86+
htmlAttribs,
87+
children,
88+
convertedCSSStyles,
89+
{
90+
...passProps,
91+
index
92+
}
93+
];
94+
95+
if (rawChild) {
96+
if (rawChild.parentTag === 'ul' && (rawChild.tagName === 'li' || rawChild.tagName === 'textwrapper')) {
97+
prefix = listsPrefixesRenderers && listsPrefixesRenderers.ul ? listsPrefixesRenderers.ul(...rendererArgs) : (
98+
<View style={{
99+
marginRight: 10,
100+
width: baseFontSize / 2.8,
101+
height: baseFontSize / 2.8,
102+
marginTop: baseFontSize / 2,
103+
borderRadius: baseFontSize / 2.8,
104+
backgroundColor: 'black'
105+
}} />
106+
);
107+
} else if (rawChild.parentTag === 'ol' && (rawChild.tagName === 'li' || rawChild.tagName === 'textwrapper')) {
108+
prefix = listsPrefixesRenderers && listsPrefixesRenderers.ol ? listsPrefixesRenderers.ol(...rendererArgs) : (
109+
<Text style={{ marginRight: 5, fontSize: baseFontSize }}>{ index + 1 })</Text>
110+
);
111+
}
112+
}
107113

108-
return (
109-
<View key={`list-${nodeIndex}-${index}-${key}`} style={{ flexDirection: 'row', marginBottom: 10 }}>
110-
{ prefix }
111-
<View style={{ flex: 1 }}>{ child }</View>
112-
</View>
113-
);
114-
});
114+
return (
115+
<View key={`list-${nodeIndex}-${index}-${key}`} style={{ flexDirection: 'row', marginBottom: 10 }}>
116+
{ prefix }
117+
<View style={{ flex: 1 }}>{ child }</View>
118+
</View>
119+
);
120+
});
115121

116122

117123
return (

0 commit comments

Comments
 (0)