Trim note name when creating wikilink + formatting
authorAdam Dullage <redacted>
Wed, 22 Nov 2023 12:44:52 +0000 (12:44 +0000)
committerAdam Dullage <redacted>
Wed, 22 Nov 2023 12:44:52 +0000 (12:44 +0000)
flatnotes/src/autolinkParsers.js

index cc658950e958bb4de913ca6cbfa51853f88ab4a5..aaf74a43cb43c1ea546f95e7785ceeec3f0be1e5 100644 (file)
@@ -1,13 +1,13 @@
 function parseWikiLink(source) {
   const matched = source.matchAll(/\[\[(.*)\]\]/g);
   if (matched) {
-    return Array.from(matched).map(match => {
+    return Array.from(matched).map((match) => {
       const text = match[1];
       return {
         text,
-        url: encodeURI(`/note/${text}`),
-        range: [match.index, match.index + match[0].length - 1]
-      }
+        url: encodeURI(`/note/${text.trim()}`),
+        range: [match.index, match.index + match[0].length - 1],
+      };
     });
   }
 
@@ -15,9 +15,11 @@ function parseWikiLink(source) {
 }
 
 export function extendedAutolinks(source) {
-  return [...parseUrlLink(source), ...parseEmailLink(source), ...parseWikiLink(source)].sort(
-    (a, b) => a.range[0] - b.range[0]
-  );
+  return [
+    ...parseUrlLink(source),
+    ...parseEmailLink(source),
+    ...parseWikiLink(source),
+  ].sort((a, b) => a.range[0] - b.range[0]);
 }
 
 /*
git clone https://git.99rst.org/PROJECT