public InlineElementRule(InlineElementType elementType, Regex regex, InlineElementConstraint constraint) { ElementType = elementType; Regex = regex; Constraint = constraint; }
private InlineElementRuleMatch <TInlineElement> CreateInlineElement <TInlineElement>(Match match, InlineElementConstraint constraint) where TInlineElement : IInlineElement, IText, IAttributable, new() { string unEscapedAttributes = null; var firstMatch = match.Groups[0].Value; if (firstMatch.StartsWith("\\")) { if (constraint == InlineElementConstraint.Constrained && !string.IsNullOrEmpty(match.Groups[2].Value)) { unEscapedAttributes = match.Groups[2].Value; } else { var element = new TInlineElement { Text = firstMatch.Substring(1, firstMatch.Length - 1) }; return(new InlineElementRuleMatch <TInlineElement>(element, match.Index, match.Index + match.Length, new string(' ', match.Length))); } } if (constraint == InlineElementConstraint.Constrained) { if (unEscapedAttributes != null) { // TODO: Parse the unEscapedAttributes and add to element var element = new TInlineElement { Text = match.Groups[3].Value }; var startIndex = match.Value[0] == ' ' || match.Value[0] == '\t' ? match.Index + 1 : match.Index; var endIndex = match.Index + match.Length; return(new InlineElementRuleMatch <TInlineElement>(element, startIndex, endIndex, new string(' ', match.Length))); } else { var attributes = ParseQuotedAttributes(match.Groups[2].Value); var element = new TInlineElement { Text = match.Groups[3].Value }; if (attributes != null) { element.Attributes.Add(attributes); } var group1 = match.Groups[1].Value; var startIndex = !string.IsNullOrEmpty(group1) ? match.Index + group1.Length : match.Index; var endIndex = match.Index + match.Length; //TODO: do something with match.Groups[1].Value var replacement = !string.IsNullOrEmpty(group1) ? group1 + new string(' ', match.Length - group1.Length) : new string(' ', match.Length); return(new InlineElementRuleMatch <TInlineElement>(element, startIndex, endIndex, replacement)); } } else { var element = new TInlineElement { Text = match.Groups[2].Value }; var attributes = ParseQuotedAttributes(match.Groups[1].Value); if (attributes != null) { element.Attributes.Add(attributes); } return(new InlineElementRuleMatch <TInlineElement>(element, match.Index, match.Index + match.Length, new string(' ', match.Length))); } }