private void GenerateVirtualDocument() { var mjmlRoot = Document.QuerySelector <IElement>("mjml"); if (mjmlRoot == null) { throw new NullReferenceException(); } // LR: Create the root element for the virtual DOM VirtualDocument = CreateMjmlComponent(mjmlRoot) as MjmlRootComponent; if (!VirtualDocument.Element.Descendents <IElement>().Any()) { return; } TraverseElementTree(VirtualDocument.Element, VirtualDocument); }
private static string BuildHeadRaw(MjmlRootComponent virtualDocument) { var mjmlHead = virtualDocument.Children.FirstOrDefault(c => c.GetTagName().Equals("mj-head")); if (mjmlHead == null) { return(string.Empty); } var rawComponents = mjmlHead.Children.Where(c => c.IsRawElement()); StringBuilder sb = new StringBuilder(); foreach (var component in rawComponents) { sb.Append(component.RenderMjml()); } return(sb.ToString()); }
public MjmlAttributesComponent(IElement element, BaseComponent parent, MjmlRootComponent documentRoot) : base(element, parent, documentRoot) { }
public HeadComponent(IElement element, BaseComponent parent, MjmlRootComponent documentRoot = null) : base(element, parent) { VirtualDocument = documentRoot; }
public static string Build(MjmlRootComponent virtualDocument) { // Generate content string head = RenderHead(virtualDocument); string body = RenderBody(virtualDocument); bool forceOWADesktop = false; string html = $@" <!doctype html> <html {(!string.IsNullOrWhiteSpace(Language) ? $@"lang=""{Language}"" " : string.Empty)}xmlns=""http://www.w3.org/1999/xhtml"" xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:o=""urn:schemas-microsoft-com:office:office""> <head> <title> {Title} </title> <!--[if !mso]><!-- --> <meta http-equiv=""X-UA-Compatible"" content=""IE=edge""> <!--<![endif]--> <meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8""> <meta name=""viewport"" content=""width=device-width, initial-scale=1""> <style type=""text/css""> #outlook a {{ padding:0; }} body {{ margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%; }} table, td {{ border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt; }} img {{ border:0;height:auto;line-height:100%; outline:none;text-decoration:none;-ms-interpolation-mode:bicubic; }} p {{ display:block;margin:13px 0; }} </style> <!--[if mso]> <xml> <o:OfficeDocumentSettings> <o:AllowPNG/> <o:PixelsPerInch>96</o:PixelsPerInch> </o:OfficeDocumentSettings> </xml> <![endif]--> <!--[if lte mso 11]> <style type=""text/css""> .mj-outlook-group-fix {{ width:100% !important; }} </style> <![endif]--> { BuildFontsTags(body) } { BuildMediaQueriesTags(forceOWADesktop) } <style type=""text/css""> { BuildComponentsHeadStyle() } { BuildHeadStyle() } { BuildStyles() } </style> { BuildHeadRaw(virtualDocument) } </head> <body{(string.IsNullOrWhiteSpace(BackgroundColor) ? string.Empty : $@" style=""background-color:{BackgroundColor};""") }> { BuildPreview() } { body } </body> </html> "; var result = PreMailer.Net.PreMailer.MoveCssInline(html, false, "#ignore", BuildInlineStyles(), false); if (result.Warnings.Any()) { return(html); } return(result.Html); }
private static string RenderBody(MjmlRootComponent virtualDocument) { return(virtualDocument.Children.FirstOrDefault(c => c.GetTagName().Equals("mj-body"))?.RenderMjml()); }