Bold only first instance of title in extract

Bug: T132523
Change-Id: I3145186264edd23ca898365ae55184cbe96ada6a
This commit is contained in:
Prateek Saxena 2016-04-13 21:24:42 +05:30
parent e53a093c73
commit 5f92196541
2 changed files with 9 additions and 3 deletions

View file

@ -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

View file

@ -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 );