mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-12-12 14:25:06 +00:00
197b5649ff
Autocomplete magic words, tag names and url protocols. This patch also enables block comment using `<!-- -->`. Bug: T95100 Change-Id: If37da956ac1eb945b96753e6728c0247b1a68b66
52 lines
2.3 KiB
JavaScript
52 lines
2.3 KiB
JavaScript
const CodeMirror = require( '../../resources/codemirror.js' );
|
|
const mediaWikiLang = require( '../../resources/codemirror.mediawiki.js' );
|
|
const bidiIsolationExtension = require( '../../resources/codemirror.mediawiki.bidiIsolation.js' );
|
|
|
|
const testCases = [
|
|
{
|
|
title: 'wraps HTML tags with span.cm-bidi-isolate',
|
|
input: 'שלום<span class="foobar">שלום</span>שלום',
|
|
output: '<div class="cm-line">שלום<span class="cm-bidi-isolate"><span class="cm-mw-htmltag-bracket"><</span><span class="cm-mw-htmltag-name">span </span><span class="cm-mw-htmltag-attribute">class="foobar"</span><span class="cm-mw-htmltag-bracket">></span></span>שלום<span class="cm-bidi-isolate"><span class="cm-mw-htmltag-bracket"></</span><span class="cm-mw-htmltag-name">span</span><span class="cm-mw-htmltag-bracket">></span></span>שלום</div>'
|
|
},
|
|
{
|
|
title: 'wraps self-closing extension tags with span.cm-bidi-isolate',
|
|
input: '<ref name="foo" />',
|
|
output: '<div class="cm-line"><span class="cm-bidi-isolate"><span class="cm-mw-exttag-bracket cm-mw-ext-ref"><</span><span class="cm-mw-exttag-name cm-mw-ext-ref">ref </span><span class="cm-mw-exttag-attribute cm-mw-ext-ref">name="foo" </span><span class="cm-mw-exttag-bracket cm-mw-ext-ref">/></span></span></div>'
|
|
}
|
|
];
|
|
|
|
// Setup CodeMirror instance.
|
|
const textarea = document.createElement( 'textarea' );
|
|
textarea.dir = 'rtl';
|
|
document.body.appendChild( textarea );
|
|
const cm = new CodeMirror( textarea );
|
|
const mwLang = mediaWikiLang(
|
|
{ bidiIsolation: true },
|
|
{
|
|
doubleUnderscore: [ {}, {} ],
|
|
functionSynonyms: [ {}, {} ],
|
|
tags: { ref: true },
|
|
urlProtocols: 'http\\:\\/\\/'
|
|
}
|
|
);
|
|
cm.initialize( [ ...cm.defaultExtensions, mwLang ] );
|
|
// Normally ran by mw.hook, but we don't mock the hook system in the Jest tests.
|
|
cm.preferences.registerExtension( 'bidiIsolation', bidiIsolationExtension, cm.view );
|
|
|
|
describe( 'CodeMirrorBidiIsolation', () => {
|
|
it.each( testCases )(
|
|
'bidi isolation ($title)',
|
|
( { input, output } ) => {
|
|
cm.view.dispatch( {
|
|
changes: {
|
|
from: 0,
|
|
to: cm.view.state.doc.length,
|
|
insert: input
|
|
}
|
|
} );
|
|
cm.$textarea.textSelection = jest.fn().mockReturnValue( input );
|
|
expect( cm.view.dom.querySelector( '.cm-content' ).innerHTML ).toStrictEqual( output );
|
|
}
|
|
);
|
|
} );
|