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);
        }
Beispiel #2
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);
        }
Beispiel #3
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 #4
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.");
            }
        }