Пример #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);
        }
 public void Set(string label, LinkReferenceDefinition link)
 {
     Links[label] = link ?? throw new ArgumentNullException(nameof(link));
     if (!Contains(link))
     {
         Add(link);
     }
 }
Пример #3
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 TryParseTrivia <T>(
            ref T text,
            [NotNullWhen(true)] out LinkReferenceDefinition?block,
            out SourceSpan triviaBeforeLabel,
            out SourceSpan labelWithTrivia,
            out SourceSpan triviaBeforeUrl,
            out SourceSpan unescapedUrl,
            out SourceSpan triviaBeforeTitle,
            out SourceSpan unescapedTitle,
            out SourceSpan triviaAfterTitle) where T : ICharIterator
        {
            block = null;

            var startSpan = text.Start;

            if (!LinkHelper.TryParseLinkReferenceDefinitionTrivia(
                    ref text,
                    out triviaBeforeLabel,
                    out string?label,
                    out labelWithTrivia,
                    out triviaBeforeUrl,
                    out string?url,
                    out unescapedUrl,
                    out bool urlHasPointyBrackets,
                    out triviaBeforeTitle,
                    out string?title,
                    out unescapedTitle,
                    out char titleEnclosingCharacter,
                    out NewLine newLine,
                    out triviaAfterTitle,
                    out SourceSpan labelSpan,
                    out SourceSpan urlSpan,
                    out SourceSpan titleSpan))
            {
                return(false);
            }

            block = new LinkReferenceDefinition(label, url, title)
            {
                UrlHasPointyBrackets    = urlHasPointyBrackets,
                TitleEnclosingCharacter = titleEnclosingCharacter,
                //LabelWithWhitespace = labelWithWhitespace,
                LabelSpan = labelSpan,
                UrlSpan   = urlSpan,
                //UnescapedUrl = unescapedUrl,
                //UnescapedTitle = unescapedTitle,
                TitleSpan = titleSpan,
                Span      = new SourceSpan(startSpan, titleSpan.End > 0 ? titleSpan.End : urlSpan.End),
                NewLine   = newLine,
            };
            return(true);
        }
Пример #4
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;
         }
     }
 }
        /// <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 successfull; <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;

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

            block = new LinkReferenceDefinition(label, url, title);
            return(true);
        }
        public static bool TryGetLinkReferenceDefinition(this MarkdownDocument document, string label, out LinkReferenceDefinition linkReferenceDefinition)
        {
            if (label == null)
            {
                ThrowHelper.ArgumentNullException_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)
            {
                ThrowHelper.ArgumentNullException_label();
            }
            var references = document.GetLinkReferenceDefinitions();

            references.Set(label, linkReferenceDefinition);
        }
Пример #8
0
 public bool TryGet(string label, out LinkReferenceDefinition link)
 {
     return(Links.TryGetValue(label, out link));
 }