aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-10-05 16:39:52 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-10-05 18:58:23 +0800
commit9d88ee357060abe90c85c4ade5fca61592c0f032 (patch)
tree7dcc34b89bd936794d4139468a9e256c7f73c6db
parent7ee20b87e0ae47a5220e8e0aad5f56cf8b262f7e (diff)
fix: patch 9a0fdb9
* use attribute "xy" as title of marker * fix config for linkify
-rw-r--r--src/dumbyUtils.mjs4
-rw-r--r--src/dumbymap.mjs12
2 files changed, 7 insertions, 9 deletions
diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs
index 5de5b05..d0a3501 100644
--- a/src/dumbyUtils.mjs
+++ b/src/dumbyUtils.mjs
@@ -101,10 +101,10 @@ const getMarkersFromMaps = link => {
101 .map(map => { 101 .map(map => {
102 const renderer = map.renderer 102 const renderer = map.renderer
103 103
104 return map.querySelector(`.marker[title="${link.title}"]`) ?? 104 return map.querySelector(`.marker[title="${link.xy}"]`) ??
105 renderer.addMarker({ 105 renderer.addMarker({
106 xy: link.xy, 106 xy: link.xy,
107 title: link.title 107 title: link.xy
108 }) 108 })
109 }) 109 })
110} 110}
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs
index 512409b..7489b1a 100644
--- a/src/dumbymap.mjs
+++ b/src/dumbymap.mjs
@@ -49,20 +49,18 @@ export const markdown2HTML = (container, mdContent) => {
49 .use(MarkdownItInjectLinenumbers) 49 .use(MarkdownItInjectLinenumbers)
50 50
51 // Create links with geo scheme 51 // Create links with geo scheme
52 const coordinateRegex = /^(\D*)(-?\d+\.?\d*)\s*([,\x2F\uFF0C])\s*(-?\d+\.?\d*)/g 52 const coordinateRegex = /^(\D*)(-?\d+\.?\d*)\s*([,\x2F\uFF0C])\s*(-?\d+\.?\d*)/
53 const coordinateValue = { 53 const coordinateValue = {
54 validate: coordinateRegex, 54 validate: coordinateRegex,
55 normalize: function (match) { 55 normalize: function (match) {
56 const matches = [...match.raw.matchAll(coordinateRegex)] 56 const [, , x, sep, y] = match.text.match(coordinateRegex)
57 if (!matches[0]) return match
58 const [, , x, sep, y] = matches[0]
59 match.url = `geo:${y},${x}?xy=${x},${y}` 57 match.url = `geo:${y},${x}?xy=${x},${y}`
60 match.text = `${x}${sep}${y}` 58 match.text = `${x}${sep} ${y}`
61 match.index = match.raw.indexOf(x) 59 match.index += match.text.indexOf(x) + 1
62 return match 60 return match
63 } 61 }
64 } 62 }
65 const patterns = ['(', '📍', '\uFF08', '@', 'geo:', 'twd'] 63 const patterns = ['[', '(', '📍', '\uFF08', '@', 'geo:', 'twd']
66 patterns.forEach(prefix => 64 patterns.forEach(prefix =>
67 md.linkify.add(prefix, coordinateValue) 65 md.linkify.add(prefix, coordinateValue)
68 ) 66 )