/// <inheritdoc /> public override IHtmlContent Button(IHtmlContent content, string type, string id, string value, HtmlAttributes htmlAttributes) { htmlAttributes = htmlAttributes ?? new HtmlAttributes(); htmlAttributes.AddClass("btn"); if (!StyledButtonClasses.Any(c => htmlAttributes.Attributes["class"].Contains(c))) { htmlAttributes.AddClass("btn-default"); } if (htmlAttributes.Attributes.ContainsKey(IconAttrKey)) { var icon = htmlAttributes.Attributes[IconAttrKey]; var iconHtml = string.Format("<span class=\"glyphicon glyphicon-{0}\"></span> ", icon); if (content == null) { content = new HtmlString(iconHtml + value.ToHtml()); } else { var bld = new HtmlContentBuilder(); bld.AppendHtml(iconHtml) .AppendHtml(content); content = bld; } htmlAttributes.Attributes.Remove(IconAttrKey); } return(base.Button(content, type, id, value, htmlAttributes)); }
/// <inheritdoc /> public IHtmlContent GetLabelHtml(IReadonlyFieldConfiguration fieldConfiguration) { fieldConfiguration = fieldConfiguration ?? new FieldConfiguration(); string @for; if (fieldConfiguration.HtmlAttributes.ContainsKey("id")) { @for = fieldConfiguration.HtmlAttributes["id"].ToString(); } else { @for = HtmlHelper.GetFullHtmlFieldName(FieldProperty); } var labelText = fieldConfiguration.LabelText ?? GetFieldDisplayName().ToHtml(); if (!fieldConfiguration.HasLabelElement) { return(labelText); } var labelAttrs = new HtmlAttributes(); if (!string.IsNullOrEmpty(fieldConfiguration.LabelClasses)) { labelAttrs.AddClass(fieldConfiguration.LabelClasses); } return(HtmlCreator.BuildLabel(@for, labelText, labelAttrs)); }
protected override void Write(HtmlRenderer renderer, CodeBlock node) { var fencedCodeBlock = node as FencedCodeBlock; var parser = node.Parser as FencedCodeBlockParser; if (fencedCodeBlock == null || parser == null) { codeBlockRenderer.Write(renderer, node); return; } var languageCode = fencedCodeBlock.Info.Replace(parser.InfoPrefix, string.Empty); if (string.IsNullOrWhiteSpace(languageCode) || !PrismSupportedLanguages.IsSupportedLanguage(languageCode)) { codeBlockRenderer.Write(renderer, node); return; } var attributes = new HtmlAttributes(); attributes.AddClass($"language-{languageCode}"); var code = ExtractSourceCode(node); renderer .Write("<pre>") .Write("<code") .WriteAttributes(attributes) .Write(">") .Write(code) .Write("</code>") .Write("</pre>"); }
protected override void Write(HtmlRenderer renderer, CodeBlock node) { FencedCodeBlock? fencedCodeBlock = node as FencedCodeBlock; FencedCodeBlockParser?parser = node.Parser as FencedCodeBlockParser; if (fencedCodeBlock == null || parser == null) { codeBlockRenderer.Write(renderer, node); return; } string language = fencedCodeBlock.Info !.Replace(parser.InfoPrefix ?? string.Empty, string.Empty); if (string.IsNullOrWhiteSpace(language) || !PrismSupportedLanguages.IsSupportedLanguage(language)) { codeBlockRenderer.Write(renderer, node); return; } var htmlAttributes = new HtmlAttributes(); htmlAttributes.AddClass("language-" + language); string sourceCode = ExtractSourceCode((LeafBlock)node); renderer .Write("<pre>") .Write("<code") .WriteAttributes(htmlAttributes) .Write(">") .Write(sourceCode) .Write("</code>") .Write("</pre>"); }
protected override void Write(HtmlRenderer renderer, GreenTextParsedModel obj) { var attr = new HtmlAttributes(); attr.AddClass("green-text"); renderer.Write("<span").WriteAttributes(attr).Write($">>{obj.Text}</span>"); }
public void Add_css_classes() { var h = new HtmlAttributes(@class => "class1"); h.AddClass("class2 class3"); Assert.That(h.ToHtmlString(), Is.EqualTo(" class=\"class2 class3 class1\"")); }
protected override void Write(HtmlRenderer renderer, LinkToParsedModel obj) { RequestLifetimeService requestLifetimeService = null; if (_serviceProvider.GetRequiredService <IHttpContextAccessor>().HttpContext.Items .TryGetValue("RequestLifetime", out var lifetimeService)) { requestLifetimeService = (RequestLifetimeService)lifetimeService; } if (requestLifetimeService == null) { throw ExceptionFactory.SoftException(ExceptionEnum.SomethingWentWrong, $"If you see this message pls contact admin, {obj.Id}"); } var publicContext = (PublicContext)_serviceProvider.GetService(typeof(PublicContext)); var isPostOrComment = publicContext.IsPostOrComment(obj.Id); var attr = new HtmlAttributes(); attr.AddClass("link-to"); attr.AddProperty("target", "_blank"); attr.AddProperty("rel", "noopener noreferrer"); attr.AddProperty("href", $"/{requestLifetimeService.Board.Name}/{requestLifetimeService.Post.Id}#{obj.Id}"); attr.AddProperty("data-thread", requestLifetimeService.Post.Id.ToString()); var innerText = ">>" + obj.Id; var mention = new Mention { MentionId = obj.Id, MentionerId = requestLifetimeService.MyId, IsComment = requestLifetimeService.IsComment, }; requestLifetimeService.AddMention(mention); if (isPostOrComment == 0) { attr.AddProperty("data-post", obj.Id.ToString()); innerText += " (OP)"; } else if (isPostOrComment == 1) { attr.AddProperty("data-comment", obj.Id.ToString()); } else { attr.AddProperty("data-post", obj.Id.ToString()); attr.AddProperty("data-comment", obj.Id.ToString()); } renderer.Write("<a").WriteAttributes(attr).Write($">{innerText}</a>"); }
public bool TryProcessAttributes(IDictionary <string, string> attributes, out HtmlAttributes htmlAttributes, out IDictionary <string, string> renderProperties, Action <string> logError, Action <string> logWarning, MarkdownObject markdownObject) { htmlAttributes = null; renderProperties = new Dictionary <string, string>(); var model = string.Empty; var action = string.Empty; var submitText = string.Empty; foreach (var attribute in attributes) { var name = attribute.Key; var value = attribute.Value; switch (name) { case "model": model = value; break; case "action": action = value; break; case "submittext": submitText = WebUtility.HtmlEncode(value); break; default: logError($"Unexpected attribute \"{name}\"."); return(false); } } if (action == string.Empty) { logError("Form action must be specified."); return(false); } if (submitText == string.Empty) { logError("Submit text must be specified."); return(false); } htmlAttributes = new HtmlAttributes(); if (model != string.Empty) { htmlAttributes.AddProperty("data-model", model); } htmlAttributes.AddProperty("data-action", action); htmlAttributes.AddClass("chromeless-form"); renderProperties.Add(new KeyValuePair <string, string>("submitText", submitText)); return(true); }
public void TestAddClass() { var attributes = new HtmlAttributes(); attributes.AddClass("test"); Assert.NotNull(attributes.Classes); Assert.AreEqual(new List <string>() { "test" }, attributes.Classes); attributes.AddClass("test"); Assert.AreEqual(1, attributes.Classes.Count); attributes.AddClass("test1"); Assert.AreEqual(new List <string>() { "test", "test1" }, attributes.Classes); }
private void UpdateFencedCodeLanguage(HtmlAttributes attributes, string originalLanguage, string updatedLanguage) { originalLanguage = Constants.FencedCodePrefix + originalLanguage; updatedLanguage = Constants.FencedCodePrefix + updatedLanguage; var index = attributes.Classes?.IndexOf(originalLanguage); if (index.HasValue && index.Value != -1) { attributes.Classes[index.Value] = WebUtility.HtmlEncode(updatedLanguage); } else { attributes.AddClass(WebUtility.HtmlEncode(updatedLanguage)); } }
public static System.Web.WebPages.HelperResult BeginNestedSection(IHtmlString heading, IHtmlString leadingHtml, HtmlAttributes htmlAttributes) { return(new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 29 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" htmlAttributes.AddClass("panel panel-default"); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <div"); #line 31 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, htmlAttributes); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, ">\r\n"); #line 32 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" if (heading != null && !string.IsNullOrWhiteSpace(heading.ToString())) { #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <div class=\"panel-heading\">"); #line 34 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, heading); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</div>\r\n"); #line 35 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" } #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <div class=\"panel-body\">\r\n"); #line 38 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" if (leadingHtml != null && !string.IsNullOrWhiteSpace(leadingHtml.ToString())) { #line default #line hidden #line 40 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, leadingHtml); #line default #line hidden #line 40 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" } #line default #line hidden })); }
/// <inheritdoc /> public IFieldConfiguration AddClass(string @class) { Attributes.AddClass(@class); return(this); }
public bool TryProcessAttributes(IDictionary <string, string> attributes, out HtmlAttributes htmlAttributes, out IDictionary <string, string> renderProperties, Action <string> logError, Action <string> logWarning, MarkdownObject markdownObject) { htmlAttributes = null; renderProperties = null; var target = string.Empty; var pivot = string.Empty; foreach (var attribute in attributes) { var name = attribute.Key; var value = attribute.Value; switch (name) { case "target": if (value != "docs" && value != "chromeless" && value != "pdf") { logError($"Unexpected target \"{value}\". Permitted targets are \"docs\", \"chromeless\" or \"pdf\"."); return(false); } target = value; break; case "pivot": if (!pivotRegex.IsMatch(value)) { logError($"Invalid pivot \"{value}\". Pivot must be a comma-delimited list of pivot names. Pivot names must be lower-case and contain only letters, numbers or dashes."); return(false); } pivot = value; break; default: logError($"Unexpected attribute \"{name}\"."); return(false); } } if (target == string.Empty && pivot == string.Empty) { logError("Either target or privot must be specified."); return(false); } if (target == "pdf" && pivot != string.Empty) { logError("Pivot not permitted on pdf target."); return(false); } htmlAttributes = new HtmlAttributes(); htmlAttributes.AddClass("zone"); if (target != string.Empty) { htmlAttributes.AddClass("has-target"); htmlAttributes.AddProperty("data-target", target); } if (pivot != string.Empty) { htmlAttributes.AddClass("has-pivot"); htmlAttributes.AddProperty("data-pivot", pivot.Trim().ReplaceRegex(pivotReplaceCommasRegex, " ")); } return(true); }
public static System.Web.WebPages.HelperResult BeginNestedSection(IHtmlString heading, IHtmlString leadingHtml, HtmlAttributes htmlAttributes) { return new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 29 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" htmlAttributes.AddClass("panel panel-default"); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <div"); #line 31 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, htmlAttributes); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, ">\r\n"); #line 32 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" if (heading != null && !string.IsNullOrWhiteSpace(heading.ToString())) { #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <div class=\"panel-heading\">"); #line 34 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, heading); #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</div>\r\n"); #line 35 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" } #line default #line hidden WebViewPage.WriteLiteralTo(@__razor_helper_writer, " <div class=\"panel-body\">\r\n"); #line 38 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" if (leadingHtml != null && !string.IsNullOrWhiteSpace(leadingHtml.ToString())) { #line default #line hidden #line 40 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" WebViewPage.WriteTo(@__razor_helper_writer, leadingHtml); #line default #line hidden #line 40 "..\..\Templates\TwitterBootstrap3\TwitterBootstrapHtmlHelpers.cshtml" } #line default #line hidden }); }
public bool TryProcessAttributes(IDictionary <string, string> attributes, out HtmlAttributes htmlAttributes, out IDictionary <string, string> renderProperties, Action <string> logError, BlockProcessor processor) { htmlAttributes = null; renderProperties = new Dictionary <string, string>(); var model = string.Empty; var action = string.Empty; var submitText = string.Empty; foreach (var attribute in attributes) { var name = attribute.Key; var value = attribute.Value; switch (name) { case "model": model = value; break; case "action": action = value; break; case "submittext": submitText = WebUtility.HtmlEncode(value); break; default: logError($"Unexpected attribute \"{name}\"."); return(false); } } if (action == string.Empty) { logError("Form action must be specified."); return(false); } if (submitText == string.Empty) { logError("Submit text must be specified."); return(false); } htmlAttributes = new HtmlAttributes(); if (model != string.Empty) { htmlAttributes.AddProperty("data-model", model); } htmlAttributes.AddProperty("data-action", action); htmlAttributes.AddClass("chromeless-form"); renderProperties.Add(new KeyValuePair <string, string>("submitText", submitText)); RenderDelegate = (renderer, obj) => { var buttonText = "Submit"; obj.RenderProperties.TryGetValue("submitText", out buttonText); renderer.Write("<form").WriteAttributes(obj).WriteLine(">"); renderer.WriteLine("<div></div>"); renderer.WriteLine($"<button class=\"button is-primary\" disabled=\"disabled\" type=\"submit\">{buttonText}</button>"); renderer.WriteLine("</form>"); return(true); }; return(true); }
public void TestCopyTo() { var from = new HtmlAttributes(); from.AddClass("test"); from.AddProperty("key1", "1"); var to = new HtmlAttributes(); from.CopyTo(to); Assert.True(ReferenceEquals(from.Classes, to.Classes)); Assert.True(ReferenceEquals(from.Properties, to.Properties)); // From: Classes From: Properties To: Classes To: Properties // test1: null null null null from = new HtmlAttributes(); to = new HtmlAttributes(); from.CopyTo(to, false, false); Assert.Null(to.Classes); Assert.Null(to.Properties); // test2: ["test"] ["key1", "1"] null null from = new HtmlAttributes(); to = new HtmlAttributes(); from.AddClass("test"); from.AddProperty("key1", "1"); from.CopyTo(to, false, false); Assert.AreEqual(new List <string>() { "test" }, to.Classes); Assert.AreEqual(new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("key1", "1") }, to.Properties); // test3: null null ["test"] ["key1", "1"] from = new HtmlAttributes(); to = new HtmlAttributes(); to.AddClass("test"); to.AddProperty("key1", "1"); from.CopyTo(to, false, false); Assert.AreEqual(new List <string>() { "test" }, to.Classes); Assert.AreEqual(new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("key1", "1") }, to.Properties); // test4: ["test1"] ["key2", "2"] ["test"] ["key1", "1"] from = new HtmlAttributes(); to = new HtmlAttributes(); from.AddClass("test1"); from.AddProperty("key2", "2"); to.AddClass("test"); to.AddProperty("key1", "1"); from.CopyTo(to, false, false); Assert.AreEqual(new List <string>() { "test", "test1" }, to.Classes); Assert.AreEqual(new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("key1", "1"), new KeyValuePair <string, string>("key2", "2") }, to.Properties); }