The next generation of the Teknik Services. Written in ASP.NET. Fork for blog tags.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

MarkdownHelper.cs 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Web;
  2. using System.Web.Mvc;
  3. using MarkdownDeep;
  4. namespace Teknik.Utilities
  5. {
  6. /// <summary>
  7. /// Helper class for transforming Markdown.
  8. /// </summary>
  9. public static partial class MarkdownHelper
  10. {
  11. /// <summary>
  12. /// Transforms a string of Markdown into HTML.
  13. /// </summary>
  14. /// <param name="text">The Markdown that should be transformed.</param>
  15. /// <returns>The HTML representation of the supplied Markdown.</returns>
  16. public static IHtmlString Markdown(string text)
  17. {
  18. // Transform the supplied text (Markdown) into HTML.
  19. var markdownTransformer = new Markdown();
  20. markdownTransformer.ExtraMode = true;
  21. string html = markdownTransformer.Transform(text);
  22. // Wrap the html in an MvcHtmlString otherwise it'll be HtmlEncoded and displayed to the user as HTML :(
  23. return new MvcHtmlString(html);
  24. }
  25. /// <summary>
  26. /// Transforms a string of Markdown into HTML.
  27. /// </summary>
  28. /// <param name="helper">HtmlHelper - Not used, but required to make this an extension method.</param>
  29. /// <param name="text">The Markdown that should be transformed.</param>
  30. /// <returns>The HTML representation of the supplied Markdown.</returns>
  31. public static IHtmlString Markdown(this HtmlHelper helper, string text)
  32. {
  33. // Just call the other one, to avoid having two copies (we don't use the HtmlHelper).
  34. return Markdown(text);
  35. }
  36. }
  37. }