Esempio n. 1
0
        public async Task EmphasisAndBoldHTMLComplex_CaretOnEmphasisAndBold_OnCommandEmphasisAndBold_HtmlIsRenderedAsNoEmphasisNorBold()
        {
            string html         = @"<div style=""font-family:Courier;"">the<span style=""color:red"">red <em><strong>and</em></strong> <span style=""color:blue"">blue </span></span>source</div><p>This is a paragraph element</p>";
            string assertedHtml = @"<body><div style=""font-family:Courier;"">the<span style=""color:red"">red and <span style=""color:blue"">blue </span></span>source</div><p>This is a paragraph element</p></body>";

            var document = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = new MarkUpRange()
            {
                PositionEnd = 9, PositionStart = 9
            };

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);
            var range  = ranges.First();

            range.ApplyStyleCommand(selectionRange, EStyleCommand.Emphasis, document, RangeNode.ApplyAttributeValueNone);
            var newHtml = document.Body.ToHtml();

            document = await Factory.DocumentFactory.GetDocument(newHtml);

            bodyNodes = document.Body.GetDescendants();

            ranges = RangeNode.InRange(bodyNodes, selectionRange);
            range  = ranges.First();

            range.ApplyStyleCommand(selectionRange, EStyleCommand.Bold, document, RangeNode.ApplyAttributeValueNone);
            newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 1);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }
Esempio n. 2
0
        public async Task EmphasisAndBoldHTML_CaretOnEmphasisAndBold_OnCommandEmphasisAndBold_HtmlIsRenderedAsNoEmphasisNorBold()
        {
            string html         = @"<body><div>This <em><strong>is</strong></em> a test</div>";
            string assertedHtml = @"<body><div>This is a test</div></body>";
            var    document     = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = new MarkUpRange()
            {
                PositionEnd = 6, PositionStart = 6
            };

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);
            var range  = ranges.First();

            range.ApplyStyleCommand(selectionRange, EStyleCommand.Emphasis, document, RangeNode.ApplyAttributeValueNone);
            var newHtml = document.Body.ToHtml();

            document = await Factory.DocumentFactory.GetDocument(newHtml);

            bodyNodes = document.Body.GetDescendants();

            ranges = RangeNode.InRange(bodyNodes, selectionRange);
            range  = ranges.First();

            range.ApplyStyleCommand(selectionRange, EStyleCommand.Bold, document, RangeNode.ApplyAttributeValueNone);
            newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 1);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }
Esempio n. 3
0
        public async Task ParentWalk_WithDeepNesting__ReturnsParentNode()
        {
            var nodes = await bodyNodes(@"<body><span><div>Line1<div>Line2</div></div></span></body>");

            var         expectedNodeHtml = @"<div>Line1<div>Line2</div></div>";
            MarkUpRange selectionRange   = new MarkUpRange()
            {
                PositionEnd = 7, PositionStart = 7
            };
            var ranges = RangeNode.InRange(nodes, selectionRange);
            var range  = ranges.First();
            var parent = range.GetParentOfElementThatContainsTheNodeWalk(range.Node);

            Assert.AreEqual(parent.ToHtml(), expectedNodeHtml);
            await Task.FromResult(0);
        }
Esempio n. 4
0
        public async Task ParentWalkToBody_Simple_ReturnsBodyWalk()
        {
            var nodes = await bodyNodes(@"<body><span>This is a test</span></body>");

            var         expectedNodeHtml = @"<body><span>This is a test</span></body>";
            MarkUpRange selectionRange   = new MarkUpRange()
            {
                PositionEnd = 3, PositionStart = 3
            };
            var ranges = RangeNode.InRange(nodes, selectionRange);
            var range  = ranges.First();
            var parent = range.GetParentOfElementThatContainsTheNodeWalk(range.Node);

            Assert.AreEqual(parent.ToHtml(), expectedNodeHtml);
            await Task.FromResult(0);
        }
