Optionally decoding Html in RemoveTags

This commit is contained in:
Codinlab
2014-03-04 17:25:25 -08:00
committed by Sebastien Ros
parent d0c89f3ee8
commit 1c7796b125
2 changed files with 10 additions and 3 deletions

View File

@@ -100,7 +100,7 @@ namespace Lucene.Models {
switch(_typeCode) {
case TypeCode.String:
if(_removeTags) {
_stringValue = _stringValue.RemoveTags();
_stringValue = _stringValue.RemoveTags(true);
}
Fields.Add(new Field(_name, _stringValue ?? String.Empty,
_store ? Field.Store.YES : Field.Store.NO,

View File

@@ -4,6 +4,7 @@ using System.Globalization;
using System.Linq;
using System.Text;
using Orchard.Localization;
using System.Web;
namespace Orchard.Utility.Extensions {
public static class StringExtensions {
@@ -88,7 +89,7 @@ namespace Orchard.Utility.Extensions {
: new LocalizedString(text);
}
public static string RemoveTags(this string html) {
public static string RemoveTags(this string html, bool htmlDecode = false) {
if (String.IsNullOrEmpty(html)) {
return String.Empty;
}
@@ -114,7 +115,13 @@ namespace Orchard.Utility.Extensions {
}
}
return new string(result, 0, cursor);
var stringResult = new string(result, 0, cursor);
if (htmlDecode) {
stringResult = HttpUtility.HtmlDecode(stringResult);
}
return stringResult;
}
// not accounting for only \r (e.g. Apple OS 9 carriage return only new lines)