mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 03:19:11 +08:00
Remove wikilink duplicate regexp
This commit is contained in:
@ -39,6 +39,14 @@ class LinkExtractor implements md.NodeVisitor {
|
||||
final String tag = el.tag;
|
||||
|
||||
if (tag == 'a') {
|
||||
var type = el.attributes['type'] ?? "";
|
||||
if (type == "wiki") {
|
||||
var term = el.attributes['term'];
|
||||
var link = Link(term: term, filePath: null);
|
||||
links.add(link);
|
||||
return;
|
||||
}
|
||||
|
||||
var title = el.attributes['title'] ?? "";
|
||||
if (title.isEmpty) {
|
||||
for (var child in el.children) {
|
||||
@ -53,13 +61,6 @@ class LinkExtractor implements md.NodeVisitor {
|
||||
links.add(link);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tag == 'wikiLink') {
|
||||
var term = el.attributes['term'];
|
||||
var link = Link(term: term, filePath: null);
|
||||
links.add(link);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
List<Link> visit(List<md.Node> nodes) {
|
||||
@ -70,15 +71,21 @@ class LinkExtractor implements md.NodeVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse [[term]]
|
||||
class WikiLinkSyntax extends md.InlineSyntax {
|
||||
static final String _pattern = '\\[\\[([^\\[\\]]+)\\]\\]';
|
||||
static final String _pattern = r'\[\[([^\[\]]+)\]\]';
|
||||
|
||||
WikiLinkSyntax() : super(_pattern);
|
||||
|
||||
@override
|
||||
bool onMatch(md.InlineParser parser, Match match) {
|
||||
md.Element el = md.Element.withTag('wikiLink');
|
||||
el.attributes['term'] = '${match[1].trim()}';
|
||||
var term = match[1].trim();
|
||||
|
||||
var el = md.Element('a', [md.Text(term)]);
|
||||
el.attributes['type'] = 'wiki';
|
||||
el.attributes['href'] = '[[$term]]';
|
||||
el.attributes['term'] = term;
|
||||
|
||||
parser.addNode(el);
|
||||
return true;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import 'package:path/path.dart' as p;
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'package:gitjournal/core/link.dart';
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||
import 'package:gitjournal/folder_views/common.dart';
|
||||
@ -57,7 +58,7 @@ class NoteViewer extends StatelessWidget {
|
||||
// It's important to add both these inline syntaxes before the other
|
||||
// syntaxes as the LinkSyntax intefers with both of these
|
||||
var markdownExtensions = md.ExtensionSet.gitHubFlavored;
|
||||
markdownExtensions.inlineSyntaxes.insert(0, WikiLinkSyntax2());
|
||||
markdownExtensions.inlineSyntaxes.insert(0, WikiLinkSyntax());
|
||||
markdownExtensions.inlineSyntaxes.insert(1, TaskListSyntax());
|
||||
|
||||
final rootFolder = Provider.of<NotesFolderFS>(context);
|
||||
@ -227,23 +228,3 @@ Widget _handleDataSchemeUri(Uri uri, final double width, final double height) {
|
||||
}
|
||||
return const SizedBox();
|
||||
}
|
||||
|
||||
/// Parse [[term]]
|
||||
class WikiLinkSyntax2 extends md.InlineSyntax {
|
||||
static final String _pattern = r'\[\[([^\[\]]+)\]\]';
|
||||
|
||||
WikiLinkSyntax2() : super(_pattern);
|
||||
|
||||
@override
|
||||
bool onMatch(md.InlineParser parser, Match match) {
|
||||
// print("-------- WIKI LINK -------");
|
||||
var term = match[1].trim();
|
||||
|
||||
var el = md.Element('a', [md.Text(term)]);
|
||||
el.attributes['type'] = 'wiki';
|
||||
el.attributes['href'] = '[[$term]]';
|
||||
|
||||
parser.addNode(el);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user