Пример #1
0
        public void BeforeRenderCalledWithBlockGroupTypeForAlignIndentAndDirection()
        {
            var ops = JArray.Parse(@"[
                { insert: 'align' },
                { insert: '\n', attributes: { align: 'right' } },
                { insert: 'rtl' },
                { insert: '\n', attributes: { direction: 'rtl' } },
                { insert: 'indent 1' },
                { insert: '\n', attributes: { indent: 1 } },
            ]");

            int blockCount = 0;
            XmlBeforeRenderer beforeRenderer = (doc, gtype, group) =>
            {
                if (gtype == GroupType.Block)
                {
                    ++blockCount;
                }
                return(null);
            };

            var qdc = new XmlConverter(ops,
                                       new XmlConverterOptions()
            {
                BeforeRenderer = beforeRenderer
            });

            qdc.Convert();
            blockCount.Should().Be(3);
        }
Пример #2
0
        public void CustomHtmlFromCallbackUsed()
        {
            var ops = JArray.Parse(
                @"[{ insert: { video: ""http"" } }, { insert: 'aa' }]");
            XmlBeforeRenderer beforeRenderer = (doc, groupType, group) =>
                                               doc.CreateElement("my-custom-video-xml");
            var qdc = new XmlConverter(ops,
                                       new XmlConverterOptions {
                BeforeRenderer = beforeRenderer
            });
            var xml = qdc.Convert().OuterXml;

            xml.Should().Contain("<my-custom");
        }
Пример #3
0
        public void BeforeAndAfterRenderCallbacks()
        {
            XmlBeforeRenderer beforeRenderer = (doc, groupType, data) =>
            {
                if (groupType == GroupType.InlineGroup)
                {
                    var op = ((InlineGroup)data).Ops[0];
                    op.Attributes.Bold.Should().BeTrue();
                }
                else if (groupType == GroupType.Video)
                {
                    var op = (VideoItem)data;
                    op.Op.Insert.Should().BeOfType <InsertDataVideo>();
                }
                else if (groupType == GroupType.Block)
                {
                    var bg = (BlockGroup)data;
                    bg.Op.Attributes.Blockquote.Should().BeTrue();
                    bg.Ops.Count.Should().Be(2);
                }
                else if (groupType == GroupType.List)
                {
                    var lg = (ListGroup)data;
                    lg.Items.Count.Should().Be(1);
                }
                else
                {
                    throw new Exception($"Unknown group type {groupType}");
                }
                return(null);
            };
            XmlAfterRenderer afterRenderer = (doc, groupType, node) =>
            {
                if (groupType == GroupType.InlineGroup)
                {
                    node.OuterXml.Should().Contain("<strong>hello");
                }
                else if (groupType == GroupType.Video)
                {
                    node.OuterXml.Should().StartWith("<iframe");
                }
                else if (groupType == GroupType.Block)
                {
                    node.OuterXml.Should().StartWith("<blockquote");
                }
                else
                {
                    node.OuterXml.Should().Contain("list item 1<ul><li");
                }
                return(node);
            };

            var qdc = new XmlConverter(_beforeAndAfterOps,
                                       new XmlConverterOptions()
            {
                BeforeRenderer = beforeRenderer,
                AfterRenderer  = afterRenderer
            });

            qdc.Convert();
        }