protected override string ProcessMarkupPatternMatch(Definition definition, MarkupPattern pattern, Match match) { var builder = new StringBuilder(); var style = CreateRtfPatternStyle(pattern.Style.Colors.ForeColor, pattern.Style.Colors.BackColor, pattern.Style.Font); var bracketStyle = CreateRtfPatternStyle(pattern.BracketColors.ForeColor, pattern.BracketColors.BackColor, pattern.Style.Font); string attributeNameStyle = null; string attributeValueStyle = null; if (pattern.HighlightAttributes) { attributeNameStyle = CreateRtfPatternStyle(pattern.AttributeNameColors.ForeColor, pattern.AttributeNameColors.BackColor, pattern.Style.Font); attributeValueStyle = CreateRtfPatternStyle(pattern.AttributeValueColors.ForeColor, pattern.AttributeValueColors.BackColor, pattern.Style.Font); } builder.AppendFormat(RtfFormat, bracketStyle, match.Groups["openTag"].Value); builder.Append(match.Groups["ws1"].Value); builder.AppendFormat(RtfFormat, style, match.Groups["tagName"].Value); if (attributeNameStyle != null) { for (var i = 0; i < match.Groups["attribute"].Captures.Count; i++) { builder.Append(match.Groups["ws2"].Captures[i].Value); builder.AppendFormat(RtfFormat, attributeNameStyle, match.Groups["attribName"].Captures[i].Value); if (String.IsNullOrWhiteSpace(match.Groups["attribValue"].Captures[i].Value)) { continue; } builder.AppendFormat(RtfFormat, attributeValueStyle, match.Groups["attribValue"].Captures[i].Value); } } builder.Append(match.Groups["ws5"].Value); builder.AppendFormat(RtfFormat, bracketStyle, match.Groups["closeTag"].Value); return ("{" + builder + "}"); }
protected override string ProcessMarkupPatternMatch(Definition definition, MarkupPattern pattern, Match match) { var builder = new StringBuilder(); builder.AppendFormat(ElementFormat, "openTag", match.Groups["openTag"].Value); builder.AppendFormat(ElementFormat, "whitespace", match.Groups["ws1"].Value); builder.AppendFormat(ElementFormat, "tagName", match.Groups["tagName"].Value); var builder2 = new StringBuilder(); for (var i = 0; i < match.Groups["attribute"].Captures.Count; i++) { builder2.AppendFormat(ElementFormat, "whitespace", match.Groups["ws2"].Captures[i].Value); builder2.AppendFormat(ElementFormat, "attribName", match.Groups["attribName"].Captures[i].Value); if (String.IsNullOrWhiteSpace(match.Groups["attribValue"].Captures[i].Value)) { continue; } builder2.AppendFormat(ElementFormat, "attribValue", match.Groups["attribValue"].Captures[i].Value); } builder.AppendFormat(ElementFormat, "attribute", builder2); builder.AppendFormat(ElementFormat, "whitespace", match.Groups["ws5"].Value); builder.AppendFormat(ElementFormat, "closeTag", match.Groups["closeTag"].Value); return String.Format(ElementFormat, pattern.Name, builder); }
protected override string ProcessMarkupPatternMatch(Definition definition, MarkupPattern pattern, Match match) { if (definition == null) { throw new ArgumentNullException("definition"); } if (pattern == null) { throw new ArgumentNullException("pattern"); } if (match == null) { throw new ArgumentNullException("match"); } var result = new StringBuilder(); if (!UseCss) { var patternStyle = HtmlEngineHelper.CreatePatternStyle(pattern.BracketColors, pattern.Style.Font); result.AppendFormat(StyleSpanFormat, patternStyle, match.Groups["openTag"].Value); result.Append(match.Groups["ws1"].Value); patternStyle = HtmlEngineHelper.CreatePatternStyle(pattern.Style); result.AppendFormat(StyleSpanFormat, patternStyle, match.Groups["tagName"].Value); if (pattern.HighlightAttributes) { var highlightedAttributes = ProcessMarkupPatternAttributeMatches(definition, pattern, match); result.Append(highlightedAttributes); } result.Append(match.Groups["ws5"].Value); patternStyle = HtmlEngineHelper.CreatePatternStyle(pattern.BracketColors, pattern.Style.Font); result.AppendFormat(StyleSpanFormat, patternStyle, match.Groups["closeTag"].Value); } else { var cssClassName = HtmlEngineHelper.CreateCssClassName(definition.Name, pattern.Name + "Bracket"); result.AppendFormat(ClassSpanFormat, cssClassName, match.Groups["openTag"].Value); result.Append(match.Groups["ws1"].Value); cssClassName = HtmlEngineHelper.CreateCssClassName(definition.Name, pattern.Name + "TagName"); result.AppendFormat(ClassSpanFormat, cssClassName, match.Groups["tagName"].Value); if (pattern.HighlightAttributes) { var highlightedAttributes = ProcessMarkupPatternAttributeMatches(definition, pattern, match); result.Append(highlightedAttributes); } result.Append(match.Groups["ws5"].Value); cssClassName = HtmlEngineHelper.CreateCssClassName(definition.Name, pattern.Name + "Bracket"); result.AppendFormat(ClassSpanFormat, cssClassName, match.Groups["closeTag"].Value); } return result.ToString(); }
protected abstract string ProcessMarkupPatternMatch(Definition definition, MarkupPattern pattern, Match match);
private string ProcessMarkupPatternAttributeMatches(Definition definition, MarkupPattern pattern, Match match) { var result = new StringBuilder(); for (var i = 0; i < match.Groups["attribute"].Captures.Count; i++) { result.Append(match.Groups["ws2"].Captures[i].Value); if (!UseCss) { var patternStyle = HtmlEngineHelper.CreatePatternStyle(pattern.AttributeNameColors, pattern.Style.Font); result.AppendFormat(StyleSpanFormat, patternStyle, match.Groups["attribName"].Captures[i].Value); if (String.IsNullOrWhiteSpace(match.Groups["attribValue"].Captures[i].Value)) { continue; } patternStyle = HtmlEngineHelper.CreatePatternStyle(pattern.AttributeValueColors, pattern.Style.Font); result.AppendFormat(StyleSpanFormat, patternStyle, match.Groups["attribValue"].Captures[i].Value); } else { var cssClassName = HtmlEngineHelper.CreateCssClassName(definition.Name, pattern.Name + "AttributeName"); result.AppendFormat(ClassSpanFormat, cssClassName, match.Groups["attribName"].Captures[i].Value); if (String.IsNullOrWhiteSpace(match.Groups["attribValue"].Captures[i].Value)) { continue; } cssClassName = HtmlEngineHelper.CreateCssClassName(definition.Name, pattern.Name + "AttributeValue"); result.AppendFormat(ClassSpanFormat, cssClassName, match.Groups["attribValue"].Captures[i].Value); } } return result.ToString(); }