protected static Token FindAncestorToken(Token searchTarget, Func<Token, bool> predicate) { if (predicate(searchTarget)) return searchTarget; return searchTarget.Parent != null ? FindAncestorToken(searchTarget.Parent, predicate) : null; }
void ApplyImpl(Token rootToken) { for (int i = 0; i < rootToken.Children.Count; i++) { var token = rootToken.Children[i]; if (token is LineBreakToken && ( token.Parent.Children.IndexOf(token) == 0 || token.Parent.Children.IndexOf(token) == token.Parent.Children.Count - 1 ) ) token.Parent.RemoveChild(token); ApplyImpl(token); } }
internal abstract string RenderOpeningTag(Token token);
internal abstract string RenderClosingTag(Token token);
internal abstract bool CanRender(Token token);
internal override string RenderOpeningTag(Token token) { return "<br />"; }
internal abstract bool Apply(StringReader reader, ref Token parentToken, ref Token previousToken);
internal override bool CanRender(Token token) { return token is LineBreakToken; }
internal override string RenderClosingTag(Token token) { return string.Empty; }
internal override string RenderClosingTag(Token token) { return "</p>"; }
internal override bool CanRender(Token token) { return token is ParagraphToken; }
internal void RemoveChild(Token token) { Children.Remove(token); }
internal void AddChild(Token token) { token.Parent = this; Children.Add(token); }
internal override bool CanRender(Token token) { return token is StrongToken; }