diff --git a/src/common/text/elements/code.js b/src/common/text/elements/code.js index a94681098a..d6dbd1cdcb 100644 --- a/src/common/text/elements/code.js +++ b/src/common/text/elements/code.js @@ -132,6 +132,35 @@ const elements = [ } }, + // regexp + code => { + if (code[0] != '/') return null; + let regexp = ''; + let thisIsNotARegexp = false; + for (let i = 1; i < code.length; i++) { + const char = code[i]; + if (char == '\\') { + i++; + continue; + } else if (char == '/') { + break; + } else if (char == '\n' || i == (code.length - 1)) { + thisIsNotARegexp = true; + break; + } else { + regexp += char; + } + } + + if (thisIsNotARegexp) return null; + if (regexp[0] == ' ' && regexp[regexp.length - 1] == ' ') return null; + + return { + html: `/${escape(regexp)}/`, + next: regexp.length + 2 + }; + }, + // extract vars (code, i, source, vars) => { const prev = source[i - 1]; diff --git a/src/web/app/base.styl b/src/web/app/base.styl index 4b107a2c98..1e26a9f85c 100644 --- a/src/web/app/base.styl +++ b/src/web/app/base.styl @@ -117,6 +117,9 @@ pre > code .string color #e96900 + .regexp + color #e9003f + .keyword color #2973b7