Posted By

jiewmeng on 08/22/10


Tagged

c markdown


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


C#: Parse markdown into HTML (with template)


 / Published in: C#
 

using markdown sharp StreamReader to read template & StreamWriter to write to HTML

  1. string html;
  2. string theme;
  3. StreamReader reader;
  4. Markdown parser = new Markdown();
  5. html = parser.Transform(txtEditor.Text);
  6.  
  7. reader = new StreamReader(@"Themes\Simple\simple.html");
  8. theme = reader.ReadToEnd();
  9. html = Regex.Replace(theme, "{body}", html);
  10. html = Regex.Replace(html, "{title}", "Markdown Edit Document");
  11.  
  12. webPreview.NavigateToString(html);
  13.  
  14. StreamWriter writer = new StreamWriter(@"C:\new.html");
  15. writer.Write(html);
  16. writer.Flush();
  17. writer.Close();
  18.  
  19. reader.Close();
  20.  
  21. // html template like ...
  22. <!DOCTYPE HTML>
  23. <html lang="en-US">
  24. <head>
  25. <meta charset="UTF-8">
  26. <title>{title}</title>
  27. </head>
  28. <body>
  29. {body}
  30. </body>
  31. </html>

Report this snippet  

You need to login to post a comment.