aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/editor.mjs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/editor.mjs b/src/editor.mjs
index 8fe8c0b..71e66be 100644
--- a/src/editor.mjs
+++ b/src/editor.mjs
@@ -12,6 +12,8 @@ const context = document.querySelector('[data-mode]')
12const dumbyContainer = document.querySelector('.DumbyMap') 12const dumbyContainer = document.querySelector('.DumbyMap')
13const textArea = document.querySelector('.editor textarea') 13const textArea = document.querySelector('.editor textarea')
14let dumbymap 14let dumbymap
15
16const refLinkPattern = /\[([^\[\]]+)\]:\s+(.+)/
15let refLinks = [] 17let refLinks = []
16 18
17/** 19/**
@@ -196,7 +198,7 @@ const cm = editor.codemirror
196const getRefLinks = () => editor.value() 198const getRefLinks = () => editor.value()
197 .split('\n') 199 .split('\n')
198 .map(line => { 200 .map(line => {
199 const [, ref, link] = line.match(/\[([^\[\]]+)\]:\s+(.+)/) ?? [] 201 const [, ref, link] = line.match(refLinkPattern) ?? []
200 return { ref, link } 202 return { ref, link }
201 }) 203 })
202 .filter(({ ref, link }) => ref && link) 204 .filter(({ ref, link }) => ref && link)
@@ -432,7 +434,11 @@ const menuForEditor = (event, menu) => {
432 } 434 }
433 while (refLinks.find(({ref}) => ref === anchorName)) 435 while (refLinks.find(({ref}) => ref === anchorName))
434 436
435 cm.replaceRange(`\n[${anchorName}]: ${link}`, { line: Infinity }) 437 const lastLineIsRefLink = cm.getLine(cm.lastLine()).match(refLinkPattern)
438 cm.replaceRange(
439 `${lastLineIsRefLink ? '' : '\n'}\n[${anchorName}]: ${link}`,
440 { line: Infinity }
441 )
436 } 442 }
437 }) 443 })
438 menu.insertBefore(item, menu.firstChild) 444 menu.insertBefore(item, menu.firstChild)