This repository has been archived on 2026-06-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
FabledApp/lib/core/wikilink_syntax.dart
T
bvandeusen 3c5f932327 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>
2026-03-01 12:55:06 -05:00

25 lines
919 B
Dart

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],
);