From 6959cec1bfcd0e15ef216103ed7338d36447c4a9 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sun, 22 Oct 2017 11:22:25 -0700 Subject: [PATCH] improved code readability --- .../components/Editor/plugins/MarkdownShortcuts.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frontend/components/Editor/plugins/MarkdownShortcuts.js b/frontend/components/Editor/plugins/MarkdownShortcuts.js index 2431b973e..10fad8247 100644 --- a/frontend/components/Editor/plugins/MarkdownShortcuts.js +++ b/frontend/components/Editor/plugins/MarkdownShortcuts.js @@ -78,13 +78,16 @@ export default function MarkdownShortcuts() { const { text } = startBlock; const start = i; const end = i + shortcut.length; + const beginningOfBlock = start === 0; + const endOfBlock = end === text.length; + const surroundedByWhitespaces = [ + text.slice(start - 1, start), + text.slice(end, end + 1), + ].includes(' '); + if ( text.slice(start, end) === shortcut && - (start === 0 || - end === text.length || - [text.slice(start - 1, start), text.slice(end, end + 1)].includes( - ' ' - )) + (beginningOfBlock || endOfBlock || surroundedByWhitespaces) ) inlineTags.push(i); }