From 07e102d0822387eafaa919ab1592727faffffe89 Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Fri, 2 Jun 2023 15:49:35 -0700 Subject: [PATCH] only trim sometimes --- src/modules/core.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/modules/core.js b/src/modules/core.js index 5465e1cd..751e4863 100644 --- a/src/modules/core.js +++ b/src/modules/core.js @@ -1585,9 +1585,12 @@ * @param {string} wikicode */ removeEmptySectionAtEnd: function ( wikicode ) { - wikicode = wikicode.replace( /(\n)==[^=]+==\n\s*?(\[\[Category:|$)/i, '$1$2' ); - wikicode = wikicode.replace( /\n\n$/, '\n' ); - return wikicode; + result = wikicode.replace( /(\n)==[^=]+==\n\s*?(\[\[Category:|$)/i, '$1$2' ); + var headingWasRemoved = result !== wikicode; + if ( headingWasRemoved ) { + result = result.replace( /\n\n$/, '\n' ); + } + return result; }, /**