Пример #1
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);
        }
Пример #2
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 + "}");
        }
Пример #3
0
        private RegexOptions GetRegexOptions(Definition definition)
        {
            if (definition.CaseSensitive) {
                return DefaultRegexOptions | RegexOptions.IgnoreCase;
            }

            return DefaultRegexOptions;
        }
Пример #4
0
        protected override string PreHighlight(Definition definition, string input)
        {
            if (definition == null) {
                throw new ArgumentNullException("definition");
            }

            return HttpUtility.HtmlEncode(input);
        }
Пример #5
0
        protected override string PostHighlight(Definition definition, string input)
        {
            var result = input
                .Replace("{", @"\{").Replace("}", @"\}").Replace("\t", @"\tab ")
                .Replace("\r\n", @"\par ");
            var fontList = BuildFontList();
            var colorList = BuildColorList();

            return String.Format(@"{{\rtf1\ansi{{\fonttbl{{{0}}}}}{{\colortbl;{1}}}{2}}}", fontList, colorList, result);
        }
Пример #6
0
        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();
        }
Пример #7
0
        public string Highlight(Definition definition, string input)
        {
            if (definition == null) {
                throw new ArgumentNullException("definition");
            }

            var output = PreHighlight(definition, input);
            output = HighlightUsingRegex(definition, output);
            output = PostHighlight(definition, output);

            return output;
        }
Пример #8
0
        protected override string ProcessBlockPatternMatch(Definition definition, BlockPattern pattern, Match match)
        {
            if (!UseCss) {
                var patternStyle = HtmlEngineHelper.CreatePatternStyle(pattern.Style);

                return String.Format(StyleSpanFormat, patternStyle, match.Value);
            }

            var cssClassName = HtmlEngineHelper.CreateCssClassName(definition.Name, pattern.Name);

            return String.Format(ClassSpanFormat, cssClassName, match.Value);
        }
Пример #9
0
        protected override string PostHighlight(Definition definition, string input)
        {
            if (definition == null) {
                throw new ArgumentNullException("definition");
            }

            if (!UseCss) {
                var cssStyle = HtmlEngineHelper.CreatePatternStyle(definition.Style);

                return String.Format(StyleSpanFormat, cssStyle, input);
            }

            var cssClassName = HtmlEngineHelper.CreateCssClassName(definition.Name, null);

            return String.Format(ClassSpanFormat, cssClassName, input);
        }
Пример #10
0
        private string ElementMatchHandler(Definition definition, Match match)
        {
            if (definition == null) {
                throw new ArgumentNullException("definition");
            }
            if (match == null) {
                throw new ArgumentNullException("match");
            }

            var pattern = definition.Patterns.First(x => match.Groups[x.Key].Success).Value;
            if (pattern != null) {
                if (pattern is BlockPattern) {
                    return ProcessBlockPatternMatch(definition, (BlockPattern) pattern, match);
                }
                if (pattern is MarkupPattern) {
                    return ProcessMarkupPatternMatch(definition, (MarkupPattern) pattern, match);
                }
                if (pattern is WordPattern) {
                    return ProcessWordPatternMatch(definition, (WordPattern) pattern, match);
                }
            }

            return match.Value;
        }
Пример #11
0
 protected abstract string ProcessWordPatternMatch(Definition definition, WordPattern pattern, Match match);
Пример #12
0
 protected abstract string ProcessMarkupPatternMatch(Definition definition, MarkupPattern pattern, Match match);
Пример #13
0
 protected abstract string ProcessBlockPatternMatch(Definition definition, BlockPattern pattern, Match match);
Пример #14
0
 protected virtual string PreHighlight(Definition definition, string input)
 {
     return input;
 }
Пример #15
0
        protected override string ProcessWordPatternMatch(Definition definition, WordPattern pattern, Match match)
        {
            var style = CreateRtfPatternStyle(pattern.Style.Colors.ForeColor, pattern.Style.Colors.BackColor, pattern.Style.Font);

            return ("{" + String.Format(RtfFormat, style, match.Value) + "}");
        }
Пример #16
0
 protected override string ProcessWordPatternMatch(Definition definition, WordPattern pattern, Match match)
 {
     return ProcessPatternMatch(pattern, match);
 }
Пример #17
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();
        }
Пример #18
0
 private MatchEvaluator GetMatchEvaluator(Definition definition)
 {
     return match => ElementMatchHandler(definition, match);
 }
Пример #19
0
 protected override string PreHighlight(Definition definition, string input)
 {
     return HttpUtility.HtmlEncode(input);
 }
Пример #20
0
        private string HighlightUsingRegex(Definition definition, string input)
        {
            var regexOptions = GetRegexOptions(definition);
            var evaluator = GetMatchEvaluator(definition);
            var regexPattern = definition.GetRegexPattern();
            var output = Regex.Replace(input, regexPattern, evaluator, regexOptions);

            return output;
        }
Пример #21
0
 protected override string PostHighlight(Definition definition, string input)
 {
     return String.Format("<highlightedInput>{0}</highlightedInput>", input);
 }