public IHtmlSanitizer CreateHtmlSanitizer()
        {
            if (!_textSettings.UseHtmlWhiteList)
            {
                return(null);
            }

            HtmlWhiteListSettings whiteListSettings = _htmlWhiteListProvider.Deserialize();

            string[] allowedTags       = whiteListSettings.AllowedElements.ToArray();
            string[] allowedAttributes = whiteListSettings.AllowedAttributes.ToArray();

            if (allowedTags.Length == 0)
            {
                allowedTags = null;
            }

            if (allowedAttributes.Length == 0)
            {
                allowedAttributes = null;
            }

            var htmlSanitizer = new HtmlSanitizer(allowedTags, null, allowedAttributes);

            htmlSanitizer.AllowDataAttributes = false;
            htmlSanitizer.AllowedAttributes.Add("class");
            htmlSanitizer.AllowedAttributes.Add("id");
            htmlSanitizer.AllowedSchemes.Add("mailto");
            htmlSanitizer.RemovingAttribute += (sender, e) =>
            {
                // Don't clean /wiki/Special:Tag urls in href="" attributes
                if (e.Attribute.Name.ToUpperInvariant() == "HREF" && e.Attribute.Value.Contains("Special:"))
                {
                    e.Cancel = true;
                }
            };

            return(htmlSanitizer);
        }
        private HtmlSanitizerFactory CreateFactory(TextSettings textSettings = null, IHtmlWhiteListProvider whiteListProviderMock = null)
        {
            if (textSettings == null)
            {
                textSettings = new TextSettings()
                {
                    UseHtmlWhiteList = true
                };
            }

            if (whiteListProviderMock == null)
            {
                whiteListProviderMock = Substitute.For <IHtmlWhiteListProvider>();
                whiteListProviderMock
                .Deserialize()
                .Returns(new HtmlWhiteListSettings()
                {
                    AllowedElements   = new List <string>(),
                    AllowedAttributes = new List <string>()
                });
            }

            return(new HtmlSanitizerFactory(textSettings, whiteListProviderMock));
        }