扩展:CodeMirror

From mediawiki.org
Jump to navigation Jump to search
This page is a translated version of the page Extension:CodeMirror and the translation is 60% 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或更新版本
下载
  • $wgCodeMirrorEnableBracketMatching
  • $wgCodeMirrorAccessibilityColors
  • $wgCodeMirrorLineNumberingNamespaces
翻譯CodeMirror擴充功能如在translatewiki.net可用

检查使用和版本矩阵。

Vagrant角色 codemirror
问题 尚未完成的工作 · 回報錯誤

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

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

The colors used in this extension have been optimised to provide higher contrast, accessibility and better readability.

Please note though, that the updated color scheme is currently only enabled by default for some wikis (see roadmap and configuration).

Bracket matching

This feature allows highlighting of the closest matching pair of surrounding brackets while navigating through wikitext code using the cursor. Bracket matching will be active in both editors when syntax highlighting is turned on, in any namespace using these editors.

Please note that bracket matching is only enabled by default in some wikis (see roadmap and configuration).

Line numbering

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

Please note that this feature is only enabled for the template namespace on most wikis (see roadmap and configuration).

浏览器支持

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

安装

  • 如果使用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. Please note though, that these features are meant to become default features. The settings might not have an effect any more then.

# 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支持。两则例子: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.

有待完成

  • 高亮定义列表( ;foo :bar ) (phab:T170042)
  • 自动完成(phab:T95100
  • 代码折叠 T166098
  • 高亮gallery标签中的内容(<gallery> foo | bar </gallery>)

参见