Last active
February 5, 2020 06:52
-
-
Save leekelleher/be0b93c069c1c40633a826e63aaaf7b1 to your computer and use it in GitHub Desktop.
Umbraco - Converts a property's description using markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 feel free to update the official docs about it :)
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
Thanks to Ian on the forum who let me know about the
EditorModelEventManager
events.