Skip to content

Commit f215ff6

Browse files
authored
Update HTML.js
1 parent 3173735 commit f215ff6

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/HTML.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
IGNORED_TAGS,
1010
TEXT_TAGS_IGNORING_ASSOCIATION,
1111
STYLESETS,
12-
TextOnlyPropTypes
13-
} from './HTMLUtils';
12+
TextOnlyPropTypes, TEXT_TAGS_MUST_INLINE
13+
} from './HTMLUtils'
1414
import { generateDefaultBlockStyles, generateDefaultTextStyles } from './HTMLDefaultStyles';
1515
import htmlparser2 from 'htmlparser2';
1616
import * as HTMLRenderers from './HTMLRenderers';
@@ -226,7 +226,38 @@ export default class HTML extends PureComponent {
226226
};
227227
}
228228
}
229+
230+
//Fixed multiple Emoji can not be inline while got img tag
231+
if (child.wrapper === 'Text' && TEXT_TAGS_MUST_INLINE.indexOf(child.tagName) !== -1
232+
&& children.length > 1) {
233+
// Texts outside <p> or not <p> themselves (with siblings)
234+
let wrappedTexts = [];
235+
for (let j = i; j < children.length; j++) {
236+
// Loop on its next siblings and store them in an array
237+
// until we encounter a block or a <p>
238+
let nextSibling = children[j];
239+
if (nextSibling.wrapper !== 'Text' || (TEXT_TAGS_MUST_INLINE.indexOf(nextSibling.tagName) === -1)) {
240+
break;
241+
}
242+
wrappedTexts.push(nextSibling);
243+
// Remove the child that has been nested
244+
children[j] = false;
245+
}
246+
// Replace the raw text with a <p> that has wrappedTexts as its children
247+
if (wrappedTexts.length) {
248+
children[i] = {
249+
attribs: {},
250+
children: wrappedTexts,
251+
nodeIndex: i,
252+
parent: child.parent,
253+
parentTag: child.parentTag,
254+
tagName: 'textwrapper',
255+
wrapper: 'Text'
256+
};
257+
}
258+
}
229259
}
260+
230261
return children.filter((parsedNode) => parsedNode !== false && parsedNode !== undefined);
231262
}
232263

@@ -383,6 +414,7 @@ export default class HTML extends PureComponent {
383414
*/
384415
renderRNElements (RNElements, parentWrapper = 'root', parentIndex = 0, props = this.props) {
385416
const { tagsStyles, classesStyles, emSize, ptSize, ignoredStyles, allowedStyles, baseFontStyle } = props;
417+
386418
return RNElements && RNElements.length ? RNElements.map((element, index) => {
387419
const { attribs, data, tagName, parentTag, children, nodeIndex, wrapper } = element;
388420
const Wrapper = wrapper === 'Text' ? Text : View;

0 commit comments

Comments
 (0)