Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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;
            }
        }
Пример #5
0
 private bool IntersectedWithHigherPriorityRule(RenderingRule rule)
 {
     return(RenderingRules.Where(r => r.Selector.Start != -1).Any(r => r.PriorityLevel < rule.PriorityLevel));
 }
Пример #6
0
 private bool IntersectedWithRenderedRule(string selection, RenderingRule rule)
 {
     return(selection.Contains(rule.ClosingTag) &&
            !selection.Contains(rule.OpeningTag));
 }