Esempio n. 5
0
        public async Task ParentWalk_NoParent_ReturnsOrginalNode()
        {
            var nodes = await bodyNodes(@"<div>This is a test</div>");

            var         expectedNodeHtml = @"<body><div>This is a test</div></body>";
            MarkUpRange selectionRange   = new MarkUpRange()
            {
                PositionEnd = 1, PositionStart = 1
            };
            var ranges = RangeNode.InRange(nodes, selectionRange);
            var range  = ranges.First();
            var parent = range.GetParentOfElementThatContainsTheNodeWalk(range.Node);

            Assert.AreEqual(parent.ToHtml(), expectedNodeHtml);
            await Task.FromResult(0);
        }
Esempio n. 6
0
        public async Task EmptyBody_ReplaceWithH1__ReturnsInEmpyH1T()
        {
            var nodes = await bodyNodes(@"<body><div></div></body>");

            var         expectedNodeHtml = @"<body><h1></h1></body>";
            MarkUpRange selectionRange   = new MarkUpRange()
            {
                PositionEnd = 1, PositionStart = 1
            };
            var ranges = RangeNode.InRange(nodes, selectionRange);
            var range  = ranges.First();

            range.ApplyBlockCommand("h1", document);

            Assert.AreEqual(document.Body.ToHtml(), expectedNodeHtml);
            await Task.FromResult(0);
        }
Esempio n. 7
0
        public async Task DivDeepNested_ReplaceDivToH1__ReturnsReplacedDiv()
        {
            var nodes = await bodyNodes(@"<body><span><div>Line1<div>Line2</div></div></span></body>");

            var         expectedNodeHtml = @"<body><span><div>Line1<h1>Line2</h1></div></span></body>";
            MarkUpRange selectionRange   = new MarkUpRange()
            {
                PositionEnd = 7, PositionStart = 7
            };
            var ranges = RangeNode.InRange(nodes, selectionRange);
            var range  = ranges.First();

            //var parent = range.GetParentElementWalk(range.Node);

            range.ApplyBlockCommand("h1", document);

            Assert.AreEqual(document.Body.ToHtml(), expectedNodeHtml);
            await Task.FromResult(0);
        }
Esempio n. 8
0
        public async Task MultipleDivOnBody_ReplaceSecondDivToH1__ReturnsReplacedDiv()
        {
            var nodes = await bodyNodes(@"<body><div>Line1</div><div>Line2</div></body>");

            var         expectedNodeHtml = @"<body><div>Line1</div><h1>Line2</h1></body>";
            MarkUpRange selectionRange   = new MarkUpRange()
            {
                PositionEnd = 8, PositionStart = 8
            };
            var ranges = RangeNode.InRange(nodes, selectionRange);
            var range  = ranges.First();

            var parent = range.GetParentOfElementThatContainsTheNodeWalk(range.Node);

            range.ApplyBlockCommand("h1", document);

            Assert.AreEqual(document.Body.ToHtml(), expectedNodeHtml);
            await Task.FromResult(0);
        }
Esempio n. 9
0
        public async Task SiblingsDivs_FirstSetToHeading1_FirstIsRenderedAsHeading1()
        {
            string html         = @"<div>the red and blue source</div><div>second line</div>";
            string assertedHtml = "<body><h1>the red and blue source</h1><div>second line</div></body>";
            var    document     = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = MarkUpRangeFactory.CursorRange(html);

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);
            var range  = ranges.First();

            range.ApplyBlockCommand("H1", document);
            var newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 1);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }
Esempio n. 10
0
        public async Task HtmlWithRangeOverTwoDivs_SetToHeading1_HtmlIsRenderedWithTwoAsHeading1()
        {
            string html         = @"<div>the red and blue source</div><div>just another paragraph</div>";
            string assertedHtml = "<body><h1>the red and blue source</h1><h1>just another paragraph</h1></body>";
            var    document     = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = MarkUpRangeFactory.SelectionDivExtendedRange(html);

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);

            foreach (var range in ranges)
            {
                range.ApplyBlockCommand("H1", document);
            }
            var newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 2);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }
