Merge "CodeMirrorModeMediaWiki: one-line definition list"

This commit is contained in:
jenkins-bot 2024-05-03 07:22:42 +00:00 committed by Gerrit Code Review
commit 45c2cf6d9e
3 changed files with 37 additions and 12 deletions

File diff suppressed because one or more lines are too long

View file

@ -114,8 +114,12 @@ class CodeMirrorModeMediaWiki {
return style;
}
isNested( state ) {
return state.nExt > 0 || state.nTemplate > 0 || state.nLink > 0;
}
makeStyle( style, state, endGround ) {
if ( this.isBold ) {
if ( this.isBold || state.nDt > 0 ) {
style += ' ' + modeConfig.tags.strong;
}
if ( this.isItalic ) {
@ -747,6 +751,15 @@ class CodeMirrorModeMediaWiki {
return this.makeLocalStyle( modeConfig.tags.freeExtLink, state );
}
eatList( stream, state ) {
// Just consume all nested list and indention syntax when there is more
const mt = stream.match( /^[*#;:]*/u );
if ( mt && !this.isNested( state ) && mt[ 0 ].includes( ';' ) ) {
state.nDt += mt[ 0 ].split( ';' ).length - 1;
}
return this.makeLocalStyle( modeConfig.tags.list, state );
}
/**
* @param {string} style
* @return {string|Function}
@ -798,21 +811,19 @@ class CodeMirrorModeMediaWiki {
modeConfig.tags[ `sectionHeader${ tmp[ 1 ].length + 1 }` ];
}
break;
case ';':
stream.backUp( 1 );
// fall through
case '*':
case '#':
case ';':
// Just consume all nested list and indention syntax when there is more
stream.match( /^[*#;:]*/ );
return modeConfig.tags.list;
return this.eatList( stream, state );
case ':':
// Highlight indented tables :{|, bug T108454
if ( stream.match( /^:*{\|/, false ) ) {
state.stack.push( state.tokenize );
state.tokenize = this.eatStartTable.bind( this );
}
// Just consume all nested list and indention syntax when there is more
stream.match( /^[*#;:]*/ );
return modeConfig.tags.indenting;
return this.eatList( stream, state );
case ' ':
// Leading spaces is valid syntax for tables, bug T108454
if ( stream.match( /^[\s\u00a0]*:*{\|/, false ) ) {
@ -1018,6 +1029,12 @@ class CodeMirrorModeMediaWiki {
}
}
break;
case ':':
if ( state.nDt > 0 && !this.isNested( state ) ) {
state.nDt--;
return modeConfig.tags.indenting;
}
break;
default:
if ( /[\s\u00a0]/.test( ch ) ) {
stream.eatSpace();
@ -1097,7 +1114,8 @@ class CodeMirrorModeMediaWiki {
extState: false,
nTemplate: 0,
nLink: 0,
nExt: 0
nExt: 0,
nDt: 0
};
},
@ -1118,7 +1136,8 @@ class CodeMirrorModeMediaWiki {
extState: state.extMode !== false && state.extMode.copyState( state.extState ),
nTemplate: state.nTemplate,
nLink: state.nLink,
nExt: state.nExt
nExt: state.nExt,
nDt: state.nDt
};
},
@ -1146,6 +1165,7 @@ class CodeMirrorModeMediaWiki {
if ( stream.sol() ) {
// reset bold and italic status in every new line
state.nDt = 0;
this.isBold = false;
this.isItalic = false;
this.firstSingleLetterWord = null;

View file

@ -105,7 +105,12 @@ const testCases = [
{
title: 'nested ordered, unordered and definition lists',
input: '*#;: item A\n#;:* item B\n;:*# item C\n:*#; item D',
output: '<div class="cm-line"><span class="cm-mw-list">*#;:</span> item A</div><div class="cm-line"><span class="cm-mw-list">#;:*</span> item B</div><div class="cm-line"><span class="cm-mw-list">;:*#</span> item C</div><div class="cm-line"><span class="cm-mw-indenting">:*#;</span> item D </div>'
output: '<div class="cm-line"><span class="cm-mw-list">*#;:</span><span class="cm-mw-strong"> item</span><span class="cm-mw-strong"> A</span></div><div class="cm-line"><span class="cm-mw-list">#;:*</span><span class="cm-mw-strong"> item</span><span class="cm-mw-strong"> B</span></div><div class="cm-line"><span class="cm-mw-list">;:*#</span><span class="cm-mw-strong"> item</span><span class="cm-mw-strong"> C</span></div><div class="cm-line"><span class="cm-mw-list">:*#;</span><span class="cm-mw-strong"> item</span><span class="cm-mw-strong"> D</span><span class="cm-mw-strong"> </span></div>'
},
{
title: 'one-line definition list',
input: ';term:definition\n;term\n:definition',
output: '<div class="cm-line"><span class="cm-mw-list">;</span><span class="cm-mw-strong">term</span><span class="cm-mw-indenting">:</span>definition</div><div class="cm-line"><span class="cm-mw-list">;</span><span class="cm-mw-strong">term</span></div><div class="cm-line"><span class="cm-mw-list">:</span>definition </div>'
},
{
title: 'link with bold text',