Example #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;
            string     label;

            if (!LinkHelper.TryParseLabel(ref slice, out 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);
        }
Example #2
0
        public static void AddAbbreviation(this MarkdownDocument document, string label, Abbreviation abbr)
        {
            if (document == null)
            {
                ThrowHelper.ArgumentNullException(nameof(document));
            }
            if (label == null)
            {
                ThrowHelper.ArgumentNullException_label();
            }
            if (abbr == null)
            {
                ThrowHelper.ArgumentNullException(nameof(abbr));
            }

            var map = document.GetAbbreviations();

            if (map == null)
            {
                map = new Dictionary <string, Abbreviation>();
                document.SetData(DocumentKey, map);
            }
            map[label] = abbr;
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AbbreviationInline"/> class.
 /// </summary>
 /// <param name="abbreviation">The abbreviation.</param>
 public AbbreviationInline(Abbreviation abbreviation)
 {
     Abbreviation = abbreviation;
 }