public virtual bool Fits(string markdown, int position, out int positionAfterEnd, TagInfo previousTag = null) { positionAfterEnd = -1; if (Tag == Tag.None || TagPosition == TagPosition.None) { return(false); } var tagRepresentation = GetRepresentation(); positionAfterEnd = position + tagRepresentation.Length; if (positionAfterEnd > markdown.Length) { return(false); } return(markdown.Substring(position, tagRepresentation.Length) == tagRepresentation); }
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."); } }
protected bool Equals(TagInfo other) { return(Tag == other.Tag && Equals(TagType, other.TagType)); }
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); }