summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-02-09 21:47:45 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-02-09 21:47:45 +0900
commit7bec5e52becc97c4963318953ae62cefacb41339 (patch)
treedac4e185623b7e2e9ca7a395136e4c23d7cbc4f5 /src
parentAdd some symbols (diff)
downloadsharkey-7bec5e52becc97c4963318953ae62cefacb41339.tar.gz
sharkey-7bec5e52becc97c4963318953ae62cefacb41339.tar.bz2
sharkey-7bec5e52becc97c4963318953ae62cefacb41339.zip
regexp support
Diffstat (limited to 'src')
-rw-r--r--src/common/text/elements/code.js29
-rw-r--r--src/web/app/base.styl3
2 files changed, 32 insertions, 0 deletions
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: `<span class="regexp">/${escape(regexp)}/</span>`,
+ 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