Beispiel #1
0
        private WikiLink ParseWikiLink()
        {
            // Note that wikilink cannot nest itself.
            ParseStart(@"\||\n|\[\[|\]\]", true);
            if (ConsumeToken(@"\[\[") == null)
            {
                return(ParseFailed <WikiLink>());
            }
            var target = new Run();

            if (!ParseRun(RunParsingMode.ExpandableText, target, true))
            {
                if (options.AllowEmptyWikiLinkTarget)
                {
                    target = null;
                }
                else
                {
                    return(ParseFailed <WikiLink>());
                }
            }
            var node = new WikiLink {
                Target = target
            };

            if (ConsumeToken(@"\|") != null)
            {
                var text = new Run();
                // Text accepts pipe
                CurrentContext.Terminator = Terminator.Get(@"\n|\[\[|\]\]");
                // For [[target|]], Text == Empty Run
                // For [[target]], Text == null
                if (ParseRun(RunParsingMode.ExpandableText, text, true))
                {
                    node.Text = text;
                }
            }
            if (ConsumeToken(@"\]\]") == null)
            {
                if (options.AllowClosingMarkInference)
                {
                    node.SetInferredClosingMark();
                }
                else
                {
                    return(ParseFailed <WikiLink>());
                }
            }
            return(ParseSuccessful(node));
        }