mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
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:
@ -61,18 +61,38 @@ class NoteViewer extends StatelessWidget {
|
|||||||
data: note.body,
|
data: note.body,
|
||||||
// selectable: false, -> making this true breaks link navigation
|
// selectable: false, -> making this true breaks link navigation
|
||||||
styleSheet: markdownStyleSheet,
|
styleSheet: markdownStyleSheet,
|
||||||
onTapLink: (String link) {
|
onTapLink: (String link) async {
|
||||||
|
var spec = link;
|
||||||
if (link.startsWith('./')) {
|
if (link.startsWith('./')) {
|
||||||
var spec = link.substring(2);
|
spec = link.substring(2);
|
||||||
|
}
|
||||||
|
|
||||||
var linkedNote = note.parent.getNoteWithSpec(spec);
|
var linkedNote = note.parent.getNoteWithSpec(spec);
|
||||||
if (linkedNote != null) {
|
if (linkedNote != null) {
|
||||||
openNoteEditor(context, linkedNote);
|
openNoteEditor(context, linkedNote);
|
||||||
} else {
|
return;
|
||||||
showSnackbar(context, "Link '$link' not found");
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Log.i("Launching $link");
|
if (!spec.endsWith('.md')) {
|
||||||
launch(link);
|
linkedNote = note.parent.getNoteWithSpec(spec + '.md');
|
||||||
|
if (linkedNote != null) {
|
||||||
|
openNoteEditor(context, linkedNote);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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(
|
imageBuilder: (url, title, alt) => kDefaultImageBuilder(
|
||||||
|
Reference in New Issue
Block a user