mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +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;
|
final String tag = el.tag;
|
||||||
|
|
||||||
if (tag == 'a') {
|
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'] ?? "";
|
var title = el.attributes['title'] ?? "";
|
||||||
if (title.isEmpty) {
|
if (title.isEmpty) {
|
||||||
for (var child in el.children) {
|
for (var child in el.children) {
|
||||||
@ -53,13 +61,6 @@ class LinkExtractor implements md.NodeVisitor {
|
|||||||
links.add(link);
|
links.add(link);
|
||||||
return;
|
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) {
|
List<Link> visit(List<md.Node> nodes) {
|
||||||
@ -70,15 +71,21 @@ class LinkExtractor implements md.NodeVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parse [[term]]
|
||||||
class WikiLinkSyntax extends md.InlineSyntax {
|
class WikiLinkSyntax extends md.InlineSyntax {
|
||||||
static final String _pattern = '\\[\\[([^\\[\\]]+)\\]\\]';
|
static final String _pattern = r'\[\[([^\[\]]+)\]\]';
|
||||||
|
|
||||||
WikiLinkSyntax() : super(_pattern);
|
WikiLinkSyntax() : super(_pattern);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool onMatch(md.InlineParser parser, Match match) {
|
bool onMatch(md.InlineParser parser, Match match) {
|
||||||
md.Element el = md.Element.withTag('wikiLink');
|
var term = match[1].trim();
|
||||||
el.attributes['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);
|
parser.addNode(el);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import 'package:path/path.dart' as p;
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
|
import 'package:gitjournal/core/link.dart';
|
||||||
import 'package:gitjournal/core/note.dart';
|
import 'package:gitjournal/core/note.dart';
|
||||||
import 'package:gitjournal/core/notes_folder_fs.dart';
|
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||||
import 'package:gitjournal/folder_views/common.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
|
// It's important to add both these inline syntaxes before the other
|
||||||
// syntaxes as the LinkSyntax intefers with both of these
|
// syntaxes as the LinkSyntax intefers with both of these
|
||||||
var markdownExtensions = md.ExtensionSet.gitHubFlavored;
|
var markdownExtensions = md.ExtensionSet.gitHubFlavored;
|
||||||
markdownExtensions.inlineSyntaxes.insert(0, WikiLinkSyntax2());
|
markdownExtensions.inlineSyntaxes.insert(0, WikiLinkSyntax());
|
||||||
markdownExtensions.inlineSyntaxes.insert(1, TaskListSyntax());
|
markdownExtensions.inlineSyntaxes.insert(1, TaskListSyntax());
|
||||||
|
|
||||||
final rootFolder = Provider.of<NotesFolderFS>(context);
|
final rootFolder = Provider.of<NotesFolderFS>(context);
|
||||||
@ -227,23 +228,3 @@ Widget _handleDataSchemeUri(Uri uri, final double width, final double height) {
|
|||||||
}
|
}
|
||||||
return const SizedBox();
|
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