Styling: Trim leading whitespace inside blockquote
As demanded by XEP-0393
This commit is contained in:
parent
58586ab2e4
commit
8572c86941
@ -269,13 +269,13 @@ describe("An incoming chat Message", function () {
|
|||||||
'This is <span class="styling-directive">`</span><code>also _quoted_</code><span class="styling-directive">`</span></blockquote>\n'+
|
'This is <span class="styling-directive">`</span><code>also _quoted_</code><span class="styling-directive">`</span></blockquote>\n'+
|
||||||
'This is not quoted');
|
'This is not quoted');
|
||||||
|
|
||||||
msg_text = `> > This is NOT doubly quoted text`;
|
msg_text = `> > This is doubly quoted text`;
|
||||||
msg = mock.createChatMessage(_converse, contact_jid, msg_text)
|
msg = mock.createChatMessage(_converse, contact_jid, msg_text)
|
||||||
await _converse.handleMessageStanza(msg);
|
await _converse.handleMessageStanza(msg);
|
||||||
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
||||||
msg_el = Array.from(view.el.querySelectorAll('converse-chat-message-body')).pop();
|
msg_el = Array.from(view.el.querySelectorAll('converse-chat-message-body')).pop();
|
||||||
expect(msg_el.innerText).toBe(msg_text);
|
expect(msg_el.innerText).toBe(msg_text);
|
||||||
await u.waitUntil(() => msg_el.innerHTML.replace(/<!---->/g, '') === "<blockquote> > This is NOT doubly quoted text</blockquote>");
|
await u.waitUntil(() => msg_el.innerHTML.replace(/<!---->/g, '') === "<blockquote><blockquote>This is doubly quoted text</blockquote></blockquote>");
|
||||||
|
|
||||||
msg_text = `>> This is doubly quoted text`;
|
msg_text = `>> This is doubly quoted text`;
|
||||||
msg = mock.createChatMessage(_converse, contact_jid, msg_text)
|
msg = mock.createChatMessage(_converse, contact_jid, msg_text)
|
||||||
|
@ -148,7 +148,11 @@ export const isQuoteDirective = (d) => ['>', '>'].includes(d);
|
|||||||
export function getDirectiveTemplate (d, text, model, offset) {
|
export function getDirectiveTemplate (d, text, model, offset) {
|
||||||
const template = styling_templates[styling_map[d].name];
|
const template = styling_templates[styling_map[d].name];
|
||||||
if (isQuoteDirective(d)) {
|
if (isQuoteDirective(d)) {
|
||||||
return template(text.replace(/\n>/g, '\n').replace(/\n$/, ''), model, offset);
|
const newtext = text
|
||||||
|
.replace(/\n>/g, '\n') // Don't show the directive itself
|
||||||
|
.replace(/\n$/, '') // Trim line-break at the end
|
||||||
|
.replace(/^ /, ''); // Trim leading space inside codeblock
|
||||||
|
return template(newtext, model, offset);
|
||||||
} else {
|
} else {
|
||||||
return template(text, model, offset);
|
return template(text, model, offset);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user