Render and navigate [[wikilink]] syntax in notes
- Add WikilinkSyntax (InlineSyntax) that parses [[Note Title]] into anchor elements with a wikilink:// href - wikilinkExtensionSet extends GFM with this syntax; shared by detail view and edit preview so rendering is consistent - NoteDetailScreen handles onTapLink: wikilink:// hrefs look up the target note by title (case-insensitive) and push its detail route; unresolved links show a "Note not found" snackbar - Add markdown as an explicit dependency (was previously transitive) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../core/constants.dart';
|
||||
import '../../core/wikilink_syntax.dart';
|
||||
import '../../providers/notes_provider.dart';
|
||||
|
||||
class NoteDetailScreen extends ConsumerWidget {
|
||||
@@ -15,6 +16,22 @@ class NoteDetailScreen extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final noteAsync = ref.watch(noteDetailProvider(noteId));
|
||||
final allNotes = ref.watch(notesProvider).valueOrNull ?? [];
|
||||
|
||||
void navigateByTitle(String title) {
|
||||
final matches = allNotes.where(
|
||||
(n) => n.title.toLowerCase() == title.toLowerCase(),
|
||||
);
|
||||
if (matches.isNotEmpty) {
|
||||
context.push(
|
||||
Routes.noteDetail.replaceFirst(':id', '${matches.first.id}'),
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Note not found: "$title"')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -71,6 +88,13 @@ class NoteDetailScreen extends ConsumerWidget {
|
||||
data: (note) => Markdown(
|
||||
data: note.body,
|
||||
selectable: true,
|
||||
extensionSet: wikilinkExtensionSet,
|
||||
onTapLink: (text, href, _) {
|
||||
if (href == null) return;
|
||||
if (href.startsWith('wikilink://')) {
|
||||
navigateByTitle(Uri.decodeComponent(href.substring(11)));
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../core/exceptions.dart';
|
||||
import '../../core/wikilink_syntax.dart';
|
||||
import '../../providers/api_client_provider.dart';
|
||||
import '../../providers/notes_provider.dart';
|
||||
|
||||
@@ -149,7 +150,10 @@ class _NoteEditScreenState extends ConsumerState<NoteEditScreen> {
|
||||
const Divider(),
|
||||
Expanded(
|
||||
child: _preview
|
||||
? Markdown(data: _contentController.text)
|
||||
? Markdown(
|
||||
data: _contentController.text,
|
||||
extensionSet: wikilinkExtensionSet,
|
||||
)
|
||||
: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16),
|
||||
|
||||
Reference in New Issue
Block a user