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; BeforeRenderer beforeRenderer = (gtype, group) => { if (gtype == GroupType.Block) { ++blockCount; } return(""); }; var qdc = new HtmlConverter(ops, new HtmlConverterOptions() { BeforeRenderer = beforeRenderer }); qdc.Convert(); blockCount.Should().Be(3); }
public void CustomHtmlFromCallbackUsed() { var ops = JArray.Parse( @"[{ insert: { video: ""http"" } }, { insert: 'aa' }]"); BeforeRenderer beforeRenderer = (groupType, group) => "<my custom video html>"; var qdc = new HtmlConverter(ops, new HtmlConverterOptions { BeforeRenderer = beforeRenderer }); var html = qdc.Convert(); html.Should().Contain("<my custom"); }
public void BeforeAndAfterRenderCallbacks() { BeforeRenderer beforeRenderer = (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(""); }; AfterRenderer afterRenderer = (groupType, html) => { if (groupType == GroupType.InlineGroup) { html.Should().Contain("<strong>hello"); } else if (groupType == GroupType.Video) { html.Should().StartWith("<iframe"); } else if (groupType == GroupType.Block) { html.Should().StartWith("<blockquote"); } else { html.Should().Contain("list item 1<ul><li"); } return(html); }; var qdc = new HtmlConverter(_beforeAndAfterOps, new HtmlConverterOptions() { BeforeRenderer = beforeRenderer, AfterRenderer = afterRenderer }); qdc.Convert(); }