private string DeleteMarks(RenderingRule rule, string rawText) { var selection = rule.GetSelection(rawText); var renderedText = rawText.Replace(selection, rule.Selector.Start, rule.Selector.GetLength()); return(renderedText); }
public string RenderWithPriority(RenderingRule rule, string rawText) { string renderedText; var selection = rule.GetSelection(rawText); var intersectedRules = RenderingRules.Where(r => IntersectedWithRenderedRule(selection, r)).ToList(); if (intersectedRules.Any()) { foreach (var r in intersectedRules) { rule.Selector.Start += r.OpeningTag.Length - 1; } return(DeleteMarks(rule, rawText)); } if (IntersectedWithHigherPriorityRule(rule)) { var oldEndOfSelection = rule.Selector.End; var oldStartOfSelection = rule.Selector.Start; renderedText = DeleteMarks(rule, rawText); MoveIntersectedStarts(rule, oldStartOfSelection, oldEndOfSelection); return(renderedText); } renderedText = Render(rule, rawText); rule.Selector.ResetSelection(); return(renderedText); }
private string Render(RenderingRule rule, string rawText) { var selection = rule.GetSelection(rawText); var tagedSelection = String.Concat(rule.OpeningTag, selection, rule.ClosingTag); var renderedText = rawText.Replace(tagedSelection, rule.Selector.Start, rule.Selector.GetLength()); return(renderedText); }
private void MoveIntersectedStarts(RenderingRule rule, int oldStartOfSelection, int oldEndOfSelection) { var intersectedRules = RenderingRules.Where(r => r.Selector.Start < oldEndOfSelection) .Where(r => r.Selector.Start > oldStartOfSelection) .ToList(); foreach (var r in intersectedRules) { r.Selector.Start -= rule.Mark.Length; } }
private bool IntersectedWithHigherPriorityRule(RenderingRule rule) { return(RenderingRules.Where(r => r.Selector.Start != -1).Any(r => r.PriorityLevel < rule.PriorityLevel)); }
private bool IntersectedWithRenderedRule(string selection, RenderingRule rule) { return(selection.Contains(rule.ClosingTag) && !selection.Contains(rule.OpeningTag)); }