Просмотр исходного кода

fix convert to md link with relative path

yusuketk 5 лет назад
Родитель
Сommit
fbc3385c0b
1 измененных файлов с 8 добавлено и 1 удалено
  1. 8 1
      src/client/js/components/PageEditor/LinkEditModal.jsx

+ 8 - 1
src/client/js/components/PageEditor/LinkEditModal.jsx

@@ -187,7 +187,14 @@ class LinkEditModal extends React.PureComponent {
 
     let reshapedLink = linkInputValue;
     if (isUseRelativePath && linkInputValue.match(/^\//)) {
-      reshapedLink = path.relative(pageContainer.state.path, linkInputValue);
+      const pagePath = pageContainer.state.path;
+      // rootPaths of md link and pukiwiki link are different
+      const rootPath = linkerType === Linker.types.markdownLink ? path.dirname(pagePath) : pagePath;
+      reshapedLink = path.relative(rootPath, linkInputValue);
+      if (!reshapedLink.startsWith('.')) {
+        reshapedLink = `./${reshapedLink}`;
+
+      }
     }
 
     return new Linker(