扩展:CodeMirror

This page is a translated version of the page Extension:CodeMirror and the translation is 39% complete.
MediaWiki扩展手冊
OOjs UI icon advanced-invert.svg
CodeMirror
發布狀態: 穩定版本
Pride and codemirror.png
实现 用户界面
描述 为wiki文本编辑器提供语法高亮
作者 Pavel Astakhov (pastakhov讨论)
最新版本 4.0.0
兼容性政策 快照跟随MediaWiki发布。 master分支不向後兼容。
MediaWiki 1.32+
PHP 5.3+
数据庫更改
许可协议 GNU通用公眾授權條款2.0或更新版本
下載
  • $wgCodeMirrorLineNumberingNamespaces
翻譯CodeMirror扩展,若在translatewiki.net可用

检查使用和版本矩阵。

Vagrant角色 codemirror
問題 尚未完成的工作 · 报告錯誤

CodeMirror扩展为MediaWiki中的wiki文本(源代码)编辑器提供语法高亮功能。 它会在编辑工具栏中添加一个图标为Codemirror-icon.png的按钮,点击可以切换开启和关闭语法高亮。 支持2010年WikiEditor工具栏以及可视化编辑器工具栏

语法高亮功能默认关闭。 开启功能后,它将使用CodeMirror库提供的编辑器替换标准的多行文本框。 功能关闭后,不产生效果。

The colors used in this extension have been optimised for higher contrast, accessibility and better readability and now conform to the Web Content Accessibility Guidelines (WCAG 1.4.3 AA). The colors provide better access for people with limited vision as well as for users working in bright daylight conditions.more information

Bracket matching

This feature highlights the innermost pair of brackets when the cursor lies between any bracket pair, and when the cursor lies directly next to a bracket, the feature highlights the corresponding matching bracket. Bracket matching is active in both editors when syntax highlighting is turned on in any namespace using these editors.

Line numbering

In the wikitext edit mode line numbers are automatically displayed in both editors.

This feature is enabled for the template namespace on most wiki, and on all namespaces on some wikis (see the roadmap and the configuration).

Colorblind mode

For users who have difficulty distinguishing between colors, CodeMirror offers a colorblind-friendly mode. This feature can be activated on wikis with CodeMirror enabled by navigating to the Special:Preferences page.

New preference colorblind syntax highlighting.png


With the colorblind-friendly scheme active, the colors of the following page elements change:

Headings, symbols, signatures, section names, magic words #E4A400
Templates #9C3A00
HTML tags, references, mathematical expressions #56B4E9
Variables #009E73

In addition, background highlights and colors are removed from all text and objects. Bolding and underlining behavior remains unaffected.


浏览器支持

支持所有受MediaWiki支持的浏览器。

安装


Vagrant installation:

  • 如果使用Vagrant ,请通过vagrant roles enable codemirror --provision安装

配置

颜色和样式的自定义见元维基帮助页面。 您可以使用自定义的wikitext语法高亮样式。 所用的样式在这里。 您的自定义样式应放入common.css

添加上述代码到你的LocalSettings.php 的结尾。

# Enables use of CodeMirror by default but still allow users to disable it
$wgDefaultUserOptions['usecodemirror'] = 1;

To try out the new features mentioned above in your local installation, add the following lines as well. Note: these features are intended to become default features. Once made default, these settings may no longer have an effect.

# Enable bracket matching in CodeMirror
$wgCodeMirrorEnableBracketMatching = true;

# Enable accessible colors in CodeMirror
$wgCodeMirrorAccessibilityColors = true;

# Enable line numbering in CodeMirror
# defaults to the template namespace [ NS_TEMPLATE ]
# null enables it for all namespace
# [] for disabling everywhere
$wgCodeMirrorLineNumberingNamespaces = null;

扩展集成

如果你的MediaWiki扩展添加了新的标签并且想确保CodeMirror正确高亮其中的内容,可以为你的扩展添加CodeMirror支持。两则例子:扩展扩展

JavaScript integration

The following front-end hooks are used in this extension:

Hook Parameters
Type Description
ext.CodeMirror.switch boolean Whether the CodeMirror editor is now shown
jQuery object The current "editor", which is either the normal ‎<textarea /> or the .CodeMirror element.

有待完成

参见