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:
@@ -0,0 +1,24 @@
|
||||
import 'package:markdown/markdown.dart' as md;
|
||||
|
||||
/// Parses `[[Note Title]]` wikilinks into anchor elements with a custom
|
||||
/// `wikilink://<encoded-title>` href, handled by the app's onTapLink callback.
|
||||
class WikilinkSyntax extends md.InlineSyntax {
|
||||
WikilinkSyntax() : super(r'\[\[([^\[\]\n]+)\]\]');
|
||||
|
||||
@override
|
||||
bool onMatch(md.InlineParser parser, Match match) {
|
||||
final title = match[1]!.trim();
|
||||
if (title.isEmpty) return false;
|
||||
final anchor = md.Element.text('a', title);
|
||||
anchor.attributes['href'] = 'wikilink://${Uri.encodeComponent(title)}';
|
||||
parser.addNode(anchor);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// GitHub-flavored markdown extended with [[wikilink]] support.
|
||||
/// Use this as the extensionSet wherever note bodies are rendered.
|
||||
final wikilinkExtensionSet = md.ExtensionSet(
|
||||
md.ExtensionSet.gitHubFlavored.blockSyntaxes,
|
||||
[WikilinkSyntax(), ...md.ExtensionSet.gitHubFlavored.inlineSyntaxes],
|
||||
);
|
||||
Reference in New Issue
Block a user