The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MarkdownHelper.cs 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Web;
  2. using System.Web.Mvc;
  3. using MarkdownDeep;
  4. namespace Teknik.Helpers
  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. string html = markdownTransformer.Transform(text);
  21. // Wrap the html in an MvcHtmlString otherwise it'll be HtmlEncoded and displayed to the user as HTML :(
  22. return new MvcHtmlString(html);
  23. }
  24. /// <summary>
  25. /// Transforms a string of Markdown into HTML.
  26. /// </summary>
  27. /// <param name="helper">HtmlHelper - Not used, but required to make this an extension method.</param>
  28. /// <param name="text">The Markdown that should be transformed.</param>
  29. /// <returns>The HTML representation of the supplied Markdown.</returns>
  30. public static IHtmlString Markdown(this HtmlHelper helper, string text)
  31. {
  32. // Just call the other one, to avoid having two copies (we don't use the HtmlHelper).
  33. return Markdown(text);
  34. }
  35. }
  36. }