#20000: Moving the logic of replacing newlines to a filter.

Work Item: 20000
This commit is contained in:
Walance 2013-08-29 10:53:47 +02:00 committed by Sebastien Ros
parent 92111e203f
commit 1086aaf0b7
3 changed files with 23 additions and 3 deletions

View File

@ -0,0 +1,20 @@
using System;
using System.Web;
using Orchard.Services;
using Orchard.Utility.Extensions;
namespace Orchard.Core.Common.Services {
public class TextFieldFilter : IHtmlFilter {
public string ProcessContent(string text, string flavor) {
// Flavor is null for a normal input/text field
return flavor == null || string.Equals(flavor, "textarea", StringComparison.OrdinalIgnoreCase) ? ReplaceNewLines(text) : text;
}
private static string ReplaceNewLines(string text) {
if (string.IsNullOrEmpty(text))
return string.Empty;
return HttpUtility.HtmlEncode(text).ReplaceNewLinesWith("<br />");
}
}
}

View File

@ -1,8 +1,7 @@
@using Orchard.Utility.Extensions;
@{
@{
string name = Model.ContentField.DisplayName;
}
@if (HasText(name) && HasText(Model.Value)) {
<p class="text-field"><span class="name">@name:</span> <span class="value">@(new MvcHtmlString(Html.Encode((HtmlString) Model.Value).ReplaceNewLinesWith("<br />")))</span></p>
<p class="text-field"><span class="name">@name:</span> <span class="value">@Model.Value</span></p>
}

View File

@ -80,6 +80,7 @@
<Compile Include="Common\ResourceManifest.cs" />
<Compile Include="Common\Routes.cs" />
<Compile Include="Common\Services\IdentifierResolverSelector.cs" />
<Compile Include="Common\Services\TextFieldFilter.cs" />
<Compile Include="Common\Services\XmlRpcHandler.cs" />
<Compile Include="Common\DateEditor\DateEditorViewModel.cs" />
<Compile Include="Common\Settings\TextFieldSettingsEvents.cs" />