public void HighlightSyntax(SyntaxDescriptor desc, Range range) { //set style order range.tb.ClearStylesBuffer(); for (int i = 0; i < desc.styles.Count; i++) { range.tb.Styles[i] = desc.styles[i]; } //brackets range.tb.LeftBracket = desc.leftBracket; range.tb.RightBracket = desc.rightBracket; range.tb.LeftBracket2 = desc.leftBracket2; range.tb.RightBracket2 = desc.rightBracket2; //clear styles of range range.ClearStyle(desc.styles.ToArray()); //highlight syntax foreach (var rule in desc.rules) { range.SetStyle(rule.style, rule.Regex); } //clear folding range.ClearFoldingMarkers(); //folding markers foreach (var folding in desc.foldings) { range.SetFoldingMarkers(folding.startMarkerRegex, folding.finishMarkerRegex, folding.options); } }
public static SyntaxDescriptor ParseXmlDescription(XmlDocument doc) { SyntaxDescriptor desc = new SyntaxDescriptor(); XmlNode brackets = doc.SelectSingleNode("doc/brackets"); if (brackets != null) { if (brackets.Attributes["left"] == null || brackets.Attributes["right"] == null || brackets.Attributes["left"].Value == "" || brackets.Attributes["right"].Value == "") { desc.leftBracket = '\x0'; desc.rightBracket = '\x0'; } else { desc.leftBracket = brackets.Attributes["left"].Value[0]; desc.rightBracket = brackets.Attributes["right"].Value[0]; } if (brackets.Attributes["left2"] == null || brackets.Attributes["right2"] == null || brackets.Attributes["left2"].Value == "" || brackets.Attributes["right2"].Value == "") { desc.leftBracket2 = '\x0'; desc.rightBracket2 = '\x0'; } else { desc.leftBracket2 = brackets.Attributes["left2"].Value[0]; desc.rightBracket2 = brackets.Attributes["right2"].Value[0]; } } Dictionary <string, Style> styleByName = new Dictionary <string, Style>(); foreach (XmlNode style in doc.SelectNodes("doc/style")) { var s = ParseStyle(style); styleByName[style.Attributes["name"].Value] = s; desc.styles.Add(s); } foreach (XmlNode rule in doc.SelectNodes("doc/rule")) { desc.rules.Add(ParseRule(rule, styleByName)); } foreach (XmlNode folding in doc.SelectNodes("doc/folding")) { desc.foldings.Add(ParseFolding(folding)); } return(desc); }
/// <summary> /// Highlights syntax for given XML description file /// </summary> public virtual void HighlightSyntax(string XMLdescriptionFile, Range range) { SyntaxDescriptor desc = null; if (!descByXMLfileNames.TryGetValue(XMLdescriptionFile, out desc)) { var doc = new XmlDocument(); string file = XMLdescriptionFile; if (!File.Exists(file)) { file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(file)); } doc.LoadXml(File.ReadAllText(file)); desc = ParseXmlDescription(doc); descByXMLfileNames[XMLdescriptionFile] = desc; } HighlightSyntax(desc, range); }