Fix relative Markdown links

While implementing Wiki Links, I seem to have accidentally broken them.
This commit is contained in:
Vishesh Handa
2020-08-14 16:14:00 +02:00
parent 5066a2a729
commit bf97887e10
2 changed files with 16 additions and 4 deletions

View File

@ -9,11 +9,14 @@ class LinkResolver {
Note resolve(String link) {
var spec = link;
var rootFolder = inputNote.parent.rootFolder;
var folder = inputNote.parent;
if (link.startsWith('[[') && link.endsWith(']]') && link.length > 4) {
// FIXME: What if the case is different?
spec = link.substring(2, link.length - 2).trim();
// In the case of Wiki Links we always resolve from the Root Folder
folder = inputNote.parent.rootFolder;
}
if (link.startsWith('./')) {
@ -24,20 +27,20 @@ class LinkResolver {
spec = p.normalize(spec);
}
var linkedNote = rootFolder.getNoteWithSpec(spec);
var linkedNote = folder.getNoteWithSpec(spec);
if (linkedNote != null) {
return linkedNote;
}
if (!spec.endsWith('.md')) {
linkedNote = rootFolder.getNoteWithSpec(spec + '.md');
linkedNote = folder.getNoteWithSpec(spec + '.md');
if (linkedNote != null) {
return linkedNote;
}
}
if (!spec.endsWith('.txt')) {
linkedNote = rootFolder.getNoteWithSpec(spec + '.txt');
linkedNote = folder.getNoteWithSpec(spec + '.txt');
if (linkedNote != null) {
return linkedNote;
}