mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-23 13:56:44 +00:00
fix attributes of table caption and table cell
Merging `inTableCaptioin` method into `eatTableRow` with an additional parameter so that table caption attributes can be respected. This patch also distinguishes double pipes (`||`) which start a new table cell and single pipe (`|`) which ends the attributes. Bug: T324374 Change-Id: If2d4600067c587fe0b6a6edb332fd4e55abec607
This commit is contained in:
parent
5235dbb322
commit
8a3d203a03
2
resources/dist/main.js
vendored
2
resources/dist/main.js
vendored
File diff suppressed because one or more lines are too long
2
resources/dist/main.js.map.json
vendored
2
resources/dist/main.js.map.json
vendored
File diff suppressed because one or more lines are too long
|
@ -629,14 +629,6 @@ class CodeMirrorModeMediaWiki {
|
|||
return this.eatWikiText( modeConfig.tags.tableDefinition )( stream, state );
|
||||
}
|
||||
|
||||
inTableCaption( stream, state ) {
|
||||
if ( stream.sol() && stream.match( /^[\s\u00a0]*[|!]/, false ) ) {
|
||||
state.tokenize = this.inTable.bind( this );
|
||||
return this.inTable( stream, state );
|
||||
}
|
||||
return this.eatWikiText( modeConfig.tags.tableCaption )( stream, state );
|
||||
}
|
||||
|
||||
inTable( stream, state ) {
|
||||
if ( stream.sol() ) {
|
||||
stream.eatSpace();
|
||||
|
@ -648,7 +640,7 @@ class CodeMirrorModeMediaWiki {
|
|||
}
|
||||
if ( stream.eat( '+' ) ) {
|
||||
stream.eatSpace();
|
||||
state.tokenize = this.inTableCaption.bind( this );
|
||||
state.tokenize = this.eatTableRow( true, false, true );
|
||||
return this.makeLocalStyle( modeConfig.tags.tableDelimiter, state );
|
||||
}
|
||||
if ( stream.eat( '}' ) ) {
|
||||
|
@ -668,7 +660,14 @@ class CodeMirrorModeMediaWiki {
|
|||
return this.eatWikiText( '' )( stream, state );
|
||||
}
|
||||
|
||||
eatTableRow( isStart, isHead ) {
|
||||
// isStart actually means whether there may be attributes */
|
||||
eatTableRow( isStart, isHead, isCaption ) {
|
||||
let tag = '';
|
||||
if ( isCaption ) {
|
||||
tag = modeConfig.tags.tableCaption;
|
||||
} else if ( isHead ) {
|
||||
tag = modeConfig.tags.strong;
|
||||
}
|
||||
return ( stream, state ) => {
|
||||
if ( stream.sol() ) {
|
||||
if ( stream.match( /^[\s\u00a0]*[|!]/, false ) ) {
|
||||
|
@ -677,22 +676,19 @@ class CodeMirrorModeMediaWiki {
|
|||
}
|
||||
} else {
|
||||
if ( stream.match( /^[^'|{[<&~!]+/ ) ) {
|
||||
return this.makeStyle( ( isHead ? modeConfig.tags.strong : '' ), state );
|
||||
return this.makeStyle( tag, state );
|
||||
}
|
||||
if (
|
||||
stream.match( '||' ) ||
|
||||
( isHead && stream.match( '!!' ) ) ||
|
||||
( isStart && stream.eat( '|' ) )
|
||||
) {
|
||||
if ( stream.match( '||' ) || ( isHead && stream.match( '!!' ) ) ) {
|
||||
this.isBold = false;
|
||||
this.isItalic = false;
|
||||
if ( isStart ) {
|
||||
state.tokenize = this.eatTableRow( false, isHead );
|
||||
}
|
||||
state.tokenize = this.eatTableRow( true, isHead, isCaption );
|
||||
return this.makeLocalStyle( modeConfig.tags.tableDelimiter, state );
|
||||
}
|
||||
if ( isStart && stream.eat( '|' ) ) {
|
||||
state.tokenize = this.eatTableRow( false, isHead, isCaption );
|
||||
return this.makeLocalStyle( modeConfig.tags.tableDelimiter, state );
|
||||
}
|
||||
}
|
||||
const tag = isHead ? modeConfig.tags.strong : '';
|
||||
return this.eatWikiText( tag )( stream, state );
|
||||
};
|
||||
}
|
||||
|
|
|
@ -78,6 +78,11 @@ const testCases = [
|
|||
input: '{{{!}} class="wikitable"\n! header\n{{!}}-\n{{!}} cell\n{{!}}}',
|
||||
output: '<div class="cm-line">{<span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">{{</span><span class="cm-mw-ext-ground cm-mw-parserfunction-name">!</span><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">}}</span> class="wikitable"</div><div class="cm-line">! header</div><div class="cm-line"><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">{{</span><span class="cm-mw-ext-ground cm-mw-parserfunction-name">!</span><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">}}</span>-</div><div class="cm-line"><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">{{</span><span class="cm-mw-ext-ground cm-mw-parserfunction-name">!</span><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">}}</span> cell</div><div class="cm-line"><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">{{</span><span class="cm-mw-ext-ground cm-mw-parserfunction-name">!</span><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">}}</span>}</div>'
|
||||
},
|
||||
{
|
||||
title: 'T324374: table cell attributes',
|
||||
input: '{|\n|+ class="z" | Z\n! class="a" | A !! class="b" | B\n|-\n! class="c" | C || class="d" | D\n|-\n| class="e" | E || class="f" | F\n|}',
|
||||
output: '<div class="cm-line"><span class="cm-mw-table-bracket">{|</span></div><div class="cm-line"><span class="cm-mw-table-delimiter">|+ </span><span class="cm-mw-table-caption">class="z" </span><span class="cm-mw-table-delimiter">|</span><span class="cm-mw-table-caption"> Z</span></div><div class="cm-line"><span class="cm-mw-table-delimiter">! </span><span class="cm-mw-strong">class="a" </span><span class="cm-mw-table-delimiter">|</span><span class="cm-mw-strong"> A </span><span class="cm-mw-table-delimiter">!!</span><span class="cm-mw-strong"> class="b" </span><span class="cm-mw-table-delimiter">|</span><span class="cm-mw-strong"> B</span></div><div class="cm-line"><span class="cm-mw-table-delimiter">|-</span></div><div class="cm-line"><span class="cm-mw-table-delimiter">! </span><span class="cm-mw-strong">class="c" </span><span class="cm-mw-table-delimiter">|</span><span class="cm-mw-strong"> C </span><span class="cm-mw-table-delimiter">||</span><span class="cm-mw-strong"> class="d" </span><span class="cm-mw-table-delimiter">|</span><span class="cm-mw-strong"> D</span></div><div class="cm-line"><span class="cm-mw-table-delimiter">|-</span></div><div class="cm-line"><span class="cm-mw-table-delimiter">| </span>class="e" <span class="cm-mw-table-delimiter">|</span> E <span class="cm-mw-table-delimiter">||</span> class="f" <span class="cm-mw-table-delimiter">|</span> F</div><div class="cm-line"><span class="cm-mw-table-bracket">|}</span></div>'
|
||||
},
|
||||
{
|
||||
title: 'section headings',
|
||||
input: '== My section ==\nFoo bar\n=== Blah ===\nBaz\n= { =\nText',
|
||||
|
|
Loading…
Reference in a new issue