Detect all kinds of local links

Not only links which start with ./

We also try to guess with the .md or .txt extension if the file is
present.

Fixes #173
This commit is contained in:
Vishesh Handa
2020-07-07 23:27:44 +02:00
parent 23f259dc60
commit 7506e3990d

View File

@ -61,18 +61,38 @@ class NoteViewer extends StatelessWidget {
data: note.body,
// selectable: false, -> making this true breaks link navigation
styleSheet: markdownStyleSheet,
onTapLink: (String link) {
onTapLink: (String link) async {
var spec = link;
if (link.startsWith('./')) {
var spec = link.substring(2);
var linkedNote = note.parent.getNoteWithSpec(spec);
spec = link.substring(2);
}
var linkedNote = note.parent.getNoteWithSpec(spec);
if (linkedNote != null) {
openNoteEditor(context, linkedNote);
return;
}
if (!spec.endsWith('.md')) {
linkedNote = note.parent.getNoteWithSpec(spec + '.md');
if (linkedNote != null) {
openNoteEditor(context, linkedNote);
} else {
showSnackbar(context, "Link '$link' not found");
return;
}
} else {
Log.i("Launching $link");
launch(link);
}
if (!spec.endsWith('.txt')) {
linkedNote = note.parent.getNoteWithSpec(spec + '.txt');
if (linkedNote != null) {
openNoteEditor(context, linkedNote);
return;
}
}
try {
await launch(link);
} catch (e, stackTrace) {
Log.e("Opening Link", ex: e, stacktrace: stackTrace);
showSnackbar(context, "Link '$link' not found");
}
},
imageBuilder: (url, title, alt) => kDefaultImageBuilder(