Beispiel #1
0
        public override BlockState TryOpen(BlockProcessor processor)
        {
            if (processor.IsCodeIndent)
            {
                return(BlockState.None);
            }

            // A link must be of the form *[Some Text]: An abbreviation
            var slice         = processor.Line;
            var startPosition = slice.Start;
            var c             = slice.NextChar();

            if (c != '[')
            {
                return(BlockState.None);
            }

            SourceSpan labelSpan;

            if (!LinkHelper.TryParseLabel(ref slice, out string label, out labelSpan))
            {
                return(BlockState.None);
            }

            c = slice.CurrentChar;
            if (c != ':')
            {
                return(BlockState.None);
            }
            slice.NextChar();

            slice.Trim();

            var abbr = new Abbreviation(this)
            {
                Label     = label,
                Text      = slice,
                Span      = new SourceSpan(startPosition, slice.End),
                Line      = processor.LineIndex,
                Column    = processor.Column,
                LabelSpan = labelSpan,
            };

            if (!processor.Document.HasAbbreviations())
            {
                processor.Document.ProcessInlinesBegin += DocumentOnProcessInlinesBegin;
            }
            processor.Document.AddAbbreviation(abbr.Label, abbr);

            return(BlockState.BreakDiscard);
        }
Beispiel #2
0
        public static void AddAbbreviation(this MarkdownDocument document, string label, Abbreviation abbr)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (label == null)
            {
                throw new ArgumentNullException(nameof(label));
            }
            if (abbr == null)
            {
                throw new ArgumentNullException(nameof(abbr));
            }

            var map = document.GetAbbreviations();

            if (map == null)
            {
                map = new Dictionary <string, Abbreviation>();
                document.SetData(DocumentKey, map);
            }
            map[label] = abbr;
        }