//================================================================================================================================================ // Public Methods //================================================================================================================================================ #region OutputTag() public string OutputTag() { StringBuilder html = new StringBuilder(); if (TagName == "br") { return("<br />"); } if (TagName == "input") { html.Append(OpenTag.Replace(">", "/>")); return(html.ToString()); } else { html.Append(OpenTag); } if (Children != null) { foreach (var child in Children) { html.Append(child.GenerateTag()); } } html.Append(InnerHTML); html.Append(CloseTag).Append(Environment.NewLine); return(html.ToString()); }
/// <summary> /// Validates that there are an equal number of opening and closing tags. /// If not, more detail is logged to the class log. /// </summary> /// <param name="text"></param> /// <returns></returns> public bool ValidateBalancedTags(string text) { int openTagNum = CountOccurrence(text, OpenTag.ToString()); int closeTagNum = CountOccurrence(text, CloseTag.ToString()); if (openTagNum != closeTagNum) { Log = string.Format("Not all tags in the string are closed. \nOpen: {0} Closed: {1} \n{2}", openTagNum, closeTagNum, text); return(false); } else { return(true); } }
public void InterpretHREF(HTMLchunk chunk) { if (chunk.bEndClosure) { // solo anchor elements are meaningless. } if (!chunk.bClosure) { // hyperlink with attributes Style.HREF = new HREFAttributes(); OpenTag tag = new OpenTag(chunk); ParseTag(tag); } else { // closing a hyperlink. NOTE: Recalculating the styles will NOT restore the previous link. Is this worth fixing? RecalculateStyle(); } }
private void ParseTag(OpenTag tag) { switch (tag.sTag) { case "b": Style.IsBold = true; break; case "i": Style.IsItalic = true; break; case "u": Style.IsUnderlined = true; break; case "outline": Style.IsOutlined = true; break; case "big": Style.Font = m_Provider.GetUnicodeFont((int)Fonts.UnicodeBig); break; case "basefont": case "medium": Style.Font = m_Provider.GetUnicodeFont((int)Fonts.UnicodeMedium); break; case "small": Style.Font = m_Provider.GetUnicodeFont((int)Fonts.UnicodeSmall); break; case "left": Style.Alignment = Alignments.Left; break; case "center": Style.Alignment = Alignments.Center; break; case "right": Style.Alignment = Alignments.Right; break; } foreach (DictionaryEntry param in tag.oParams) { // get key and value for this tag param string key = param.Key.ToString(); string value = param.Value.ToString(); // trim trailing forward slash. if (value.EndsWith("/")) value = value.Substring(0, value.Length - 1); switch (key) { case "href": // href paramater can only be used on 'anchor' tags. if (tag.sTag == "a") { Style.HREF.HREF = value; } break; case "color": case "hovercolor": case "activecolor": // get the color! string color = value; Color? c = null; if (color[0] == '#') { color = color.Substring(1); if (color.Length == 3 || color.Length == 6) { c = Utility.ColorFromHexString(color); } } else { //try to parse color by name c = Utility.ColorFromString(color); } if (c.HasValue) { if (key == "color") Style.Color = c.Value; if (tag.sTag == "a") { switch (key) { case "color": Style.HREF.UpHue = m_Provider.GetWebSafeHue(c.Value); break; case "hovercolor": Style.HREF.OverHue = m_Provider.GetWebSafeHue(c.Value); break; case "activecolor": Style.HREF.DownHue = m_Provider.GetWebSafeHue(c.Value); break; } } } else Tracer.Warn("Improperly formatted color:" + color); break; case "src": case "hoversrc": case "activesrc": switch (tag.sTag) { case "gumpimg": if (key == "src") Style.GumpImgSrc = int.Parse(value); else if (key == "hoversrc") Style.GumpImgSrcOver = int.Parse(value); else if (key == "activesrc") Style.GumpImgSrcDown = int.Parse(value); break; default: Tracer.Warn("src param encountered within " + tag.sTag + " which does not use this param."); break; } break; case "width": switch (tag.sTag) { case "gumpimg": case "span": Style.ElementWidth = int.Parse(value); break; default: Tracer.Warn("width param encountered within " + tag.sTag + " which does not use this param."); break; } break; case "height": switch (tag.sTag) { case "gumpimg": case "span": Style.ElementHeight = int.Parse(value); break; default: Tracer.Warn("height param encountered within " + tag.sTag + " which does not use this param."); break; } break; case "style": ParseStyle(value); break; default: Tracer.Warn(string.Format("Unknown parameter:{0}", key)); break; } } }
public void OpenTag(HTMLchunk chunk) { OpenTag tag = new OpenTag(chunk); if (!chunk.bClosure || chunk.bEndClosure) { m_OpenTags.Add(tag); ParseTag(tag); } else { CloseOneTag(chunk); } }