private void AddNewDelimiter(Substring lexeme) { var canBeClosing = specification.CanBeClosing(lexeme, markdownInput); var canBeStarting = specification.CanBeStarting(lexeme, markdownInput); var delimiter = new Delimiter(lexeme.Value, lexeme.Index, canBeClosing, canBeStarting); if (delimiter.CanBeClosing) { var closed = TryCloseToken(delimiter, out var closedToken); if (closed) { ResolveToken(closedToken); CurrentToken = closedToken.ParentToken; return; } } if (delimiter.CanBeStarting) { var newToken = new Token(delimiter); CurrentToken.AddToken(newToken); CurrentToken = newToken; } else { CurrentToken.AddText(delimiter.Value); } }
public bool CanBeClosing(Substring substring, string markdownInput) { if (substring.Value == "\r\n") { return(true); } return(substring.Index != 0 && markdownInput[substring.Index - 1] != ' '); }
public bool CanBeStarting(Substring substring, string markdownInput) { if (substring.Value.StartsWith("#") && substring.Index > 0 && markdownInput[substring.Index - 1] != '\n') { return(false); } return(substring.Index + substring.Length < markdownInput.Length && markdownInput[substring.Index + substring.Length] != ' '); }