: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../python/python"), require("../stex/stex"), require("../../addon/mode/overlay"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../python/python", "../stex/stex", "../../addon/mode/overlay"], mod);
else // Plain browser env
})(function(CodeMirror) {
CodeMirror.defineMode('rst', function (config, options) {
var rx_strong = /^\*\*[^\*\s](?:[^\*]*[^\*\s])?\*\*/;
var rx_emphasis = /^\*[^\*\s](?:[^\*]*[^\*\s])?\*/;
var rx_literal = /^``[^`\s](?:[^`]*[^`\s])``/;
var rx_number = /^(?:[\d]+(?:[\.,]\d+)*)/;
var rx_positive = /^(?:\s\+[\d]+(?:[\.,]\d+)*)/;
var rx_negative = /^(?:\s\-[\d]+(?:[\.,]\d+)*)/;
var rx_uri_protocol = "[Hh][Tt][Tt][Pp][Ss]?://";
var rx_uri_domain = "(?:[\\d\\w.-]+)\\.(?:\\w{2,6})";
var rx_uri_path = "(?:/[\\d\\w\\#\\%\\&\\-\\.\\,\\/\\:\\=\\?\\~]+)*";
var rx_uri = new RegExp("^" + rx_uri_protocol + rx_uri_domain + rx_uri_path);
token: function (stream) {
if (stream.match(rx_strong) && stream.match (/\W+|$/, false))
if (stream.match(rx_emphasis) && stream.match (/\W+|$/, false))
if (stream.match(rx_literal) && stream.match (/\W+|$/, false))
if (stream.match(rx_number))
if (stream.match(rx_positive))
if (stream.match(rx_negative))
if (stream.match(rx_uri))
while (stream.next() != null) {
if (stream.match(rx_strong, false)) break;
if (stream.match(rx_emphasis, false)) break;
if (stream.match(rx_literal, false)) break;
if (stream.match(rx_number, false)) break;
if (stream.match(rx_positive, false)) break;
if (stream.match(rx_negative, false)) break;
if (stream.match(rx_uri, false)) break;
var mode = CodeMirror.getMode(
config, options.backdrop || 'rst-base'
return CodeMirror.overlayMode(mode, overlay, true); // combine
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
CodeMirror.defineMode('rst-base', function (config) {
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function format(string) {
var args = Array.prototype.slice.call(arguments, 1);
return string.replace(/{(\d+)}/g, function (match, n) {
return typeof args[n] != 'undefined' ? args[n] : match;
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
var mode_python = CodeMirror.getMode(config, 'python');
var mode_stex = CodeMirror.getMode(config, 'stex');
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
var TAIL = "(?:\\s*|\\W|$)",
rx_TAIL = new RegExp(format('^{0}', TAIL));
"(?:[^\\W\\d_](?:[\\w!\"#$%&'()\\*\\+,\\-\\.\/:;<=>\\?]*[^\\W_])?)",
rx_NAME = new RegExp(format('^{0}', NAME));
"(?:[^\\W\\d_](?:[\\w\\s!\"#$%&'()\\*\\+,\\-\\.\/:;<=>\\?]*[^\\W_])?)";
var REF_NAME = format('(?:{0}|`{1}`)', NAME, NAME_WWS);
var TEXT1 = "(?:[^\\s\\|](?:[^\\|]*[^\\s\\|])?)";
var TEXT2 = "(?:[^\\`]+)",
rx_TEXT2 = new RegExp(format('^{0}', TEXT2));
var rx_section = new RegExp(
"^([!'#$%&\"()*+,-./:;<=>?@\\[\\\\\\]^_`{|}~])\\1{3,}\\s*$");
var rx_explicit = new RegExp(
format('^\\.\\.{0}', SEPA));
var rx_link = new RegExp(
format('^_{0}:{1}|^__:{1}', REF_NAME, TAIL));
var rx_directive = new RegExp(
format('^{0}::{1}', REF_NAME, TAIL));
var rx_substitution = new RegExp(
format('^\\|{0}\\|{1}{2}::{3}', TEXT1, SEPA, REF_NAME, TAIL));
var rx_footnote = new RegExp(
format('^\\[(?:\\d+|#{0}?|\\*)]{1}', REF_NAME, TAIL));
var rx_citation = new RegExp(
format('^\\[{0}\\]{1}', REF_NAME, TAIL));
var rx_substitution_ref = new RegExp(
format('^\\|{0}\\|', TEXT1));
var rx_footnote_ref = new RegExp(
format('^\\[(?:\\d+|#{0}?|\\*)]_', REF_NAME));
var rx_citation_ref = new RegExp(
format('^\\[{0}\\]_', REF_NAME));
var rx_link_ref1 = new RegExp(
format('^{0}__?', REF_NAME));
var rx_link_ref2 = new RegExp(
format('^`{0}`_', TEXT2));
var rx_role_pre = new RegExp(
format('^:{0}:`{1}`{2}', NAME, TEXT2, TAIL));
var rx_role_suf = new RegExp(
format('^`{1}`:{0}:{2}', NAME, TEXT2, TAIL));
var rx_role = new RegExp(
format('^:{0}:{1}', NAME, TAIL));
var rx_directive_name = new RegExp(format('^{0}', REF_NAME));
var rx_directive_tail = new RegExp(format('^::{0}', TAIL));
var rx_substitution_text = new RegExp(format('^\\|{0}\\|', TEXT1));
var rx_substitution_sepa = new RegExp(format('^{0}', SEPA));
var rx_substitution_name = new RegExp(format('^{0}', REF_NAME));
var rx_substitution_tail = new RegExp(format('^::{0}', TAIL));
var rx_link_head = new RegExp("^_");
var rx_link_name = new RegExp(format('^{0}|_', REF_NAME));
var rx_link_tail = new RegExp(format('^:{0}', TAIL));
var rx_verbatim = new RegExp('^::\\s*$');
var rx_examples = new RegExp('^\\s+(?:>>>|In \\[\\d+\\]:)\\s');
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function to_normal(stream, state) {
if (stream.sol() && stream.match(rx_examples, false)) {
mode: mode_python, local: CodeMirror.startState(mode_python)
} else if (stream.sol() && stream.match(rx_explicit)) {
change(state, to_explicit);
} else if (stream.sol() && stream.match(rx_section)) {
change(state, to_normal);
} else if (phase(state) == rx_role_pre ||
stream.match(rx_role_pre, false)) {
change(state, to_normal, context(rx_role_pre, 1));
change(state, to_normal, context(rx_role_pre, 2));
if (stream.current().match(/^(?:math|latex)/)) {
change(state, to_normal, context(rx_role_pre, 3));
state.tmp_stex = undefined; state.tmp = {
mode: mode_stex, local: CodeMirror.startState(mode_stex)
if (stream.peek() == '`') {
change(state, to_normal, context(rx_role_pre, 4));
token = state.tmp.mode.token(stream, state.tmp.local);
change(state, to_normal, context(rx_role_pre, 4));
change(state, to_normal, context(rx_role_pre, 5));
change(state, to_normal, context(rx_role_pre, 6));
change(state, to_normal);
} else if (phase(state) == rx_role_suf ||
stream.match(rx_role_suf, false)) {
change(state, to_normal, context(rx_role_suf, 1));
change(state, to_normal, context(rx_role_suf, 2));
change(state, to_normal, context(rx_role_suf, 3));
change(state, to_normal, context(rx_role_suf, 4));
change(state, to_normal, context(rx_role_suf, 5));
change(state, to_normal, context(rx_role_suf, 6));
change(state, to_normal);
} else if (phase(state) == rx_role || stream.match(rx_role, false)) {
change(state, to_normal, context(rx_role, 1));
change(state, to_normal, context(rx_role, 2));
change(state, to_normal, context(rx_role, 3));
change(state, to_normal, context(rx_role, 4));
change(state, to_normal);
} else if (phase(state) == rx_substitution_ref ||
stream.match(rx_substitution_ref, false)) {
change(state, to_normal, context(rx_substitution_ref, 1));
stream.match(rx_substitution_text);
change(state, to_normal, context(rx_substitution_ref, 2));
if (stream.match(/^_?_?/)) token = 'link';
change(state, to_normal);
} else if (stream.match(rx_footnote_ref)) {
change(state, to_normal);
} else if (stream.match(rx_citation_ref)) {
change(state, to_normal);
} else if (stream.match(rx_link_ref1)) {
change(state, to_normal);
if (!stream.peek() || stream.peek().match(/^\W$/)) {
} else if (phase(state) == rx_link_ref2 ||
stream.match(rx_link_ref2, false)) {
if (!stream.peek() || stream.peek().match(/^\W$/)) {
change(state, to_normal, context(rx_link_ref2, 1));
stream.match(rx_link_ref2);
change(state, to_normal, context(rx_link_ref2, 2));
change(state, to_normal, context(rx_link_ref2, 3));
change(state, to_normal, context(rx_link_ref2, 4));
change(state, to_normal);
} else if (stream.match(rx_verbatim)) {
change(state, to_verbatim);
if (stream.next()) change(state, to_normal);
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function to_explicit(stream, state) {
if (phase(state) == rx_substitution ||
stream.match(rx_substitution, false)) {
change(state, to_explicit, context(rx_substitution, 1));
stream.match(rx_substitution_text);
change(state, to_explicit, context(rx_substitution, 2));
stream.match(rx_substitution_sepa);
change(state, to_explicit, context(rx_substitution, 3));
stream.match(rx_substitution_name);
change(state, to_explicit, context(rx_substitution, 4));
stream.match(rx_substitution_tail);
change(state, to_normal);
} else if (phase(state) == rx_directive ||
stream.match(rx_directive, false)) {
change(state, to_explicit, context(rx_directive, 1));
stream.match(rx_directive_name);
if (stream.current().match(/^(?:math|latex)/))
else if (stream.current().match(/^python/))
change(state, to_explicit, context(rx_directive, 2));
stream.match(rx_directive_tail);
if (stream.match(/^latex\s*$/) || state.tmp_stex) {
state.tmp_stex = undefined; change(state, to_mode, {
mode: mode_stex, local: CodeMirror.startState(mode_stex)
change(state, to_explicit, context(rx_directive, 3));
if (stream.match(/^python\s*$/) || state.tmp_py) {
state.tmp_py = undefined; change(state, to_mode, {
mode: mode_python, local: CodeMirror.startState(mode_python)
change(state, to_normal);
} else if (phase(state) == rx_link || stream.match(rx_link, false)) {
change(state, to_explicit, context(rx_link, 1));
stream.match(rx_link_head);
stream.match(rx_link_name);
change(state, to_explicit, context(rx_link, 2));
stream.match(rx_link_tail);
change(state, to_normal);
} else if (stream.match(rx_footnote)) {
change(state, to_normal);
} else if (stream.match(rx_citation)) {
change(state, to_normal);
change(state, to_normal);
change(state, to_comment);
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function to_comment(stream, state) {
return as_block(stream, state, 'comment');
function to_verbatim(stream, state) {
return as_block(stream, state, 'meta');
function as_block(stream, state, token) {
if (stream.eol() || stream.eatSpace()) {
change(state, to_normal);
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function to_mode(stream, state) {
if (state.ctx.mode && state.ctx.local) {
if (!stream.eatSpace()) change(state, to_normal);
return state.ctx.mode.token(stream, state.ctx.local);
change(state, to_normal);
///////////////////////////////////////////////////////////////////////////