From fa70c40b339e539800c48bd7821b47b0edc6e161 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 11 Feb 2017 23:41:57 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=A9=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/text/elements/inline-code.js | 14 ++++++++++++++ src/common/text/index.js | 3 ++- src/web/app/base.styl | 8 ++++++-- src/web/app/common/scripts/text-compiler.js | 2 ++ src/web/app/desktop/tags/timeline-post.tag | 9 +++++++-- src/web/app/mobile/tags/timeline-post.tag | 9 +++++++-- 6 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/common/text/elements/inline-code.js diff --git a/src/common/text/elements/inline-code.js b/src/common/text/elements/inline-code.js new file mode 100644 index 0000000000..d117c53a15 --- /dev/null +++ b/src/common/text/elements/inline-code.js @@ -0,0 +1,14 @@ +/** + * Code (inline) + */ + +module.exports = text => { + const match = text.match(/^`(.+?)`/); + if (!match) return null; + const code = match[0]; + return { + type: 'inline-code', + content: code, + code: code.substr(1, code.length - 2).trim() + }; +}; diff --git a/src/common/text/index.js b/src/common/text/index.js index d0ef8674b0..9da3a26b91 100644 --- a/src/common/text/index.js +++ b/src/common/text/index.js @@ -7,7 +7,8 @@ const elements = [ require('./elements/url'), require('./elements/mention'), require('./elements/hashtag'), - require('./elements/code') + require('./elements/code'), + require('./elements/inline-code') ]; function analyze(source) { diff --git a/src/web/app/base.styl b/src/web/app/base.styl index 0e5eeba971..334ef91f76 100644 --- a/src/web/app/base.styl +++ b/src/web/app/base.styl @@ -107,11 +107,15 @@ a * cursor pointer +code + font-family Consolas, 'Courier New', Courier, Monaco, monospace + pre - overflow auto + display block > code - font-family Consolas, 'Courier New', Courier, Monaco, monospace + display block + overflow auto tab-size 2 .comment diff --git a/src/web/app/common/scripts/text-compiler.js b/src/web/app/common/scripts/text-compiler.js index 25f36382fb..f47ce0f3c3 100644 --- a/src/web/app/common/scripts/text-compiler.js +++ b/src/web/app/common/scripts/text-compiler.js @@ -32,6 +32,8 @@ module.exports = function(tokens, shouldBreak, shouldEscape) { return '' + escape(token.content) + ''; case 'code': return '
' + token.codeHtml + '
'; + case 'inline-code': + return '' + escape(token.code) + ''; } }).join(''); diff --git a/src/web/app/desktop/tags/timeline-post.tag b/src/web/app/desktop/tags/timeline-post.tag index 4b9f4eec0c..1f204254d0 100644 --- a/src/web/app/desktop/tags/timeline-post.tag +++ b/src/web/app/desktop/tags/timeline-post.tag @@ -232,13 +232,18 @@ font-style oblique color #a0bf46 - pre - padding 16px + code + padding 4px 8px + margin 0 0.5em font-size 80% color #525252 background #f8f8f8 border-radius 2px + pre > code + padding 16px + margin 0 + [data-is-me]:after content "you" padding 0 4px diff --git a/src/web/app/mobile/tags/timeline-post.tag b/src/web/app/mobile/tags/timeline-post.tag index db71720574..a5a5a64f62 100644 --- a/src/web/app/mobile/tags/timeline-post.tag +++ b/src/web/app/mobile/tags/timeline-post.tag @@ -212,13 +212,18 @@ font-style oblique color #a0bf46 - pre - padding 16px + code + padding 4px 8px + margin 0 0.5em font-size 80% color #525252 background #f8f8f8 border-radius 2px + pre > code + padding 16px + margin 0 + [data-is-me]:after content "you" padding 0 4px