From 3652b19e99a3fdd114dd26c94a9552c47ad3f8e0 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sat, 21 Oct 2017 17:16:07 -0700 Subject: [PATCH] Only use inline tags if they have space around them --- .../components/Editor/plugins/MarkdownShortcuts.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/components/Editor/plugins/MarkdownShortcuts.js b/frontend/components/Editor/plugins/MarkdownShortcuts.js index de530b00..2431b973 100644 --- a/frontend/components/Editor/plugins/MarkdownShortcuts.js +++ b/frontend/components/Editor/plugins/MarkdownShortcuts.js @@ -73,8 +73,19 @@ export default function MarkdownShortcuts() { let { mark, shortcut } = key; let inlineTags = []; + // only add tags if they have spaces around them or the tag is beginning or the end of the block for (let i = 0; i < startBlock.text.length; i++) { - if (startBlock.text.slice(i, i + shortcut.length) === shortcut) + const { text } = startBlock; + const start = i; + const end = i + shortcut.length; + if ( + text.slice(start, end) === shortcut && + (start === 0 || + end === text.length || + [text.slice(start - 1, start), text.slice(end, end + 1)].includes( + ' ' + )) + ) inlineTags.push(i); }