Skip to content

Instantly share code, notes, and snippets.

@leekelleher
Last active February 5, 2020 06:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leekelleher/be0b93c069c1c40633a826e63aaaf7b1 to your computer and use it in GitHub Desktop.
Save leekelleher/be0b93c069c1c40633a826e63aaaf7b1 to your computer and use it in GitHub Desktop.
Umbraco - Converts a property's description using markdown
using Umbraco.Core;
using Umbraco.Web.Editors;
namespace Our.Umbraco
{
public class MyBootstrapper : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
EditorModelEventManager.SendingContentModel += (sender, e) =>
{
var markdown = new MarkdownSharp.Markdown()
{
DisableHeaders = true,
DisableImages = true
};
foreach (var property in e.Model.Properties)
{
if (string.IsNullOrWhiteSpace(property.Description) == false)
{
property.Description = markdown
.Transform(property.Description)
.Replace("<a href=", "<a target=\"_blank\" href=")
.Replace("</p>\n\n<p>", "</p><p>");
}
}
};
}
}
}
@leekelleher
Copy link
Author

Thanks to Ian on the forum who let me know about the EditorModelEventManager events.

@Shazwazza
Copy link

@leekelleher feel free to update the official docs about it :)

@Shazwazza
Copy link

Btw, this idea started way back: http://issues.umbraco.org/issue/U4-2670, there's also this: http://issues.umbraco.org/issue/U4-8530

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment