Unify and streamline code working with mw.attrs

I find it very helpful to use the name "mwAttrs" specifically for the
mw.attrs thingy that contains the original key-value pairs from the
wikitext.

An alternative is to use ve.getProp, which is helpful in other
situations.

Change-Id: I3edf0dfe5b9629fcda0bf8cb3b734215377a5c77
This commit is contained in:
thiemowmde 2024-02-21 13:52:12 +01:00
parent 90dc52620c
commit 7151077e5f
2 changed files with 10 additions and 9 deletions

View file

@ -72,17 +72,17 @@ ve.dm.MWReferenceNode.static.toDataElement = function ( domElements, converter )
const mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' );
const mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
const reflistItemId = mwData.body && mwData.body.id;
const body = ( mwData.body && mwData.body.html ) ||
const mwAttrs = mwData.attrs || {};
const reflistItemId = ve.getProp( mwData, 'body', 'id' );
const body = ve.getProp( mwData, 'body', 'html' ) ||
( reflistItemId && getReflistItemHtml( reflistItemId ) ) ||
'';
const extendsRef = mw.config.get( 'wgCiteBookReferencing' ) && mwData.attrs && mwData.attrs.extends;
const refGroup = mwData.attrs && mwData.attrs.group || '';
const extendsRef = mw.config.get( 'wgCiteBookReferencing' ) && mwAttrs.extends;
const refGroup = mwAttrs.group || '';
const listGroup = this.name + '/' + refGroup;
const autoKeyed = !mwData.attrs || mwData.attrs.name === undefined;
const listKey = autoKeyed ?
const listKey = !mwAttrs.name ?
'auto/' + converter.internalList.getNextUniqueNumber() :
'literal/' + mwData.attrs.name;
'literal/' + mwAttrs.name;
const queueResult = converter.internalList.queueItemHtml( listGroup, listKey, body );
const listIndex = queueResult.index;
const contentsUsed = ( body !== '' && queueResult.isNew );

View file

@ -102,8 +102,9 @@ ve.dm.MWReferencesListNode.static.toDataElement = function ( domElements, conver
const mwDataJSON = refListNode.getAttribute( 'data-mw' );
const mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
const refGroup = ve.getProp( mwData, 'attrs', 'group' ) || '';
const responsiveAttr = ve.getProp( mwData, 'attrs', 'responsive' );
const mwAttrs = mwData.attrs || {};
const refGroup = mwAttrs.group || '';
const responsiveAttr = mwAttrs.responsive;
const listGroup = 'mwReference/' + refGroup;
const templateGenerated = type.indexOf( 'mw:Transclusion' ) !== -1;
const isResponsiveDefault = mw.config.get( 'wgCiteResponsiveReferences' );