Commit 1a88aff1 authored by JC Brand's avatar JC Brand

Decided to still collapse newlines...

and to solve the offset issue by replacing excessive newlines with
the zero-width space unicode character.
parent 61bb0cfa
......@@ -626,7 +626,10 @@ describe("A Chat Message", function () {
</message>`);
_converse.connection._dataRecv(mock.createRequest(stanza));
await new Promise(resolve => view.model.messages.once('rendered', resolve));
expect(view.content.querySelector('converse-chat-message:last-child .chat-msg__text').innerHTML.replace(/<!---->/g, '')).toBe('Hey\nHave you heard\n\n\nthe news?\nhttps://conversejs.org');
await u.waitUntil(() => {
const text = view.content.querySelector('converse-chat-message:last-child .chat-msg__text').innerHTML.replace(/<!---->/g, '');
return text === 'Hey\nHave you heard\n\u200B\nthe news?\n<a target="_blank" rel="noopener" href="https://conversejs.org/">https://conversejs.org</a>';
});
done();
}));
......
......@@ -8,6 +8,11 @@ import { html } from 'lit-html';
const u = converse.env.utils;
const isString = (s) => typeof s === 'string';
// We don't render more than two line-breaks, replace extra line-breaks with
// the zero-width whitespace character
const collapseLineBreaks = text => text.replace(/\n\n+/g, m => `\n${"\u200B".repeat(m.length-2)}\n`);
const tpl_mention_with_nick = (o) => html`<span class="mention mention--self badge badge-info">${o.mention}</span>`;
const tpl_mention = (o) => html`<span class="mention">${o.mention}</span>`;
......@@ -317,6 +322,6 @@ export class MessageText extends String {
...list
];
});
return list.reduce((acc, i) => isString(i) ? [...acc, convertASCII2Emoji(i)] : [...acc, i], []);
return list.reduce((acc, i) => isString(i) ? [...acc, convertASCII2Emoji(collapseLineBreaks(i))] : [...acc, i], []);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment