Expand
You can download the code via CDN on a MediaWiki site, for example:
mw.loader.load('https://cdn.jsdelivr.net/npm/@bhsd/codemirror-mediawiki/dist/wiki.min.js');
or
mw.loader.load('https://unpkg.com/@bhsd/codemirror-mediawiki/dist/wiki.min.js');
The script also loads the styles, adds a button to configure user preferences, and watches Shift
-clicks of any textarea.
Expand
version added: 2.2.2
The CodeMirror
class extends the CodeMirror6
class with one more argument to specify the namespace.
param: HTMLTextAreaElement
the textarea element to be replaced by CodeMirror
param: string
the language mode to be used, default as plain text
param: number
the namespace id associated with the content, default as the current namespace
param: unknown
the optional language configuration
param: boolean
whether to use CodeMirror or Monaco editor, default as CodeMirror
param: string
the optional page title, default as the current page title
const cm = new CodeMirror6(textarea); // plain text
const cm = new CodeMirror6(textarea, 'mediawiki', undefined, mwConfig);
const cm = new CodeMirror6(textarea, 'html', 274, mwConfig); // mixed MediaWiki-HTML
const cm = new CodeMirror6(textarea, 'css');
const cm = new CodeMirror6(textarea, 'javascript');
const cm = new CodeMirror6(textarea, 'json');
const cm = new CodeMirror6(textarea, 'lua');
The CodeMirror
class inherits all the accessors from the CodeMirror6
class.
Expand
version added: 2.11.1
type: Monaco.editor.IStandaloneCodeEditor | undefined
The Monaco editor instance.
Expand
version added: 2.11.1
type: Monaco.editor.ITextModel | undefined
The Monaco text model instance.
The CodeMirror
class inherits all the methods from the CodeMirror6
class and addes more.
Expand
version added: 2.1.9
param: boolean
whether to start linting
param: Record<string, unknown> | number
the optional linter configuration or the namespace id
Lint the CodeMirror editor with a default linter.
cm.defaultLint(true, 0);
Expand
version added: 2.11.1
returns: string
Get the content of the editor.
cm.getContent();
Expand
version added: 2.6.3
type: string
The version number.
The CodeMirror
class inherits all the static methods from the CodeMirror6
class and addes more.
Expand
version added: 2.2.2
param: HTMLTextAreaElement
the textarea element to be replaced by CodeMirror
param: string
the language mode to be used, default as plain text
param: number
the namespace id associated with the content, default as the current namespace
param: string
the optional page title, default as the current page title
Replace the textarea with a CodeMirror or Monaco editor.
CodeMirror6.fromTextArea(textarea, 'mediawiki');
The CodeMirror
class inherits all the extensions from the CodeMirror6
class and addes more.
version added: 2.4.5
Load the WikiEditor toolbar. This extension can only be used before CodeMirror instantiation, which means it is inaccessible by the prefer
method.
version added: 2.7.0
Save preferences as JSON on a user subpage (Special:Mypage/codemirror-mediawiki.json
).
version added: 2.11.1
Use the Monaco editor instead of the CodeMirror editor.