From 7bec5e52becc97c4963318953ae62cefacb41339 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Feb 2017 21:47:45 +0900 Subject: [PATCH] regexp support --- src/common/text/elements/code.js | 29 +++++++++++++++++++++++++++++ src/web/app/base.styl | 3 +++ 2 files changed, 32 insertions(+) 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