Beispiel #1
0
        private static bool IsEndOfLine(string markdown, int position, out int positionAfterEnd)
        {
            positionAfterEnd = MarkdownParsingUtils.FindNextNotFitting(markdown, position, char.IsWhiteSpace);
            var endTagSubstr = markdown.Substring(position, positionAfterEnd - position);

            return(endTagSubstr.Any(MarkdownParsingUtils.IsNextLineSymbol) || positionAfterEnd == markdown.Length);
        }
 private string GetAbsoluteLink(string relativeLink, string baseUrl)
 {
     if (baseUrl == null)
     {
         throw new InvalidOperationException("Base url was not specified.");
     }
     return(MarkdownParsingUtils.CombineLinks(baseUrl, relativeLink));
 }
Beispiel #3
0
        public override bool Fits(string markdown, int position, out int positionAfterEnd, TagInfo previousTag)
        {
            positionAfterEnd = MarkdownParsingUtils.FindNextNotFitting(markdown, position, char.IsWhiteSpace);
            var symbolsBetween         = markdown.Substring(position, positionAfterEnd - position);
            var exactlyOneNewLine      = symbolsBetween.Count(MarkdownParsingUtils.IsNextLineSymbol) == 1;
            var nextLineSymbolPosition = symbolsBetween.IndexOfAny(MarkdownParsingUtils.NextLineSymbols.ToCharArray());
            var enoughSpaces           = nextLineSymbolPosition >= MinimalSpaceSymbolsNumberBeforeNewLine;

            positionAfterEnd = position + nextLineSymbolPosition + 1;

            return(exactlyOneNewLine && enoughSpaces);
        }
 public override void AddValueOrProperty(string valueOrProperty, TagType tagType, string baseUrl)
 {
     if (tagType.TagPart == HyperlinkTagInfo.VALUE_PART)
     {
         Value = valueOrProperty;
     }
     else
     {
         var correctLink = MarkdownParsingUtils.ToCorrectLink(valueOrProperty);
         if (correctLink == null)
         {
             throw new InvalidOperationException("Link is incorrect"); // should not happen
         }
         var absoluteLink = IsRelativeLink(correctLink) ? GetAbsoluteLink(correctLink, baseUrl) : correctLink;
         AddProperty("href", absoluteLink);
     }
 }
        /// <summary>
        /// Checks that hyperlink will be finished at some point.
        /// </summary>
        /// <param name="position">Position after "](" symbols</param>
        /// <returns></returns>
        private static bool IsHyperlinkSecondPart(string markdown, int position)
        {
            var builder = new StringBuilder();
            var endRepr = new HyperlinkTagInfo(TagPosition.Closing, LINK_PART).GetRepresentation();

            for (var i = position; i <= markdown.Length - endRepr.Length; ++i)
            {
                if (markdown.Substring(i, endRepr.Length) == endRepr)
                {
                    return(MarkdownParsingUtils.IsCorrectLink(builder.ToString()));
                }
                else
                {
                    builder.Append(markdown[i]);
                }
            }
            return(false);
        }
Beispiel #6
0
 public override bool Fits(string markdown, int position, out int positionAfterEnd, TagInfo previousTag = null)
 {
     positionAfterEnd = -1;
     if (TagPosition == TagPosition.Opening)
     {
         int afterWhiteSpaces;
         if (IsEndOfLine(markdown, position, out afterWhiteSpaces))
         {
             return(false);
         }
         var headerSymbolsEndPosition = MarkdownParsingUtils.FindNextNotFitting(markdown, afterWhiteSpaces, HeaderSymbol.Equals);
         var headerSymbolsCount       = headerSymbolsEndPosition - afterWhiteSpaces;
         if (!IsInRangeNotStrict(headerSymbolsCount, 1, 6))
         {
             return(false);
         }
         positionAfterEnd = MarkdownParsingUtils.FindNextNotFitting(markdown, headerSymbolsEndPosition, char.IsWhiteSpace);
         if (positionAfterEnd == headerSymbolsEndPosition)
         {
             return(false); // need at least one white space
         }
         HeaderLevel = headerSymbolsCount;
         return(true);
     }
     else
     {
         if (IsEndOfLine(markdown, position, out positionAfterEnd))
         {
             return(true);
         }
         if (markdown[positionAfterEnd] != HeaderSymbol)
         {
             return(false);
         }
         var positionAfterHeaderSymbols = MarkdownParsingUtils.FindNextNotFitting(markdown,
                                                                                  positionAfterEnd, HeaderSymbol.Equals);
         return(IsEndOfLine(markdown, positionAfterHeaderSymbols, out positionAfterEnd));
     }
 }
Beispiel #7
0
        public override bool Fits(string markdown, int position, out int positionAfterEnd, TagInfo previousTag = null)
        {
            switch (TagPosition)
            {
            case TagPosition.Closing:
                positionAfterEnd = MarkdownParsingUtils.FindNextNotFitting(markdown, position, char.IsWhiteSpace);
                var symbolsBetween = markdown.Substring(position, positionAfterEnd - position);
                var newLinesCount  = symbolsBetween.Count(MarkdownParsingUtils.IsNextLineSymbol);
                int ignore;
                var nextTagIsHeader     = new HeaderTagInfo(TagPosition.Opening).Fits(markdown, positionAfterEnd, out ignore);
                var enoughNewLines      = newLinesCount > 1;
                var enoughForNextHeader = newLinesCount == 1 || previousTag?.Tag == Tag.Paragraph;
                return(enoughNewLines || (enoughForNextHeader && nextTagIsHeader));

            case TagPosition.Opening:
                positionAfterEnd = MarkdownParsingUtils.FindNextNotFitting(markdown, position, char.IsWhiteSpace);
                return(true);

            default:
                throw new InvalidOperationException("Tag position should eather be opening or closing.");
            }
        }
 public string CombineLinks(string baseUrl, string relativePath)
 {
     return(MarkdownParsingUtils.CombineLinks(baseUrl, relativePath));
 }
 public string ReturnCorrectLink(string link)
 {
     return(MarkdownParsingUtils.ToCorrectLink(link));
 }