Skip to content

Commit

Permalink
handle disabled categories
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae committed Dec 7, 2023
1 parent 6fc2a18 commit 51e7f73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@
* @param {string} wikicode
*/
removeEmptySectionAtEnd: function ( wikicode ) {
result = wikicode.replace( /(\n)==[^=]+==\n\s*?(\[\[Category:|$)/i, '$1$2' );
result = wikicode.replace( /(\n)==[^=]+==\n\s*?(\[\[:?Category:|$)/i, '$1$2' );
var headingWasRemoved = result !== wikicode;
if ( headingWasRemoved ) {
result = result.replace( /\n\n$/, '\n' );
Expand Down
6 changes: 6 additions & 0 deletions tests/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ describe( 'AFCH.removeEmptySectionAtEnd', function () {
expect( output ).toBe( 'Test\n\n==Test2==\n\n[[Category:Test]]\n' );
} );

it( 'disabled category', function () {
var wikicode = 'Test\n\n==Test2==\n\n== Test 3 ==\n\n[[:Category:Test]]\n';
var output = AFCH.removeEmptySectionAtEnd( wikicode );
expect( output ).toBe( 'Test\n\n==Test2==\n\n[[:Category:Test]]\n' );
} );

it( 'two headings without body text and with two categories #1', function () {
var wikicode = 'Test\n\n==Test2==\n\n== Test 3 ==\n\n[[Category:Test]]\n[[Category:Test2]]\n';
var output = AFCH.removeEmptySectionAtEnd( wikicode );
Expand Down

0 comments on commit 51e7f73

Please sign in to comment.