@bhsd/codemirror-wikitext
v0.1.0
Published
Wikitext mode based on wikimedia/mediawiki-extensions-CodeMirror and language support extensions
Readme
@bhsd/codemirror-wikitext
This repository contains a modified Wikitext language from MediaWiki extension CodeMirror and various language support extensions.
Installation
You can install the package via npm and import it as a module:
npm install @bhsd/codemirror-wikitextYou may also want to install WikiParser-Node for pre-defined parser configurations:
npm install wikiparser-nodeBasic Usage
You can simply import the mediawiki function to get the Wikitext language with full language support:
import {mediawiki} from '@bhsd/codemirror-wikitext';
import config from 'wikiparser-node/config/default.json' with {type: 'json'};
const langSupport: LanguageSupport = mediawiki(
config,
// (optional) specify the jsDelivr CDN for loading assets, default to https://testingcf.jsdelivr.net
'https://cdn.jsdelivr.net',
);Here is an online demo.
Language
mediawikiLanguage
You can import the stream language for Wikitext:
import {mediawikiLanguage} from '@bhsd/codemirror-wikitext';
import config from 'wikiparser-node/config/default.json' with {type: 'json'};
const lang: StreamLanguage = mediawikiLanguage(config);Keymap
escapeKeymap
Key bindings:
Ctrl/Cmd+[: Escape the selected text with HTML entitiesCtrl/Cmd+]: Escape the selected text with URL encodingCtrl/Cmd+\: Escape the selected text with magic words
import {escapeKeymap} from '@bhsd/codemirror-wikitext';
import config from 'wikiparser-node/config/default.json' with {type: 'json'};
const keymap: KeyBinding[] = escapeKeymap(
config,
// (optional) specify the jsDelivr CDN for loading assets, default to https://testingcf.jsdelivr.net
'https://cdn.jsdelivr.net',
);formatKeymap
Formatting key bindings:
Ctrl+0: Plain paragraphCtrl+1-6: Headings level 1 to 6Ctrl+7: Preformatted textCtrl+8: BlockquoteCtrl/Cmd+/: CommentCtrl/Cmd+.: SuperscriptCtrl/Cmd+,: SubscriptCtrl/Cmd+B: BoldCtrl/Cmd+I: ItalicCtrl/Cmd+U: UnderlineCtrl/Cmd+K: Wiki linkCtrl+Shift+5: StrikethroughCtrl/Cmd+Shift+6: Inline codeCtrl/Cmd+Shift+K: Ref tag
import {formatKeymap} from '@bhsd/codemirror-wikitext';
const keymap: KeyBinding[] = formatKeymap;Extensions
bracketMatching
Matched or unmatched brackets or tags are highlighted in cyan or dark red when the cursor is next to them.
import {bracketMatching} from '@bhsd/codemirror-wikitext';
const extension: Extension = bracketMatching();codeFolding
Fold sections, templates, parser functions and extension tags.
Key bindings:
Ctrl+Shift+[/Cmd+Alt+[: Fold at the selected textCtrl+Shift+]/Cmd+Alt+]: Unfold at the selected textCtrl+Alt+[: Fold allCtrl+Alt+]: Unfold allCtrl+Alt+.: Fold all<ref>tags
import {codeFolding} from '@bhsd/codemirror-wikitext';
const extension: Extension = codeFolding();colorPicker
Provide color pickers.
import {colorPicker} from '@bhsd/codemirror-wikitext';
const extension: Extension = colorPicker();hover
Show the help information of a magic word when hovering.
import {hover} from '@bhsd/codemirror-wikitext';
import config from 'wikiparser-node/config/default.json' with {type: 'json'};
const extension: Extension = hover(
config,
// (optional) specify the jsDelivr CDN for loading assets, default to https://testingcf.jsdelivr.net
'https://cdn.jsdelivr.net',
);inlayHints
Show inlay hints for anonymous parameters.
import {inlayHints} from '@bhsd/codemirror-wikitext';
import config from 'wikiparser-node/config/default.json' with {type: 'json'};
const extension: Extension = inlayHints(
config,
// (optional) specify the jsDelivr CDN for loading assets, default to https://testingcf.jsdelivr.net
'https://cdn.jsdelivr.net',
);refHover
Show the content of the <ref> tag defined elsewhere when hovering.
import {refHover} from '@bhsd/codemirror-wikitext';
import config from 'wikiparser-node/config/default.json' with {type: 'json'};
const extension: Extension = refHover(
config,
// (optional) specify the jsDelivr CDN for loading assets, default to https://testingcf.jsdelivr.net
'https://cdn.jsdelivr.net',
);signatureHelp
Show the parser function signature when typing.
import {signatureHelp} from '@bhsd/codemirror-wikitext';
import config from 'wikiparser-node/config/default.json' with {type: 'json'};
const extension: Extension = signatureHelp(
config,
// (optional) specify the jsDelivr CDN for loading assets, default to https://testingcf.jsdelivr.net
'https://cdn.jsdelivr.net',
);wikilint
Provide syntax diagnostics using WikiParser-Node.
import {wikilint} from '@bhsd/codemirror-wikitext';
import config from 'wikiparser-node/config/default.json' with {type: 'json'};
const extension: Extension = wikilint(
config,
// (optional) specify the linting rules; see https://github.com/bhsd-harry/wikiparser-node/wiki/Rules#configuration
// In particular, Stylelint will not be loaded if the 'invalid-css' rule is disabled.
{'invalid-css': 0},
// (optional) specify the jsDelivr CDN for loading assets, default to https://testingcf.jsdelivr.net
'https://cdn.jsdelivr.net',
);