/// <summary> /// Defines a child conditional token for replacement. /// </summary> /// <typeparam name="TChild"></typeparam> /// <param name="replacement"></param> /// <param name="identifier"></param> /// <param name="condition"></param> /// <param name="context"></param> /// <returns></returns> public IConditionalToken <TModel, TChild> TokenizeIf <TChild>(Func <TModel, TChild> replacement, string identifier, Func <TModel, bool> condition, ITokenRoot <TChild> context) { Ensure.ArgumentNotNull(replacement, "replacement"); Ensure.ArgumentNotNullOrEmpty(identifier, "identifier"); Ensure.ArgumentNotNull(condition, "condition"); Ensure.ArgumentNotNull(context, "context"); var blockToken = new BlockToken <TModel, TChild> { Child = replacement, Resolve = p => string.Empty, Identifier = string.Intern(identifier), Condition = condition }; _currentToken = blockToken; Token.Children.Add(_currentToken); foreach (var token in context.Token.Children) { _currentToken.AddChild(token); } return(new TokenBlockBuilder <TModel, TChild>(_currentToken)); }
internal override bool Apply(StringReader reader, ref Token parentToken, ref Token previousToken) { var token = new LineBreakToken(); parentToken.AddChild(token); previousToken = token; return true; }
internal override bool Apply(StringReader reader, ref Token parentToken, ref Token previousToken) { var temp = previousToken as LiteralToken; if (temp != null) { temp.AddChar(reader.CurrentChar); } else { var token = new LiteralToken(reader.CurrentChar); parentToken.AddChild(token); previousToken = token; } return true; }
internal override bool Apply(StringReader reader, ref Token parentToken, ref Token previousToken) { var previousEmphasisToken = FindAncestorToken(parentToken, token => token is EmphasisToken); if (previousEmphasisToken != null && previousEmphasisToken.Closed == false) { previousToken.Closed = true; parentToken = parentToken.Parent; previousToken = previousEmphasisToken; } else { var token = new EmphasisToken(); parentToken.AddChild(token); parentToken = token; previousToken = token; } return true; }
internal override bool Apply(StringReader reader, ref Token parentToken, ref Token previousToken) { var token = new ParagraphToken(); if (reader.NextChar == '\n') { reader.Advance(2); parentToken.Parent.AddChild(token); parentToken = token; } else { parentToken.AddChild(token); parentToken = token; } previousToken = token; return false; }
/// <summary> /// Defines a child block of tokens. /// </summary> /// <typeparam name="TChild"></typeparam> /// <param name="children"></param> /// <param name="identifier"></param> /// <param name="context"></param> /// <returns></returns> public ITokenBlock <TModel, TChild> Block <TChild>(Func <TModel, IEnumerable <TChild> > children, string identifier, ITokenRoot <TChild> context) { Ensure.ArgumentNotNull(children, "children"); Ensure.ArgumentNotNullOrEmpty(identifier, "identifier"); Ensure.ArgumentNotNull(context, "context"); var blockToken = new BlockToken <TModel, TChild> { Resolve = p => string.Empty, Identifier = string.Intern(identifier), Items = model => GetEachChild(model, children) }; _currentToken = blockToken; Token.Children.Add(_currentToken); foreach (var token in context.Token.Children) { _currentToken.AddChild(token); } return(new TokenBlockBuilder <TModel, TChild>(_currentToken)); }