Check for .md file existence on link click.

This commit is contained in:
Clément
2019-08-20 15:23:09 +02:00
parent 9b36458eff
commit 283f992512
+16 -1
View File
@@ -1927,7 +1927,22 @@ current file somewhere to enable this feature.", \
- (void)openOrCreateFileForUrl:(NSURL *)url
{
// Simply open the file if it is not local, or exists already.
if (!url.isFileURL || [url checkResourceIsReachableAndReturnError:NULL])
BOOL file = url.isFileURL;
BOOL reachable = !file || [url checkResourceIsReachableAndReturnError:NULL];
// If the file is local but doesn't exist, check if a file with
// the .md extension exists.
if (file && !reachable && [url.pathExtension isEqualToString:@""])
{
NSURL *markdownURL = [url URLByAppendingPathExtension:@"md"];
if ([markdownURL checkResourceIsReachableAndReturnError:NULL])
{
reachable = YES;
url = markdownURL;
}
}
if (reachable)
{
[[NSWorkspace sharedWorkspace] openURL:url];
return;