示例#1
0
        private string ElementMatchHandler(Definition definition, Match match)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            if (match == null)
            {
                throw new ArgumentNullException(nameof(match));
            }

            var pattern = definition.Patterns.First
                          (
                x => match.Groups[x.Key]
                .Success
                          )
                          .Value;

            return(pattern switch
            {
                BlockPattern blockPattern => ProcessBlockPatternMatch(definition, blockPattern, match),
                MarkupPattern markupPattern => ProcessMarkupPatternMatch(definition, markupPattern, match),
                WordPattern wordPattern => ProcessWordPatternMatch(definition, wordPattern, match),
                _ => match.Value,
            });
示例#2
0
        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));
        }
示例#3
0
        protected override Span[] ProcessMarkupPatternMatch(Definition definition, MarkupPattern pattern, Match match)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            if (pattern == null)
            {
                throw new ArgumentNullException(nameof(pattern));
            }

            if (match == null)
            {
                throw new ArgumentNullException(nameof(match));
            }

            var result = new List <Span>();

            result.Add(new Span()
            {
                Text  = match.Groups["openTag"].Value,
                Style = GetSpanStyle(pattern.BracketColors, pattern.Style?.Font),
            });
            result.Add(new Span()
            {
                Text = match.Groups["ws1"].Value,
            });
            result.Add(new Span()
            {
                Text  = match.Groups["tagName"].Value,
                Style = GetSpanStyle(pattern.Style),
            });
            if (pattern.HighlightAttributes)
            {
                var highlightedAttributes = ProcessMarkupPatternAttributeMatches(definition, pattern, match);
                result.AddRange(highlightedAttributes);
            }
            result.Add(new Span()
            {
                Text = match.Groups["ws5"].Value,
            });
            result.Add(new Span()
            {
                Text  = match.Groups["closeTag"].Value,
                Style = GetSpanStyle(pattern.BracketColors, pattern.Style?.Font),
            });
            return(result.ToArray());
        }
示例#4
0
        protected Span[] ProcessMarkupPatternAttributeMatches(Definition definition, MarkupPattern pattern, Match match)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            if (pattern == null)
            {
                throw new ArgumentNullException(nameof(pattern));
            }

            if (match == null)
            {
                throw new ArgumentNullException(nameof(match));
            }

            var result = new List <Span>();

            for (int i = 0; i < match.Groups["attribute"].Captures.Count; i++)
            {
                result.Add(new Span()
                {
                    Text = match.Groups["ws2"].Captures[i].Value,
                });
                result.Add(new Span()
                {
                    Text  = match.Groups["attribName"].Value,
                    Style = GetSpanStyle(pattern.AttributeNameColors, pattern.Style?.Font),
                });
                if (string.IsNullOrEmpty(match.Groups["attribValue"].Captures[i].Value))
                {
                    continue;
                }
                result.Add(new Span()
                {
                    Text  = match.Groups["attribValue"].Value,
                    Style = GetSpanStyle(pattern.AttributeValueColors, pattern.Style?.Font),
                });
            }

            return(result.ToArray());
        }
示例#5
0
        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());
        }
示例#6
0
        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 + "}");
        }
示例#7
0
 protected abstract string ProcessMarkupPatternMatch(Definition definition, MarkupPattern pattern, Match match);
示例#8
0
        protected override string ProcessMarkupPatternMatch(Definition definition, MarkupPattern pattern, Match match)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            if (pattern == null)
            {
                throw new ArgumentNullException(nameof(pattern));
            }

            if (match == null)
            {
                throw new ArgumentNullException(nameof(match));
            }

            var result = new StringBuilder();

            if (!UseCss)
            {
                var patternStyle = HtmlEngineHelper.CreatePatternStyle(pattern.BracketColors, pattern.Style.Font);

                result.AppendFormat
                (
                    STYLE_SPAN_FORMAT,
                    patternStyle,
                    match.Groups["openTag"]
                    .Value
                );

                result.Append
                (
                    match.Groups["ws1"]
                    .Value
                );

                patternStyle = HtmlEngineHelper.CreatePatternStyle(pattern.Style);

                result.AppendFormat
                (
                    STYLE_SPAN_FORMAT,
                    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
                (
                    STYLE_SPAN_FORMAT,
                    patternStyle,
                    match.Groups["closeTag"]
                    .Value
                );
            }
            else
            {
                var cssClassName = HtmlEngineHelper.CreateCssClassName(definition.Name, pattern.Name + "Bracket");

                result.AppendFormat
                (
                    CLASS_SPAN_FORMAT,
                    cssClassName,
                    match.Groups["openTag"]
                    .Value
                );

                result.Append
                (
                    match.Groups["ws1"]
                    .Value
                );

                cssClassName = HtmlEngineHelper.CreateCssClassName(definition.Name, pattern.Name + "TagName");

                result.AppendFormat
                (
                    CLASS_SPAN_FORMAT,
                    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
                (
                    CLASS_SPAN_FORMAT,
                    cssClassName,
                    match.Groups["closeTag"]
                    .Value
                );
            }

            return(result.ToString());
        }
示例#9
0
 protected override string ProcessMarkupPatternMatch(Definition definition, MarkupPattern pattern, Match match)
 {
     HighlightedSpans.Add(new FormattedString(match.Value, pattern.Style.Colors.ForeColor, pattern.Style.Font.IsBold, pattern.Style.Font.IsItalic));
     return(match.Value);
 }