Beispiel #1
0
        /// <summary>
        /// Tries to the parse the specified text into a definition.
        /// </summary>
        /// <typeparam name="T">Type of the text</typeparam>
        /// <param name="text">The text.</param>
        /// <param name="block">The block.</param>
        /// <returns><c>true</c> if parsing is successful; <c>false</c> otherwise</returns>
        public static bool TryParse<T>(ref T text, out LinkReferenceDefinition block) where T : ICharIterator
        {
            block = null;
            string label;
            string url;
            string title;
            SourceSpan labelSpan;
            SourceSpan urlSpan;
            SourceSpan titleSpan;

            var startSpan = text.Start;

            if (!LinkHelper.TryParseLinkReferenceDefinition(ref text, out label, out url, out title, out labelSpan, out urlSpan, out titleSpan))
            {
                return false;
            }

            block = new LinkReferenceDefinition(label, url, title)
            {
                LabelSpan = labelSpan,
                UrlSpan = urlSpan,
                TitleSpan = titleSpan,
                Span = new SourceSpan(startSpan, titleSpan.End > 0 ? titleSpan.End: urlSpan.End)
            };
            return true;
        }
Beispiel #2
0
 public void Set(string label, LinkReferenceDefinition link)
 {
     if (link == null)
     {
         throw new ArgumentNullException(nameof(link));
     }
     if (!Contains(link))
     {
         Add(link);
         if (!Links.ContainsKey(label))
         {
             Links[label] = link;
         }
     }
 }
        public static bool TryGetLinkReferenceDefinition(this MarkdownDocument document, string label, out LinkReferenceDefinition linkReferenceDefinition)
        {
            if (label == null)
            {
                throw new ArgumentNullException(nameof(label));
            }
            linkReferenceDefinition = null;
            var references = document.GetData(DocumentKey) as LinkReferenceDefinitionGroup;

            if (references == null)
            {
                return(false);
            }
            return(references.TryGet(label, out linkReferenceDefinition));
        }
        public static void SetLinkReferenceDefinition(this MarkdownDocument document, string label, LinkReferenceDefinition linkReferenceDefinition)
        {
            if (label == null)
            {
                throw new ArgumentNullException(nameof(label));
            }
            var references = document.GetLinkReferenceDefinitions();

            references.Set(label, linkReferenceDefinition);
        }
Beispiel #5
0
 public bool TryGet(string label, out LinkReferenceDefinition link)
 {
     return(Links.TryGetValue(label, out link));
 }