private bool CheckForMatch(List <string> expressions, IDOTNode node, out IDOTNode newnode) { var ismatch = false; newnode = null; foreach (var expression in expressions) { var reg = new Regex(expression); if (reg.IsMatch(node.Text)) { ismatch = true; MatchCollection matches = reg.Matches(node.Text); var match = matches[0]; if (!string.IsNullOrEmpty(match.Groups[TextGroup].Value)) { newnode = new DOTNode() { BlockType = this.LineType, NodeType = DOTNodeType.Text, Text = match.Groups[TextGroup].Value }; } break; } } return(ismatch); }
private bool ProcessNextLine(IDOTNode node, out IDOTNode newnode, out bool backup) { var islast = false; var ismatch = false; // Check to see if we have an end match if (this.CheckForMatch(this.EndExpressions, node, out newnode)) { node.ProcessingType = DOTProcessingType.Remove; islast = true; } // If we don't have an end match but don't have any Line exressions we're still in the block else if ((this.LineExpressions.Count == 0 && this.EndExpressions.Count > 0)) { ismatch = true; newnode = new DOTNode() { BlockType = this.LineType, NodeType = DOTNodeType.Text, Text = node.Text }; } // if we have line expressions we check for a match. else { ismatch = this.CheckForMatch(this.LineExpressions, node, out newnode); } backup = (!islast) && (!ismatch); return(islast ? islast : !ismatch); }
public override bool Process(IDOTNode rootnode, MatchCollection matches, ref int index) { var ret = base.Process(rootnode, matches, ref index); var basenode = rootnode.Nodes[index]; if (string.IsNullOrEmpty(basenode.Text) && basenode.Nodes.Count == 0) { basenode.ProcessingType = DOTProcessingType.Remove; } return(ret); }
protected void LineProcessNodes(IDOTNode basenode) { foreach (var proc in LineProcessors) { proc.Value.ProcessNode(basenode); foreach (var node in basenode.Nodes) { proc.Value.ProcessNode(node.Value); } } }
private void IndexTree(IDOTNode parentnode) { foreach (var node in parentnode.Nodes) { node.Value.ParentNode = parentnode; if (node.Value.Nodes.Count > 0) { this.IndexTree(node.Value); } } }
public bool ProcessNode(IDOTNode node) { var ok = true; var reg = new Regex(this.Expression); if (reg.IsMatch(node.Text)) { MatchCollection matches = reg.Matches(node.Text); for (int i = 0; i < matches.Count; i++) { var match = matches[i]; if (match.Groups.Count > 2) { node.Text = string.Empty; node.NodeType = DOTNodeType.Node; node.AddNode(new DOTNode() { BlockType = DOTBlockType.TextBlock, NodeType = DOTNodeType.Text, Text = match.Groups[1].Value }); var newnode = (IDOTNode) new DOTNode() { BlockType = this.BlockType, NodeType = DOTNodeType.Text, Text = match.Groups[2].Value }; foreach (var attr in this.Attributes) { if (!string.IsNullOrEmpty(match.Groups[attr.Key].Value)) { newnode.SetAttribute(attr.Value, match.Groups[attr.Key].Value); } } node.AddNode(newnode); if (match.Groups.Count == (PostTextGroupPosition + 1) && !string.IsNullOrEmpty(match.Groups[3].Value)) { node.AddNode(new DOTNode() { BlockType = DOTBlockType.TextBlock, NodeType = DOTNodeType.Text, Text = match.Groups[PostTextGroupPosition].Value }); } } } } // Check to see if er have sub nodes and if so process them if (node.Nodes.Count > 0) { foreach (var n in node.Nodes) { ProcessNode(n.Value); } } return(ok); }
private string AsHtmlCodeLine(IDOTNode node) { var html = new StringBuilder(); var rule = Rules.FirstOrDefault(item => item.BlockType == node.BlockType); if (!string.IsNullOrEmpty(node.Text)) { html.Append(HTMLCharacterConverter.Replace(node.Text)); } html.Append(AddSubNodes(node)); return(AddTagWrapper(rule, node.GetAttributeString(), html.ToString())); }
private string AsHtmlImageBlock(IDOTNode node) { var html = new StringBuilder(); var rule = Rules.FirstOrDefault(item => item.BlockType == node.BlockType); if (!string.IsNullOrEmpty(node.Text)) { node.SetAttribute("alt", node.Text); } html.Append(AddSubNodes(node)); return(AddTagWrapper(rule, node.GetAttributeString(), html.ToString())); }
public override bool Process(IDOTNode rootnode, MatchCollection matches, ref int index) { var ok = true; var basenode = rootnode.Nodes[index]; if (Regex.IsMatch(basenode.Text, _unorderedExpression)) { _blockType = DOTBlockType.UnOrderedListBlock; } var match = matches[0]; if (match.Groups.Count > 2) { basenode.Text = string.Empty; basenode.NodeType = DOTNodeType.Node; basenode.BlockType = _blockType; foreach (var attr in this.Attributes) { if (!string.IsNullOrEmpty(match.Groups[attr.Key].Value)) { basenode.SetAttribute(attr.Value, match.Groups[attr.Key].Value); } } if (!string.IsNullOrEmpty(match.Groups[TextGroup].Value)) { basenode.AddNode(new DOTNode() { BlockType = _linetype, NodeType = DOTNodeType.Text, Text = match.Groups[TextGroup].Value }); } bool islast; do { index++; if (index > rootnode.Nodes.Count) { break; } var node = rootnode.Nodes[index]; islast = ProcessNextLine(node, out IDOTNode addnode); if (addnode != null) { basenode.AddNode(addnode); node.ProcessingType = DOTProcessingType.Remove; } } while (!islast); index--; LineProcessNodes(basenode); } return(ok); }
public override bool Process(IDOTNode rootnode, MatchCollection matches, ref int index) { var basenode = rootnode.Nodes[index]; var match = matches[0]; var ret = base.Process(rootnode, matches, ref index); if (match.Groups.Count > 1 && !string.IsNullOrEmpty(match.Groups[1].Value)) { basenode.SetValue("level", match.Groups[1].Value.Length); } return(ret); }
private bool ProcessNextLine(IDOTNode node, out IDOTNode newnode) { var islast = true; newnode = null; foreach (var expression in this.Expressions) { if (Regex.IsMatch(node.Text, expression)) { islast = false; MatchCollection matches = Regex.Matches(node.Text, expression); var match = matches[0]; if (!string.IsNullOrEmpty(match.Groups[TextGroup].Value)) { newnode = new DOTNode() { BlockType = _linetype, NodeType = DOTNodeType.Text, Text = match.Groups[TextGroup].Value }; } break; } } return(islast); }
private string AddSubNodes(IDOTNode node) { var html = new StringBuilder(); if (node.Nodes.Count > 0) { foreach (var n in node.Nodes) { var rule = Rules.FirstOrDefault(item => item.BlockType == n.Value.BlockType); if (rule != null) { if (rule.IsLineBlock) { html.AppendLine(rule.ConverterMethod(n.Value)); } else { html.Append(rule.ConverterMethod(n.Value)); } } } } return(html.ToString()); }
public override bool Process(IDOTNode rootnode, MatchCollection matches, ref int index) { return(base.Process(rootnode, matches, ref index)); }
public virtual bool Process(IDOTNode rootnode, MatchCollection matches, ref int index) { var ok = true; var basenode = rootnode.Nodes[index]; var match = matches[0]; if (match.Groups.Count >= this.MinimumGroups) { basenode.Text = string.Empty; basenode.NodeType = DOTNodeType.Node; basenode.BlockType = this.BlockType; foreach (var attr in this.Attributes) { if (!string.IsNullOrEmpty(match.Groups[attr.Key].Value)) { basenode.SetAttribute(attr.Value, match.Groups[attr.Key].Value); } } foreach (var val in this.Values) { if (!string.IsNullOrEmpty(match.Groups[val.Key].Value)) { basenode.SetValue(val.Value, match.Groups[val.Key].Value); } } if (TextGroup > 0 && !string.IsNullOrEmpty(match.Groups[TextGroup].Value)) { if (this.IsMultiline) { basenode.AddNode(new DOTNode() { BlockType = this.LineType, NodeType = DOTNodeType.Text, Text = match.Groups[TextGroup].Value }); } else { basenode.Text = match.Groups[TextGroup].Value; } } if (this._isReallyMultiLine) { bool islast; do { index++; var node = rootnode.Nodes[index]; islast = ProcessNextLine(node, out IDOTNode addnode, out bool backup); if (addnode != null) { basenode.AddNode(addnode); node.ProcessingType = DOTProcessingType.Remove; } if (backup) { index--; } } while (!islast); } LineProcessNodes(basenode); } return(ok); }