mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 23:24:39 +00:00
Merge "Add reference type detection to HTML scraping gateway"
This commit is contained in:
commit
f812611470
BIN
resources/dist/index.js
vendored
BIN
resources/dist/index.js
vendored
Binary file not shown.
BIN
resources/dist/index.js.map.json
vendored
BIN
resources/dist/index.js.map.json
vendored
Binary file not shown.
|
@ -21,6 +21,22 @@ export default function createReferenceGateway() {
|
|||
return $( `${ idSelector } .mw-reference-text, ${ idSelector } .reference-text` );
|
||||
}
|
||||
|
||||
/**
|
||||
* This duplicates the strict type detection from
|
||||
* @see https://phabricator.wikimedia.org/diffusion/GMOA/browse/master/lib/transformations/references/structureReferenceListContent.js$93
|
||||
*
|
||||
* @param {JQuery} $referenceText
|
||||
* @returns {string|null}
|
||||
*/
|
||||
function scrapeReferenceType( $referenceText ) {
|
||||
const $cite = $referenceText.find( 'cite[class]' );
|
||||
if ( $cite.length === 1 ) {
|
||||
return $cite.attr( 'class' ).replace( /\bcitation\b/g, '' ).trim();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {mw.Title} title
|
||||
* @param {Element} el
|
||||
|
@ -43,6 +59,7 @@ export default function createReferenceGateway() {
|
|||
url: `#${ id }`,
|
||||
extract: $referenceText.html(),
|
||||
type: previewTypes.TYPE_REFERENCE,
|
||||
referenceType: scrapeReferenceType( $referenceText ),
|
||||
sourceElementId: el && el.parentNode && el.parentNode.id
|
||||
};
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ QUnit.module( 'ext.popups/gateway/reference', {
|
|||
$( '<span>' ).addClass( 'mw-reference-text' ).text( 'Footnote 1' )
|
||||
),
|
||||
$( '<li>' ).attr( 'id', 'cite_note--2' ).append(
|
||||
$( '<span>' ).addClass( 'reference-text' ).text( 'Footnote 2' )
|
||||
$( '<span>' ).addClass( 'reference-text' ).append(
|
||||
$( '<cite>' ).addClass( 'citation web unknown' ).text( 'Footnote 2' )
|
||||
)
|
||||
)
|
||||
).appendTo( document.body );
|
||||
},
|
||||
|
@ -36,6 +38,7 @@ QUnit.test( 'Reference preview gateway returns the correct data', function ( ass
|
|||
url: '#cite_note--1',
|
||||
extract: 'Footnote 1',
|
||||
type: 'reference',
|
||||
referenceType: null,
|
||||
sourceElementId: undefined
|
||||
}
|
||||
);
|
||||
|
@ -51,8 +54,9 @@ QUnit.test( 'Reference preview gateway accepts alternative text node class name'
|
|||
result,
|
||||
{
|
||||
url: '#cite_note--2',
|
||||
extract: 'Footnote 2',
|
||||
extract: '<cite class="citation web unknown">Footnote 2</cite>',
|
||||
type: 'reference',
|
||||
referenceType: 'web unknown',
|
||||
sourceElementId: undefined
|
||||
}
|
||||
);
|
||||
|
@ -70,6 +74,7 @@ QUnit.test( 'Reference preview gateway returns source element id', function ( as
|
|||
url: '#cite_note--1',
|
||||
extract: 'Footnote 1',
|
||||
type: 'reference',
|
||||
referenceType: null,
|
||||
sourceElementId: 'cite_ref-1'
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue