mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-23 22:03:28 +00:00
CodeMirrorModeMediaWiki: one-line definition list
Add highlighting for a special one-line definition list syntax `;a:b`. Also highlight `;a` in bold. Bug: T170042 Change-Id: Ia3bdf481469368fcb5a7651729dde4b5f3682ed8
This commit is contained in:
parent
eee5093270
commit
52471d4b8f
2
resources/dist/codemirror.mode.mediawiki.js
vendored
2
resources/dist/codemirror.mode.mediawiki.js
vendored
File diff suppressed because one or more lines are too long
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue