Prtksxna has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/283212

Change subject: Bold only first instance of title in extract
......................................................................

Bold only first instance of title in extract

Bug: T132523
Change-Id: I3145186264edd23ca898365ae55184cbe96ada6a
---
M resources/ext.popups.renderer.article.js
M tests/qunit/ext.popups.renderer.article.test.js
2 files changed, 9 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups 
refs/changes/12/283212/1

diff --git a/resources/ext.popups.renderer.article.js 
b/resources/ext.popups.renderer.article.js
index 56add36..434ae15 100644
--- a/resources/ext.popups.renderer.article.js
+++ b/resources/ext.popups.renderer.article.js
@@ -182,13 +182,13 @@
        article.getProcessedElements = function ( extract, title ) {
                var elements = [],
                        escapedTitle = mw.RegExp.escape( title ), // Escape 
RegExp elements
-                       regExp = new RegExp( '(^|\\s)(' + escapedTitle + 
')(|$)', 'ig' ),
+                       regExp = new RegExp( '(^|\\s)(' + escapedTitle + 
')(|$)', 'i' ),
                        boldIdentifier = '<bi-' + Math.random() + '>',
                        snip = '<snip-' + Math.random() + '>';
 
                // Remove text in parentheses along with the parentheses
                extract = article.removeParensFromText( extract );
-               extract = extract.replace( /\s+/g, ' ' ); // Remove extra white 
spaces
+               extract = extract.replace( /\s+/, ' ' ); // Remove extra white 
spaces
 
                // Make title bold in the extract text
                // As the extract is html escaped there can be no such string 
in it
diff --git a/tests/qunit/ext.popups.renderer.article.test.js 
b/tests/qunit/ext.popups.renderer.article.test.js
index e2fd9ae..30dae3a 100644
--- a/tests/qunit/ext.popups.renderer.article.test.js
+++ b/tests/qunit/ext.popups.renderer.article.test.js
@@ -3,7 +3,7 @@
        QUnit.module( 'ext.popups.renderer.renderers.article', 
QUnit.newMwEnvironment() );
 
        QUnit.test( 'render.article.getProcessedElements', function ( assert ) {
-               QUnit.expect( 13 );
+               QUnit.expect( 14 );
 
                function test( extract, title, expected, msg ) {
                        var $div = $( '<div>' ).append(
@@ -90,6 +90,12 @@
                        'Article that begins with asterisk'
                );
 
+               test(
+                       'Testing if repeated words are not matched when 
repeated', 'Repeated',
+                       'Testing if <b>repeated</b> words are not matched when 
repeated',
+                       'Repeated title'
+               );
+
        } );
        QUnit.test( 'render.article.getClosestYPosition', function ( assert ) {
                QUnit.expect( 3 );

-- 
To view, visit https://gerrit.wikimedia.org/r/283212
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3145186264edd23ca898365ae55184cbe96ada6a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Prtksxna <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to