Tweak signature formatting in previews for more accurate results

When posting a new topic, if your comment ends with a template
that has trailing line breaks, the signature will be added as a
preformatted text (which is arguably a bug: T255741).

Preview, however, did not reflect this bug, because of the <span>
markup added to fade out the automatic signature.

Change-Id: I062b01a035e22edfca752a49c5e2433b3f7fb4f6
This commit is contained in:
Bartosz Dziewoński 2021-03-06 19:16:21 +01:00
parent 44f2209abf
commit 1a52f06daf

View file

@ -552,7 +552,7 @@ ReplyWidget.prototype.onInputChange = function () {
* @return {jQuery.Promise} Promise resolved when we're done
*/
ReplyWidget.prototype.preparePreview = function ( wikitext ) {
var parsePromise, widget, title, indent;
var parsePromise, widget, title, indent, signature;
if ( this.getMode() !== 'source' ) {
return $.Deferred().resolve().promise();
@ -588,8 +588,13 @@ ReplyWidget.prototype.preparePreview = function ( wikitext ) {
if ( !modifier.isWikitextSigned( wikitext ) ) {
// Add signature.
signature = mw.msg( 'discussiontools-signature-prefix' ) + '~~~~';
// Drop opacity of signature in preview to make message body preview clearer.
wikitext = wikitext + '<span style="opacity: 0.6;">' + mw.msg( 'discussiontools-signature-prefix' ) + '~~~~</span>';
// Extract any leading spaces outside the <span> markup to ensure accurate previews.
signature = signature.replace( /^( *)(.+)$/, function ( _, leadingSpaces, sig ) {
return leadingSpaces + '<span style="opacity: 0.6;">' + sig + '</span>';
} );
wikitext += signature;
}
if ( title ) {
wikitext = '== ' + title + ' ==\n' + wikitext;