public void Convert_NoPluginsTest() { var elements = new OpenXmlElement[] { new Paragraph() }; var conversionP = new ConversionParameter { Elements = elements, Stream = new MemoryStream() }; var ex = Assert.ThrowsException <InvalidOperationException>(() => _instance.Convert(conversionP)); }
public static void Convert(string URL) { HtmlConversionOptions options = new HtmlConversionOptions(false); HtmlConverter htmlConverter = new HtmlConverter(new Uri(URL), options); htmlConverter.Convert("converter-output.pdf"); }
public string wrapMdNodeInHtml(MdNode mdNode) { var tree = new MdTree(mdNode); var htmlConverter = new HtmlConverter(); return(htmlConverter.Convert(tree)); }
public void TableWithAnchors() { const string html = @"<table> <thead> <tr> <th><a href=""google.com"">Abc</a></th> <th>Def</th> </tr> </thead> <tbody> <tr> <td><a href=""google.com"">Ghi</a></td> <td>Jkl</td> </tr> <tr> <td>Mno</td> <td>Pqr</td> </tr> </tbody> </table>"; const string expected = @"| [Abc](google.com ""Abc"") | Def | | --- | --- | | [Ghi](google.com ""Ghi"") | Jkl | | Mno | Pqr | "; var node = HtmlNode.CreateNode(html); var markdown = HtmlConverter.Convert(node); Assert.AreEqual(expected, markdown); }
public void CustomRenderCallbacksAreUsed() { var ops = JArray.Parse( "[{ insert: { video: \"http\" } }, { insert: 'aa' }]"); var qdc = new HtmlConverter(ops); var html = qdc.Convert(); html.Should().Contain("iframe"); qdc = new HtmlConverter(ops, new HtmlConverterOptions { BeforeRenderer = (gt, g) => "" }); html = qdc.Convert(); html.Should().Contain("<iframe"); html.Should().Contain("aa"); qdc = new HtmlConverter(ops, new HtmlConverterOptions { AfterRenderer = (gt, g) => "" }); html = qdc.Convert(); html.Should().BeEmpty(); }
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 CustomInsertTypesRenderAsBlock() { var ops = JArray.Parse(@"[ {insert: 'hello '}, { insert: { myblot: 'my friend' } }, { insert: '!' }, {insert: {myblot: 'how r u?'}, attributes: {renderAsBlock: true}} ]"); CustomRenderer renderer = (op, contextOp) => { var insert = (InsertDataCustom)op.Insert; if (insert.CustomType == "myblot") { return(op.Attributes.RenderAsBlock == true ? $"<div>{insert.Value}</div>" : insert.Value.ToString()); } return("unknown"); }; var qdc = new HtmlConverter(ops, new HtmlConverterOptions { CustomRenderer = renderer }); var html = qdc.Convert(); html.Should().Be("<p>hello my friend!</p><div>how r u?</div>"); }
public static void Convert() { HtmlConversionOptions options = new HtmlConversionOptions(false); HtmlConverter htmlConverter = new HtmlConverter(new Uri(@"https://en.wikipedia.org"), options); htmlConverter.Convert("converter-output.pdf"); }
public void ConvertTable() { const string html = @"<table> <thead> <tr> <th>Abc</th> <th>Def</th> </tr> </thead> <tbody> <tr> <td>Ghi</td> <td>Jkl</td> </tr> <tr> <td>Mno</td> <td>Pqr</td> </tr> </tbody> </table>"; const string expected = @"| Abc | Def | | --- | --- | | Ghi | Jkl | | Mno | Pqr | "; var node = HtmlNode.CreateNode(html); var markdown = HtmlConverter.Convert(node); Assert.AreEqual(expected, markdown); }
public void CodeBlockOneLine() { var qdc = new HtmlConverter(new JArray( _codeBlockOps[0], _codeBlockOps[1])); var html = qdc.Convert(); html.Should().Be("<pre>line 1</pre>"); }
public void createHtmlHyperlinkWithAbsolutePath() { var htmlConverter = new HtmlConverter(@"http://test.ru/"); var tree = new MdTree(new MdNode("test](/img", new HyperlinkTag())); var html = htmlConverter.Convert(tree); html.ShouldBeEquivalentTo($"<a href=\"http://test.ru//img\">test</a>"); }
public Action <Section> Convert(string contents) { var converter = new MarkdownSharp.Markdown(options); var html = converter.Transform(contents); var htmlConverter = new HtmlConverter(); return(htmlConverter.Convert(html)); }
public void PositionalStylesUseDefaultTag() { var qdc = new HtmlConverter(_posOps); var html = qdc.Convert(); html.Should().Contain("<p class=\"ql-align"); html.Should().Contain("<p class=\"ql-direction"); html.Should().Contain("<p class=\"ql-indent"); }
public Action <Section> Convert(string contents) { var pipeline = new MarkdownPipelineBuilder().UseEmphasisExtras().Build(); var html = Markdig.Markdown.ToHtml(contents, pipeline); var htmlConverter = new HtmlConverter(); return(htmlConverter.Convert(html)); }
public void CodeBlockSimple() { //console.log(encodeHtml("<p>line 4</p>")); var qdc = new HtmlConverter(_codeBlockOps); var html = qdc.Convert(); html.Should().Be("<pre>line 1\nline 2\nline 3\n" + HtmlHelpers.EncodeHtml("<p>line 4</p>") + "</pre>"); }
public void ConvertAnchorWithFormatterElement() { const string html = @"<a href=""abc.html""><b>Google</b></a>"; const string expected = @"[**Google**](abc.md ""Google"")"; var node = HtmlNode.CreateNode(html); var markdown = HtmlConverter.Convert(node); Assert.AreEqual(expected, markdown); }
public void ConvertAnchorWithImage() { const string html = @"<a href=""abc.html""><img src=""google.com"" alt=""Google"" /></a>"; const string expected = @"[![Google](google.com ""Google"")](abc.md """")"; var node = HtmlNode.CreateNode(html); var markdown = HtmlConverter.Convert(node); Assert.AreEqual(expected, markdown); }
public void TargetAttrDefaultLinkTarget() { var qdc = new HtmlConverter(_targetOps); var html = qdc.Convert(); html.Should().Be( "<p><a href=\"http://#\" target=\"_self\">A</a>" + "<a href=\"http://#\" target=\"_blank\">B</a>" + "<a href=\"http://#\" target=\"_blank\">C</a></p>"); }
public void ConvertImage() { const string html = "<img src=\"logo.png\" alt=\"text\" title=\"Title\"/>"; const string expected = "![text](logo.png \"Title\")"; var node = HtmlNode.CreateNode(html); var markdown = HtmlConverter.Convert(node); Assert.AreEqual(expected, markdown); }
public void ConvertBold() { const string html = "<b>abc</b>"; const string expected = "**abc**"; var node = HtmlNode.CreateNode(html); var markdown = HtmlConverter.Convert(node); Assert.AreEqual(expected, markdown); }
public void ConvertItalic() { const string html = "<i>abc</i>"; const string expected = "_abc_"; var node = HtmlNode.CreateNode(html); var markdown = HtmlConverter.Convert(node); Assert.AreEqual(expected, markdown); }
public void ConvertBreak() { const string html = "<br />"; var expected = Environment.NewLine + Environment.NewLine; var node = HtmlNode.CreateNode(html); var markdown = HtmlConverter.Convert(node); Assert.AreEqual(expected, markdown); }
public void ConvertCode() { const string html = "<code>abc</code>"; const string expected = "`abc`"; var node = HtmlNode.CreateNode(html); var markdown = HtmlConverter.Convert(node); Assert.AreEqual(expected, markdown); }
public void CustomBlotEmptyStringWithNoRenderer() { var ops = JArray.Parse(@"[ { insert: { customstuff: 'my val' } } ]"); var qdc = new HtmlConverter(ops); var html = qdc.Convert(); html.Should().Be("<p></p>"); }
public void AnchorConvert() { const string html = "<a href=\"UnityEngine.InputLegacyModule.html\">UnityEngine.InputLegacyModule</a>"; const string expected = "[UnityEngine.InputLegacyModule](UnityEngine.InputLegacyModule.md \"UnityEngine.InputLegacyModule\")"; var node = HtmlNode.CreateNode(html); var markdown = HtmlConverter.Convert(node); Assert.AreEqual(expected, markdown); }
public void ConstructorSetsDefaultInlineStyles() { var qdc = new HtmlConverter(_hugeOps, new HtmlConverterOptions() { InlineStyles = new InlineStyles() }); var html = qdc.Convert(); html.Should().Contain("<span style=\"font-size: 2.5em\">huge</span>"); }
public string createHtmlWithCssClass(MdNode mdNode) { var tree = new MdTree(mdNode); var properties = new CssProperties() { ClassName = "mdClass" }; var htmlConverter = new HtmlConverter(properties); return(htmlConverter.Convert(tree)); }
public void CustomInsertTypesInCodeBlocks() { var qdc = new HtmlConverter(new JArray( _customTypeCodeBlockOps[0], _customTypeCodeBlockOps[1]), new HtmlConverterOptions { CustomRenderer = _customTypeCodeBlockRenderer }); var html = qdc.Convert(); html.Should().Be("<pre>:</pre>"); }
public string wrapInnerMdNodeInHtml(MdNode mdNode) { var htmlConverter = new HtmlConverter(); mdNode.InnerMdNodes.Add(new MdNode("a", new UnderscoreTag())); mdNode.InnerMdNodes.Add(new MdNode("text", new EmptyTag())); mdNode.InnerMdNodes.Add(new MdNode("b", new UnderscoreTag())); var tree = new MdTree(mdNode); return(htmlConverter.Convert(tree)); }
public async Task <IActionResult> SaveDocument(int id) { HtmlConversionOptions options = new HtmlConversionOptions(false); options.Title = "Contrato " + id + " - LocalizaCS"; HtmlConverter htmlConverter = new HtmlConverter(new Uri("http://localhost:8680/TbLocacoes/Contrato/" + id), options); htmlConverter.Convert("C:/Users/talita.salles/source/repos/LocalizaCS/wwwroot/Contratos/Contrato_" + id + ".pdf"); return(Redirect("http://localhost:8680/Contratos/Contrato_2.pdf")); }
public void ConvertHtmlContentToPdf() { var converter = new HtmlConverter(); var setting = new GenerateSettings { HtmlFileContent = "<b>Bold Text</b><br /><br /><i>Italic Text</i>", OutputType = OutputType.PDF, }; setting.GlobalOptions.FooterHtmlUrl = "http://www.oracle.com/splash/rpls/embargoed.html"; setting.GlobalOptions.HeaderHtmlUrl = "http://wkhtmltopdf.org/libwkhtmltox/"; setting.GlobalOptions.MarginTop = "30mm"; setting.GlobalOptions.MarginBottom = "30mm"; setting.GlobalOptions.ShowFooterLine = true; setting.GlobalOptions.ShowHeaderLine = true; var filePath = converter.Convert(setting); Assert.IsTrue(File.Exists(filePath)); }