mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-31 21:15:28 +08:00
#20000: Moving the logic of replacing newlines to a filter.
Work Item: 20000
This commit is contained in:
parent
92111e203f
commit
1086aaf0b7
20
src/Orchard.Web/Core/Common/Services/TextFieldFilter.cs
Normal file
20
src/Orchard.Web/Core/Common/Services/TextFieldFilter.cs
Normal 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 />");
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
||||
}
|
@ -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" />
|
||||
|
Loading…
Reference in New Issue
Block a user