public static void Main(string[] args) { // Get executing path and /example.md full path string exeLocation = Assembly.GetExecutingAssembly().Location; string path = Path.GetDirectoryName(exeLocation); string template = Path.Combine(path, "example.md"); // Create the markdown-razor template compiler MarkdownFormat format = new MarkdownFormat(); string contents = File.ReadAllText(template); var page = new MarkdownPage(format, path, "example", contents); format.AddPage(page); // Create our view container (ViewBag) var view = new Dictionary <string, object>() { { "examples", examples } }; // Compile and output. // This can be redirected to html file // e.g. RazorExample.exe > output.html var html = format.RenderDynamicPageHtml("example", view); Console.WriteLine(html); }
public void Layout_MasterPage_Scenarios_Adding_Sections() { var websiteTemplate = @"<!DOCTYPE html> <html> <head> <title>Simple Site</title> </head> <body> <div id=""header""> <a href=""/"">Home</a> <a href=""/About"">About</a> </div> <div id=""left-menu""> <!--@Menu--> </div> <div id=""body""> <!--@Body--> </div> <div id=""footer""> <!--@Footer--> </div> </body> </html>".NormalizeNewLines(); var pageTemplate = @"@Layout ~/websiteTemplate # About this Site This is some content that will make up the ""about"" page of our web-site. We'll use this in conjunction with a layout template. The content you are seeing here comes from ^^^websiteTemplate. And obviously I can have code in here too. Here is the current date/year: @DateTime.Now.Year @section Menu { - About Item 1 - About Item 2 } @section Footer { This is my custom footer for Home } "; var expectedHtml = @"<!DOCTYPE html> <html> <head> <title>Simple Site</title> </head> <body> <div id=""header""> <a href=""/"">Home</a> <a href=""/About"">About</a> </div> <div id=""left-menu""> <ul> <li>About Item 1</li> <li>About Item 2</li> </ul> </div> <div id=""body""> <h1>About this Site</h1> <p>This is some content that will make up the ""about"" page of our web-site. We'll use this in conjunction with a layout template. The content you are seeing here comes from ^^^websiteTemplate.</p> <p>And obviously I can have code in here too. Here is the current date/year: 2011</p> </div> <div id=""footer""> <p>This is my custom footer for Home</p> </div> </body> </html>".NormalizeNewLines(); var markdownFormat = new MarkdownFormat(); markdownFormat.AddPage( new MarkdownPage(markdownFormat, @"C:\path\to\page-tpl", PageName, pageTemplate)); markdownFormat.AddTemplate(@"C:\path\to\websiteTemplate", websiteTemplate); var html = markdownFormat.RenderDynamicPageHtml(PageName); Console.WriteLine(html); Assert.That(html, Is.EqualTo(expectedHtml)); }