WikiLinkSyntax: Add option of telling it which style

Obsidian or Dendron
This commit is contained in:
Vishesh Handa
2021-03-18 15:04:25 +01:00
parent b3972beb0c
commit f6f0f5a9a6

View File

@ -132,16 +132,25 @@ class LinkExtractor implements md.NodeVisitor {
class WikiLinkSyntax extends md.InlineSyntax {
static final String _pattern = r'\[\[([^\[\]]+)\]\]';
WikiLinkSyntax() : super(_pattern);
// In Obsidian style, the link is like [[fileToLinkTo|display text]]
final bool obsidianStyle;
WikiLinkSyntax({this.obsidianStyle = true}) : super(_pattern);
@override
bool onMatch(md.InlineParser parser, Match match) {
var term = match[1].trim();
var displayText = term;
if (term.contains('|')) {
var s = term.split('|');
term = s[0].trimRight();
displayText = s[1].trimLeft();
if (obsidianStyle) {
term = s[0].trimRight();
displayText = s[1].trimLeft();
} else {
displayText = s[0].trimRight();
term = s[1].trimLeft();
}
}
var el = md.Element('a', [md.Text(displayText)]);