(cherry picked from commit 90cce88358)
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
parent
44708f5bba
commit
ad249e9fe4
3 changed files with 181 additions and 2 deletions
|
|
@ -31,3 +31,164 @@ exports[`MarkdownEmoji should match snapshot 1`] = `
|
|||
</Unknown>
|
||||
</Unknown>
|
||||
`;
|
||||
|
||||
exports[`MarkdownEmoji should render with hardbreaks 1`] = `
|
||||
<Unknown
|
||||
context={Array []}
|
||||
first={true}
|
||||
last={true}
|
||||
literal={null}
|
||||
nodeKey="22"
|
||||
>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
]
|
||||
}
|
||||
emojiName="fire"
|
||||
literal=":fire:"
|
||||
nodeKey="4"
|
||||
>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
"emoji",
|
||||
]
|
||||
}
|
||||
literal=":fire:"
|
||||
nodeKey="3"
|
||||
/>
|
||||
</Unknown>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
]
|
||||
}
|
||||
literal=" "
|
||||
nodeKey="5"
|
||||
/>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
]
|
||||
}
|
||||
emojiName="fire"
|
||||
literal=":fire:"
|
||||
nodeKey="8"
|
||||
>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
"emoji",
|
||||
]
|
||||
}
|
||||
literal=":fire:"
|
||||
nodeKey="7"
|
||||
/>
|
||||
</Unknown>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
]
|
||||
}
|
||||
literal=""
|
||||
nodeKey="9"
|
||||
/>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
]
|
||||
}
|
||||
literal={null}
|
||||
nodeKey="10"
|
||||
/>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
]
|
||||
}
|
||||
emojiName="fire"
|
||||
literal=":fire:"
|
||||
nodeKey="13"
|
||||
>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
"emoji",
|
||||
]
|
||||
}
|
||||
literal=":fire:"
|
||||
nodeKey="12"
|
||||
/>
|
||||
</Unknown>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
]
|
||||
}
|
||||
literal=" "
|
||||
nodeKey="14"
|
||||
/>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
]
|
||||
}
|
||||
emojiName="fire"
|
||||
literal=":fire:"
|
||||
nodeKey="17"
|
||||
>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
"emoji",
|
||||
]
|
||||
}
|
||||
literal=":fire:"
|
||||
nodeKey="16"
|
||||
/>
|
||||
</Unknown>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
]
|
||||
}
|
||||
literal=" "
|
||||
nodeKey="18"
|
||||
/>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
]
|
||||
}
|
||||
emojiName="fire"
|
||||
literal=":fire:"
|
||||
nodeKey="21"
|
||||
>
|
||||
<Unknown
|
||||
context={
|
||||
Array [
|
||||
"paragraph",
|
||||
"emoji",
|
||||
]
|
||||
}
|
||||
literal=":fire:"
|
||||
nodeKey="20"
|
||||
/>
|
||||
</Unknown>
|
||||
</Unknown>
|
||||
`;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ export default class MarkdownEmoji extends PureComponent {
|
|||
paragraph: this.renderParagraph,
|
||||
document: this.renderParagraph,
|
||||
text: this.renderText,
|
||||
hardbreak: this.renderNewLine,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
@ -73,10 +74,14 @@ export default class MarkdownEmoji extends PureComponent {
|
|||
|
||||
renderText = ({context, literal}) => {
|
||||
const style = this.computeTextStyle(this.props.baseTextStyle, context);
|
||||
|
||||
return <Text style={style}>{literal}</Text>;
|
||||
};
|
||||
|
||||
renderNewLine = ({context}) => {
|
||||
const style = this.computeTextStyle(this.props.baseTextStyle, context);
|
||||
return <Text style={style}>{'\n'}</Text>;
|
||||
}
|
||||
|
||||
renderEditedIndicator = ({context}) => {
|
||||
let spacer = '';
|
||||
if (context[0] === 'paragraph') {
|
||||
|
|
@ -101,7 +106,7 @@ export default class MarkdownEmoji extends PureComponent {
|
|||
};
|
||||
|
||||
render() {
|
||||
const ast = this.parser.parse(this.props.value);
|
||||
const ast = this.parser.parse(this.props.value.replace(/\n*$/, ''));
|
||||
|
||||
if (this.props.isEdited) {
|
||||
const editIndicatorNode = new Node('edited_indicator');
|
||||
|
|
|
|||
|
|
@ -24,4 +24,17 @@ describe('MarkdownEmoji', () => {
|
|||
|
||||
expect(wrapper.getElement()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should render with hardbreaks', () => {
|
||||
const wrapper = shallow(
|
||||
<MarkdownEmoji
|
||||
{...baseProps}
|
||||
value={`:fire: :fire:
|
||||
:fire: :fire: :fire:
|
||||
`}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(wrapper.getElement()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue