ParserNode RootNode() { if ((!previousData.Match(Data.Data)) || (previousType != ContentType)) { previousRoot = Parser.Parse(Data.Data, ContentType); previousData.SetValue(Data.Data); previousType = ContentType; } return previousRoot; }
static public string Reformat(ParserNode node, string input, ParserType parserType) { switch (parserType) { case ParserType.HTML: return HTMLVisitor.Format(node, input); case ParserType.JSON: return JSONVisitor.Format(node, input); case ParserType.XML: return XMLVisitor.Format(node, input); default: throw new Exception("Unable to reformat this type"); } }
void Command_Content_Navigate(ParserNode.ParserNavigationDirectionEnum direction, bool shiftDown) => ContentReplaceSelections(GetSelectionNodes().SelectMany(node => node.Navigate(direction, shiftDown)));
List<string> Print() { var parents = new List<ParserNode>(); for (var parent = this; parent != null; parent = parent.Parent) parents.Insert(0, parent); var parentTypes = string.Join("->", parents.Select(node => node.Type)); var attrs = string.Join(", ", attributes.Select(child => ($"{child.start}-{child.end} {child.Type} \"{(child.Text ?? "").Replace("\r", "").Replace("\n", "").Replace("\"", "\"\"")}\""))); var result = new List<string> { $"[{start}-{end}: {attrs} Path: \"{parentTypes}\"" }; result.AddRange(children.SelectMany(child => child.Print()).Select(str => $" {str}")); if (result.Count == 1) result[0] += "]"; else result.Add("]"); return result; }