扩展:CodeMirror

This page is a translated version of the page Extension:CodeMirror and the translation is 41% 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
Quarterly downloads 404 (Ranked 25th)
Public wikis using 2,702 (Ranked 39th)
翻譯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 only for the template namespace on most wikis, 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安装:

  • 如果使用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 enable additional features:

# Restrict line numbering to specific namespaces.
# Defaults to null, which enables it for all namespaces.
# Set to [] to disable everywhere.
$wgCodeMirrorLineNumberingNamespaces = [ NS_TEMPLATE ];

扩展集成

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

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.

If you need to interact with the contents of a CodeMirror instance, use jQuery.plugin.textSelection.

有待完成

  • Unfortunately, right-to-left content is not supported. (task T170001)
  • 高亮定义列表( ;foo :bar ) (task T170042)
  • 自动完成(task T95100
  • 代码折叠 (task T166098)
  • 高亮gallery标签中的内容(<gallery> foo | bar </gallery>)


参见