mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-09-25 03:09:14 +00:00
Bold only first instance of title in extract
Bug: T132523 Change-Id: I3145186264edd23ca898365ae55184cbe96ada6a
This commit is contained in:
parent
e53a093c73
commit
5f92196541
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue