diff --git a/EditorExtensions/Validation/HTML/BootstrapClassValidator.cs b/EditorExtensions/Validation/HTML/BootstrapClassValidator.cs
index 3385cc82d..bf836f0fc 100644
--- a/EditorExtensions/Validation/HTML/BootstrapClassValidator.cs
+++ b/EditorExtensions/Validation/HTML/BootstrapClassValidator.cs
@@ -5,8 +5,9 @@
using Microsoft.Web.Editor;
using System.Collections.Generic;
using System.ComponentModel.Composition;
+using System.Linq;
-namespace MadsKristensen.EditorExtensions.Validation.HTML
+namespace MadsKristensen.EditorExtensions
{
[Export(typeof(IHtmlElementValidatorProvider))]
[ContentType(HtmlContentTypeDefinition.HtmlContentType)]
@@ -16,6 +17,7 @@ public class BootstrapClassValidatorProvider : BaseHtmlElementValidatorProvider<
public class BootstrapClassValidator : BaseValidator
{
private static string[] _tokens = new[] { "btn", "glyphicon", "alert", "label", "fa" }; // fa is for FontAwesome
+ private static string _error = "When using \"{0}\", you must also specify the class \"{1}\".";
public override IList ValidateElement(ElementNode element)
{
@@ -30,14 +32,17 @@ public override IList ValidateElement(ElementNode element)
if (!IsCorrect(classNames.Value, token))
{
int index = element.Attributes.IndexOf(classNames);
- results.AddAttributeError(element, "You must also specify the class \"" + token + "\"", HtmlValidationErrorLocation.AttributeValue, index);
+ string offender = GetOffendingClassName(classNames.Value, token);
+ string error = string.Format(_error, offender, token);
+
+ results.AddAttributeError(element, error, HtmlValidationErrorLocation.AttributeValue, index);
}
}
return results;
}
- private bool IsCorrect(string input, string token)
+ private static bool IsCorrect(string input, string token)
{
if (input.Contains(token + "-") &&
!(input.Contains(token + " ") || input.EndsWith(token)))
@@ -45,5 +50,11 @@ private bool IsCorrect(string input, string token)
return true;
}
+
+ private static string GetOffendingClassName(string input, string token)
+ {
+ string[] classes = input.Split(' ');
+ return classes.FirstOrDefault(c => c.StartsWith(token + "-"));
+ }
}
}