Esempio n. 11
0
        public async Task H1WithStylingAndChildNodesAndMextSibling_SetToHeading1_HtmlIsRenderedAsDiv()
        {
            string html         = @"<body><h1 style=""font-family:Courier;"">the <span style=""color:red"">red and <span style=""color:blue"">blue </span></span>source <span style=""color:orange"">from holland </span> with greetings</h1><p>This is a paragraph element</p></body>";
            string assertedHtml = @"<body><div style=""font-family:Courier;"">the <span style=""color:red"">red and <span style=""color:blue"">blue </span></span>source <span style=""color:orange"">from holland </span> with greetings</div><p>This is a paragraph element</p></body>";
            var    document     = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = new MarkUpRange()
            {
                PositionEnd = 18, PositionStart = 18
            };

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);
            var range  = ranges.First();

            range.ApplyBlockCommand("H1", document);
            var newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 1);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }
Esempio n. 12
0
        public async Task HtmlWithCaretOnSecondParagraph_setHeading1_SecondParagraphIsRenderedAsAsHeading()
        {
            var    html         = @"<div>​first paragraphe</div><div>​second paragraphe</div>";
            string assertedHtml = @"<body><div>​first paragraphe</div><h1>​second paragraphe</h1></body>";
            var    document     = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = new MarkUpRange()
            {
                PositionEnd = 20, PositionStart = 20
            };

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);
            var range  = ranges.First();

            range.ApplyBlockCommand("H1", document);
            var newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 1);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }
Esempio n. 13
0
        public async Task Empty_SetToHeading1_HtmlIsRenderedAsHeading1()
        {
            string html         = @"<div></div>";
            string assertedHtml = "<body><h1></h1></body>";
            var    document     = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = new MarkUpRange()
            {
                PositionEnd = 1, PositionStart = 1
            };

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);
            var range  = ranges.First();

            range.ApplyBlockCommand("H1", document);
            var newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 1);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }
Esempio n. 14
0
        public async Task DivWithStyling_SetToHeading1_HtmlIsRenderedAsStyledHeading1()
        {
            string html         = @"<body><div style=""font-family:Courier;"">the red and blue source</div></body>";
            string assertedHtml = @"<body><h1 style=""font-family:Courier;"">the red and blue source</h1></body>";
            var    document     = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = new MarkUpRange()
            {
                PositionEnd = 2, PositionStart = 2
            };

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);
            var range  = ranges.First();

            range.ApplyBlockCommand("H1", document);
            var newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 1);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }
Esempio n. 15
0
        public async Task SpanWithStyle_UndoStyle_SpanIsRemoved()
        {
            string html         = @"<div>​this <span style=""font-family:Courier;"">is</span> a test</div>";
            string assertedHtml = @"<body><div>​this is a test</div></body>";
            var    document     = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = new MarkUpRange()
            {
                PositionEnd = 6, PositionStart = 6
            };

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);
            var range  = ranges.First();

            range.ApplyStyleCommand(selectionRange, EStyleCommand.FormatClear, document, () => "");
            var newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 1);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }
Esempio n. 16
0
        public async Task NoAlignHTML_SetToLeftAlignOn_HtmlIsRenderedAsLeftAlign()
        {
            string html         = @"<div>This is a test</div>";
            string assertedHtml = @"<body><div style=""text-align:left;"">This is a test</div></body>";
            var    document     = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = new MarkUpRange()
            {
                PositionEnd = 1, PositionStart = 1
            };

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);
            var range  = ranges.First();

            range.ApplyStyleCommand(selectionRange, EStyleCommand.TextAlignLeft, document, () => "left");
            var newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 1);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }
Esempio n. 17
0
        public async Task HtmlWithCaretOnSpanWithinDiv_setHeading1_DivIsRenderedAsHeading()
        {
            string html         = "<div>the <span>red</span> and blue source</div>";
            string assertedHtml = @"<body><h1>the <span>red</span> and blue source</h1></body>";

            var document = await Factory.DocumentFactory.GetDocument(html);

            var bodyNodes = document.Body.GetDescendants();

            MarkUpRange selectionRange = new MarkUpRange()
            {
                PositionEnd = 5, PositionStart = 5
            };

            var ranges = RangeNode.InRange(bodyNodes, selectionRange);
            var range  = ranges.First();

            range.ApplyBlockCommand("H1", document);
            var newHtml = document.Body.ToHtml();

            Assert.IsTrue(ranges.Count() == 1);
            Assert.AreEqual(newHtml, assertedHtml);
            await Task.FromResult(0);
        }