/// <summary> /// Ctor. /// </summary> /// <param name="name"></param> public HtmlTag(string name, IHtmlFilter filter) { this.filter = filter; if (name == null) { name = String.Empty; } this.rawName = name.Trim(); if (this.rawName.StartsWith("!") || this.rawName.StartsWith("?") || this.rawName.StartsWith("%")) { this.tagType = HtmlTagType.Unparsed; } else if (this.rawName.StartsWith("/")) { this.tagType = HtmlTagType.EndTag; this.rawName = this.rawName.Substring(1); } else if (HtmlTag.FullTagRequired(this.TagName)) // this.TagName is lowercase { this.tagType = HtmlTagType.FullTag; } else { this.tagType = HtmlTagType.BeginTag; } }
/// <summary> /// Initializes a new instance of the <see cref="HtmlElement"/> class. /// </summary> /// <param name="tag">The tag.</param> /// <param name="content">The content.</param> /// <param name="attributes">The attributes.</param> public HtmlElement(HtmlTag tag, string content, params KeyValuePair <string, string>[] attributes) { _element = new StringBuilder(); _tag = tag; _content = content; _attributes = attributes?.ToList() ?? new List <KeyValuePair <string, string> >(); ElementType = _tag.TagType; }
/// <summary> /// Changes a BeginTag to a FullTag /// </summary> internal void SetFullTag() { if (this.TagType != HtmlTagType.BeginTag) { return; } this.tagType = HtmlTagType.FullTag; }
HtmlTagType GetTagType(string tag) { for (HtmlTagType t = HtmlTagType.A; t < HtmlTagType.max; ++t) { if (t.ToString() == tag) { return(t); } } return(HtmlTagType.max); }
public HtmlDTDType DTDType; // Document Type Definition //public bool Head; //public HtmlTag(string TagName, HtmlTagType TagType, HtmlBoundType StartTagType, HtmlBoundType EndTagType, bool Empty, bool Deprecated, HtmlDTDType DTDType) //{ // this.TagName = TagName; // this.TagType = TagType; // this.StartBoundType = StartTagType; // this.EndBoundType = EndTagType; // this.Empty = Empty; // this.Deprecated = Deprecated; // this.DTDType = DTDType; // this.TagCategory = HtmlTagCategory.NoCategory; //} public HtmlTag(string TagName, HtmlTagType TagType, HtmlBoundType StartTagType, HtmlBoundType EndTagType, bool Empty, bool Deprecated, HtmlDTDType DTDType, HtmlTagCategory TagCategory = HtmlTagCategory.NoCategory) { this.TagName = TagName; this.TagType = TagType; this.StartBoundType = StartTagType; this.EndBoundType = EndTagType; this.Empty = Empty; this.Deprecated = Deprecated; this.DTDType = DTDType; this.TagCategory = TagCategory; }
public static HtmlTag GetHtmlTag(HtmlTagType tagType) { //int i = __tags.IndexOfKey(TagType); //if (i != -1) return __tags.Values[i]; if (__tags.ContainsKey(tagType)) { return(__tags[tagType]); } else { return(null); } }
public HtmlChunk(string tagName, HtmlTagType tagType, Dictionary <string, string> parameters = null) : this() { this.Type = HtmlChunkType.Tag; this.TagName = tagName; this.TagType = tagType; this.parameters = parameters; this.Html = '<' + (tagType == HtmlTagType.Close ? "/" : "") + tagName + (parameters.IsNull() ? "" : ' ' + parameters.Aggregate(kvp => "{0}=\"{1}\"".FormatWith(kvp.Key, kvp.Value), " ")) + (tagType == HtmlTagType.SelfClose ? "/" : "") + '>'; }
/// <summary> /// Creates new HtmlChunk wrapper. For internal use. /// </summary> internal HtmlChunk(HtmlParserMajestic.HtmlChunk chunk) : this() { Html = chunk.GenerateHtml(); switch (chunk.oType) { case HtmlParserMajestic.HtmlChunkType.Text: Type = HtmlChunkType.Text; Text = chunk.oHTML ?? string.Empty; Html = WebUtility.HtmlEncode(Text); break; case HtmlParserMajestic.HtmlChunkType.OpenTag: Type = HtmlChunkType.Tag; TagName = chunk.sTag; TagType = HtmlTagType.Open; parameters = new Dictionary <string, string>(chunk.oParams); break; case HtmlParserMajestic.HtmlChunkType.CloseTag: Type = HtmlChunkType.Tag; TagName = chunk.sTag; TagType = chunk.bEndClosure ? HtmlTagType.SelfClose : HtmlTagType.Close; parameters = new Dictionary <string, string>(chunk.oParams); break; case HtmlParserMajestic.HtmlChunkType.Comment: Type = HtmlChunkType.Comment; break; case HtmlParserMajestic.HtmlChunkType.Script: Type = HtmlChunkType.Script; break; default: throw new ArgumentOutOfRangeException(); } }
public static HtmlTag GetHtmlTag(HtmlTagType tagType) { //int i = __tags.IndexOfKey(TagType); //if (i != -1) return __tags.Values[i]; if (__tags.ContainsKey(tagType)) return __tags[tagType]; else return null; }
HtmlTagType[] GetFullTagInfo(ITag tag, out string[] value) { value = null; List <HtmlTagType> ret = new List <HtmlTagType>(); HtmlTagType tagType = GetTagType(tag.TagName); switch (tagType) { case HtmlTagType.FONT: { if (tag.IsEndTag()) { if (mFontSizeStack.Count > 0) { if (null != mFontSizeStack.Peek()) { ret.Add(HtmlTagType.FONT_SIZE); } mFontSizeStack.Pop(); } if (mFontColorStack.Count > 0) { if (null != mFontColorStack.Peek()) { ret.Add(HtmlTagType.FONT_COLOR); } mFontColorStack.Pop(); } if (mFontEffectStack.Count > 0) { if (null != mFontEffectStack.Peek()) { ret.Add(HtmlTagType.FONT_EFFECT); } mFontEffectStack.Pop(); } } else { object size = tag.Attributes[HtmlTagAttrType.SIZE.ToString()]; object color = tag.Attributes[HtmlTagAttrType.COLOR.ToString()]; object effect = tag.Attributes[HtmlTagAttrType.EFFECT.ToString()]; mFontSizeStack.Push(size); mFontColorStack.Push(color); mFontEffectStack.Push(effect); if (null != size) { ret.Add(HtmlTagType.FONT_SIZE); } if (null != color) { ret.Add(HtmlTagType.FONT_COLOR); } if (null != effect) { ret.Add(HtmlTagType.FONT_EFFECT); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != tag.Attributes && tag.Attributes.Count > 0) { if (null != size) { string attrStr = size.ToString(); string newStr = attrStr.Replace("px", ""); if (newStr == attrStr) { newStr = attrStr; } value[index++] = newStr; } if (null != color) { string attrStr = color.ToString(); if (attrStr.Length < 8) { for (int i = 0; i < 8 - attrStr.Length + 1; ++i) { attrStr = "f" + attrStr; } } //if ('#' != attrStr[0]) // attrStr = "#" + attrStr; value[index++] = attrStr; } if (null != effect) { string attrStr = effect.ToString(); value[index++] = attrStr; } } } } } break; case HtmlTagType.AEND: { if (tag.IsEndTag()) { if (mHrefbStack.Count > 0) { if (null != mHrefbStack.Peek()) { ret.Add(HtmlTagType.A_HREF); } mHrefbStack.Pop(); } if (mHrefbColorStack.Count > 0) { if (null != mHrefbColorStack.Peek()) { ret.Add(HtmlTagType.A_COLOR); } mHrefbColorStack.Pop(); } if (mEnableStack.Count > 0) { if (null != mEnableStack.Peek()) { ret.Add(HtmlTagType.A_ENABLE); } mEnableStack.Pop(); } } } break; case HtmlTagType.A: { /* * ATag httpTag = tag as ATag; * httpTag.IsEndTag(); */ if (tag.IsEndTag()) { if (mHrefbStack.Count > 0) { if (null != mHrefbStack.Peek()) { ret.Add(HtmlTagType.A_HREF); } mHrefbStack.Pop(); } if (mHrefbColorStack.Count > 0) { if (null != mHrefbColorStack.Peek()) { ret.Add(HtmlTagType.A_COLOR); } mHrefbColorStack.Pop(); } if (mEnableStack.Count > 0) { if (null != mEnableStack.Peek()) { ret.Add(HtmlTagType.A_ENABLE); } mEnableStack.Pop(); } } else { object href = tag.Attributes[HtmlTagAttrType.HREF.ToString()]; object color = tag.Attributes[HtmlTagAttrType.COLOR.ToString()]; object enable = tag.Attributes[HtmlTagAttrType.ENABLE.ToString()]; mHrefbStack.Push(href); mHrefbColorStack.Push(color); mEnableStack.Push(enable); if (null != href) { ret.Add(HtmlTagType.A_HREF); } if (null != color) { ret.Add(HtmlTagType.A_COLOR); } if (null != enable) { ret.Add(HtmlTagType.A_ENABLE); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != tag.Attributes && tag.Attributes.Count > 0) { if (null != href) { value[index++] = href.ToString(); } if (null != color) { value[index++] = color.ToString(); } if (null != enable) { value[index++] = enable.ToString(); } } } } } break; case HtmlTagType.SPACE: { if (tag.IsEndTag()) { if (mSpaceHORStack.Count > 0) { if (null != mSpaceHORStack.Peek()) { ret.Add(HtmlTagType.SPACE_HOR); } } if (mSpaceVERStack.Count > 0) { if (null != mSpaceVERStack.Peek()) { ret.Add(HtmlTagType.SPACE_VER); } } if (mSpaceSegmentStack.Count > 0) { if (null != mSpaceSegmentStack.Peek()) { ret.Add(HtmlTagType.SPACE_SEGMENT); } } } else { object hor = tag.Attributes[HtmlTagAttrType.HOR.ToString()]; object ver = tag.Attributes[HtmlTagAttrType.VER.ToString()]; object segment = tag.Attributes[HtmlTagAttrType.SEGMENT.ToString()]; mSpaceHORStack.Push(hor); mSpaceVERStack.Push(ver); mSpaceSegmentStack.Push(segment); if (null != hor) { ret.Add(HtmlTagType.SPACE_HOR); } if (null != ver) { ret.Add(HtmlTagType.SPACE_VER); } if (null != segment) { ret.Add(HtmlTagType.SPACE_SEGMENT); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != hor) { value[index++] = hor.ToString(); } if (null != ver) { value[index++] = ver.ToString(); } if (null != segment) { value[index++] = segment.ToString(); } } } } break; case HtmlTagType.TRANS: { if (tag.IsEndTag()) { if (mTransSizeWStack.Count > 0) { if (null != mTransSizeWStack.Peek()) { ret.Add(HtmlTagType.TRANS_SIZE_W); } } if (mTransSizeHStack.Count > 0) { if (null != mTransSizeHStack.Peek()) { ret.Add(HtmlTagType.TRANS_SIZE_H); } } if (mTransPosXStack.Count > 0) { if (null != mTransPosXStack.Peek()) { ret.Add(HtmlTagType.TRANS_POS_X); } } if (mTransPosYStack.Count > 0) { if (null != mTransPosYStack.Peek()) { ret.Add(HtmlTagType.TRANS_POS_Y); } } } else { object size_w = tag.Attributes[HtmlTagAttrType.SIZE_W.ToString()]; object size_h = tag.Attributes[HtmlTagAttrType.SIZE_H.ToString()]; object pos_x = tag.Attributes[HtmlTagAttrType.POS_X.ToString()]; object pos_y = tag.Attributes[HtmlTagAttrType.POS_Y.ToString()]; mTransSizeWStack.Push(size_w); mTransSizeHStack.Push(size_h); mTransPosXStack.Push(pos_x); mTransPosYStack.Push(pos_y); if (null != size_w) { ret.Add(HtmlTagType.TRANS_SIZE_W); } if (null != size_h) { ret.Add(HtmlTagType.TRANS_SIZE_H); } if (null != pos_x) { ret.Add(HtmlTagType.TRANS_POS_X); } if (null != pos_y) { ret.Add(HtmlTagType.TRANS_POS_Y); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != size_w) { value[index++] = size_w.ToString(); } if (null != size_h) { value[index++] = size_h.ToString(); } if (null != pos_x) { value[index++] = pos_x.ToString(); } if (null != pos_y) { value[index++] = pos_y.ToString(); } } } } break; case HtmlTagType.ITEM: { object idVal = tag.Attributes[HtmlTagAttrType.INDEX.ToString()]; object e1Val = tag.Attributes[HtmlTagAttrType.EXCHANGE1.ToString()]; object e2Val = tag.Attributes[HtmlTagAttrType.EXCHANGE2.ToString()]; if (null != idVal) { ret.Add(HtmlTagType.ITEM_INDEX); } if (null != e1Val) { ret.Add(HtmlTagType.ITEM_EXCHANGE1); } if (null != e2Val) { ret.Add(HtmlTagType.ITEM_EXCHANGE2); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != idVal) { value[index++] = idVal.ToString(); } if (null != e1Val) { value[index++] = e1Val.ToString(); } if (null != e2Val) { value[index++] = e2Val.ToString(); } } } break; case HtmlTagType.IMAGE: { object idVal = tag.Attributes[HtmlTagAttrType.ID.ToString()]; if (null != idVal) { ret.Add(HtmlTagType.IMAGE_ID); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != idVal) { value[index++] = idVal.ToString(); } } } break; case HtmlTagType.IMGANIM: { object idVal = tag.Attributes[HtmlTagAttrType.ID.ToString()]; if (null != idVal) { ret.Add(HtmlTagType.IMGANIM_ID); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != idVal) { value[index++] = idVal.ToString(); } } } break; case HtmlTagType.NUMBER: { object idVal = tag.Attributes[HtmlTagAttrType.ID.ToString()]; if (null != idVal) { ret.Add(HtmlTagType.NUMBER_ID); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != idVal) { value[index++] = idVal.ToString(); } } } break; case HtmlTagType.PARAM: { object idVal = tag.Attributes[HtmlTagAttrType.ID.ToString()]; object pushVal = tag.Attributes[HtmlTagAttrType.PUSH.ToString()]; if (null != idVal) { ret.Add(HtmlTagType.PARAM_ID); } if (null != pushVal) { ret.Add(HtmlTagType.PARAM_PUSH); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != idVal) { value[index++] = idVal.ToString(); } if (null != pushVal) { value[index++] = pushVal.ToString(); } } } break; case HtmlTagType.SKILL_ATTR: { object skillAttrID = tag.Attributes[HtmlTagAttrType.ID.ToString()]; object skillLinkAttrID = tag.Attributes[HtmlTagAttrType.LINK.ToString()]; if (null != skillAttrID) { ret.Add(HtmlTagType.SKILL_ATTR_ID); } if (null != skillLinkAttrID) { ret.Add(HtmlTagType.SKILL_ATTR_LINK); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != skillAttrID) { value[index++] = skillAttrID.ToString(); } if (null != skillLinkAttrID) { value[index++] = skillLinkAttrID.ToString(); } } } break; case HtmlTagType.SKILL_HW: { object hwID = tag.Attributes[HtmlTagAttrType.ID.ToString()]; object hwPropID = tag.Attributes[HtmlTagAttrType.PROP.ToString()]; if (null != hwID) { ret.Add(HtmlTagType.SKILL_HW_ID); } if (null != hwPropID) { ret.Add(HtmlTagType.SKILL_HW_PROP); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != hwID) { value[index++] = hwID.ToString(); } if (null != hwPropID) { value[index++] = hwPropID.ToString(); } } } break; case HtmlTagType.SKILL_DMG: { object dmgID = tag.Attributes[HtmlTagAttrType.ID.ToString()]; object dmgPropID = tag.Attributes[HtmlTagAttrType.PROP.ToString()]; if (null != dmgID) { ret.Add(HtmlTagType.SKILL_DMG_ID); } if (null != dmgPropID) { ret.Add(HtmlTagType.SKILL_DMG_PROP); } if (ret.Count > 0) { value = new string[ret.Count]; int index = 0; if (null != dmgID) { value[index++] = dmgID.ToString(); } if (null != dmgPropID) { value[index++] = dmgPropID.ToString(); } } } break; default: { if (null != tag.Attributes && tag.Attributes.Count > 0) { List <string> keys = new List <string>(); List <string> vals = new List <string>(); IEnumerator ks = tag.Attributes.Keys.GetEnumerator(); while (ks.MoveNext()) { keys.Add(ks.Current.ToString()); vals.Add(tag.Attributes[ks.Current.ToString()].ToString()); } value = new string[vals.Count]; for (int i = 0; i < keys.Count; ++i) { ret.Add(tagType); value[i] = vals[i]; } } else { ret.Add(tagType); value = new string[] { "" }; } } break; } return(ret.ToArray()); }
private void TagBegin(string tagName, bool tagEnd) { _noTag = false; HtmlTagType tagType = HtmlTags.GetHtmlTagType(tagName); HtmlTag tag = HtmlTags.GetHtmlTag(tagType); if (_normalizeXml) { if (tagType == HtmlTagType.Html || tagType == HtmlTagType.Head) { _noTag = true; return; } if (tagType == HtmlTagType.Body) { _noTag = true; if (!_body) { _body = true; _currentNode = _currentTreeNode = _bodyNode; } return; } if (tagType == HtmlTagType.Title) { if (!_title) { if (!tagEnd) { _title = true; _currentNode = _titleNode; } } else { _noTag = true; } return; } // $$pb modif le 11/01/2015 //if (!_body && tag.TagCategory != HtmlTagCategory.Head) //{ // _body = true; // _currentNode = _currentTreeNode = _bodyNode; //} } _currentNode = CreateElement(tagName); if (_normalizeXml) { if (tagType == HtmlTagType.Table && !tagEnd) { if (_table != null) { _tableStack.Push(_table); } _table = new HtmlTable_v2(); _table.Table = _currentNode; AddElement(_currentTreeNode, _currentNode); _currentTreeNode = _currentNode; return; } if (TagBeginTableCategory(tag, tagEnd)) { return; } if (tagType == HtmlTagType.DL && !tagEnd) { if (_definitionList != null) { _definitionListStack.Push(_definitionList); } _definitionList = _currentNode; AddElement(_currentTreeNode, _currentNode); _currentTreeNode = _currentNode; return; } if (TagBeginDefinitionListCategory(tag, tagEnd)) { return; } // $$pb à revérifier // il faut au moins annuler gLastPNode quand un des parents de gLastPNode se ferme //if (tagType == HtmlTagTypeEnum.P) //{ // // pour gérer une balise <p> qui n'a pas de fin de balise </p> // if (gLastPNode != null) // { // gCurrentTreeNode = GetParentXXNode(gLastPNode); // gLastPNode = null; // } // if (!bTagEnd) gLastPNode = gCurrentNode; //} } AddElement(_currentTreeNode, _currentNode); //if (!tagEnd && tag.EndBoundType != HtmlBoundType.Forbidden) // _currentTreeNode = _currentNode; if (!tagEnd) { if (tag.EndBoundType != HtmlBoundType.Forbidden) { _currentTreeNode = _currentNode; } } else if (_correctionMarkBeginEnd) { _currentNode = _currentTreeNode; } }
private void TagEnd(string sTagName) { if (gbNormalizeXml) { HtmlTagType tagType = HtmlTags.GetHtmlTagType(sTagName); switch (tagType) { case HtmlTagType.Html: case HtmlTagType.Head: case HtmlTagType.Body: return; case HtmlTagType.Title: gCurrentNode = gCurrentTreeNode; return; case HtmlTagType.Table: if (gTable == null) { return; } //gCurrentNode = gCurrentTreeNode = gTable.Table.ParentNode; gCurrentNode = gCurrentTreeNode = GetParentXXNode(gTable.Table); gTable = null; if (gTableStack.Count != 0) { gTable = gTableStack.Pop(); } return; case HtmlTagType.DL: if (gDefinitionList == null) { return; } //gCurrentNode = gCurrentTreeNode = gDefinitionList.ParentNode; gCurrentNode = gCurrentTreeNode = GetParentXXNode(gDefinitionList); gDefinitionList = null; if (gDefinitionListStack.Count != 0) { gDefinitionList = gDefinitionListStack.Pop(); } return; } if (gTable != null) { switch (tagType) { case HtmlTagType.THead: case HtmlTagType.TBody: case HtmlTagType.TFoot: gCurrentNode = gCurrentTreeNode = gTable.Table; gTable.Body = null; return; case HtmlTagType.ColGroup: gCurrentNode = gCurrentTreeNode = gTable.Table; gTable.ColGroup = null; return; case HtmlTagType.Col: if (gTable.Col != null) { //gCurrentNode = gCurrentTreeNode = gTable.Col.ParentNode; gCurrentNode = gCurrentTreeNode = GetParentXXNode(gTable.Col); gTable.Col = null; } return; case HtmlTagType.TR: if (gTable.Row != null) { //gCurrentNode = gCurrentTreeNode = gTable.Row.ParentNode; gCurrentNode = gCurrentTreeNode = GetParentXXNode(gTable.Row); gTable.Row = null; } return; case HtmlTagType.TH: case HtmlTagType.TD: if (gTable.Data != null) { //gCurrentNode = gCurrentTreeNode = gTable.Data.ParentNode; gCurrentNode = gCurrentTreeNode = GetParentXXNode(gTable.Data); gTable.Data = null; } return; } } } //XmlNode node = gCurrentTreeNode; //while (node != null) //{ // if (node.Name == sTagName) // { // gCurrentTreeNode = node.ParentNode; // break; // } // node = node.ParentNode; //} XXXNode_v2 node = GetParentXXNodeByName(gCurrentTreeNode, sTagName); if (node != null) { gCurrentTreeNode = GetParentXXNode(node); } gCurrentNode = gCurrentTreeNode; }
private void TagBegin(string sTagName, bool bTagEnd) { gbNoTag = false; //sTagName = sTagName.Replace('-', '_'); //sTagName = sTagName.Replace('!', '_'); //sTagName = sTagName.Replace('[', '_'); //sTagName = sTagName.Replace(']', '_'); //sTagName = gReplace.Replace(sTagName, "_"); //if (sTagName == "") sTagName = "_"; HtmlTagType tagType = HtmlTags.GetHtmlTagType(sTagName); HtmlTag tag = HtmlTags.GetHtmlTag(tagType); if (gbNormalizeXml) { if (tagType == HtmlTagType.Html || tagType == HtmlTagType.Head) { gbNoTag = true; return; } if (tagType == HtmlTagType.Body) { gbNoTag = true; if (!gbBody) { gbBody = true; gCurrentNode = gCurrentTreeNode = gBodyNode; } return; } if (tagType == HtmlTagType.Title) { if (!gbTitle) { if (!bTagEnd) { gbTitle = true; gCurrentNode = gTitleNode; } } else { gbNoTag = true; } return; } if (!gbBody && tag.TagCategory != HtmlTagCategory.Head) { gbBody = true; gCurrentNode = gCurrentTreeNode = gBodyNode; } } //gCurrentNode = gXmlDocument.CreateElement(sTagName); gCurrentNode = CreateElement(sTagName); if (gbNormalizeXml) { if (tagType == HtmlTagType.Table && !bTagEnd) { if (gTable != null) { gTableStack.Push(gTable); } gTable = new HtmlTable_v2(); gTable.Table = gCurrentNode; //gCurrentTreeNode.AppendChild(gCurrentNode); AddElement(gCurrentTreeNode, gCurrentNode); gCurrentTreeNode = gCurrentNode; return; } if (TagBeginTableCategory(tag, bTagEnd)) { return; } if (tagType == HtmlTagType.DL && !bTagEnd) { if (gDefinitionList != null) { gDefinitionListStack.Push(gDefinitionList); } gDefinitionList = gCurrentNode; //gCurrentTreeNode.AppendChild(gCurrentNode); AddElement(gCurrentTreeNode, gCurrentNode); gCurrentTreeNode = gCurrentNode; return; } if (TagBeginDefinitionListCategory(tag, bTagEnd)) { return; } // $$pb à revérifier // il faut au moins annuler gLastPNode quand un des parents de gLastPNode se ferme //if (tagType == HtmlTagTypeEnum.P) //{ // // pour gérer une balise <p> qui n'a pas de fin de balise </p> // if (gLastPNode != null) // { // gCurrentTreeNode = GetParentXXNode(gLastPNode); // gLastPNode = null; // } // if (!bTagEnd) gLastPNode = gCurrentNode; //} } //gCurrentTreeNode.AppendChild(gCurrentNode); AddElement(gCurrentTreeNode, gCurrentNode); if (!bTagEnd && tag.EndBoundType != HtmlBoundType.Forbidden) { gCurrentTreeNode = gCurrentNode; } }
public HtmlTagInfo(string tagName, HtmlTagType tagType, string tagContent) { this.Name = tagName; this.TagType = tagType; this.InsideContent = tagContent; }
/// <summary> /// Initializes a new instance of the <see cref="HtmlTag"/> class. /// </summary> /// <param name="tagType">Type of the tag.</param> /// <param name="tag">The tag.</param> private HtmlTag(HtmlTagType tagType, string tag) { TagType = tagType; Tag = tag; }
protected virtual bool OnHandleTagBegin(HtmlTagType tag, string value) { switch (tag) { case HtmlTagType.TITLE: mIsNextTitleText = true; return(true); case HtmlTagType.BR: { if (NextTextIsNotShow) { NextTextIsNotShow = false; return(true); } DoChangeLine(); } return(true); case HtmlTagType.A_HREF: mNowHrefbData = value; return(true); case HtmlTagType.A_COLOR: mNowHrefbColor = value; return(true); case HtmlTagType.A_ENABLE: mNowEnableData = value; return(true); case HtmlTagType.FONT_SIZE: { int size = 0; if (int.TryParse(value, out size)) { if (size > 100) { size = 100; } mFontSizeTagStack.Push(size); float height = mFontSizeTagStack.Peek(); mLastFontSize = height; } } return(true); case HtmlTagType.FONT_COLOR: { Color color = StringUtils.ColorStr2U3DColor(value); mFontColorTagStack.Push(color); } return(true); case HtmlTagType.FONT_EFFECT: { string[] ps = value.Split(",".ToCharArray()); if (ps.Length >= 3) { UILabel.Effect et = UILabel.Effect.None; if (ps[0] == "s") { et = UILabel.Effect.Shadow; } else if (ps[0] == "o") { et = UILabel.Effect.Outline; } else { return(true); } float distX = 0, distY = 0; if (!float.TryParse(ps[1], out distX)) { return(false); } if (!float.TryParse(ps[2], out distY)) { return(false); } if (ps.Length == 4) { Color c = StringUtils.ColorStr2U3DColor(ps[3]); mFontEffectTagStack.Push(new UILabelEffect(et, distX, distY, c)); } else { mFontEffectTagStack.Push(new UILabelEffect(et, distX, distY)); } } } return(true); case HtmlTagType.SPACE_HOR: { int val = 0; if (int.TryParse(value, out val)) { mSpaceHorStack.Push(val); } else { mSpaceHorStack.Push(0); } } return(true); case HtmlTagType.SPACE_VER: { int val = 0; if (int.TryParse(value, out val)) { mSpaceVerStack.Push(val); } else { mSpaceVerStack.Push(0); } } return(true); case HtmlTagType.SPACE_SEGMENT: { int val = 0; if (int.TryParse(value, out val)) { mSpaceSegmentStack.Push(val); } else { mSpaceSegmentStack.Push(0); } } return(true); case HtmlTagType.TRANS_SIZE_W: { int val = 0; if (int.TryParse(value, out val)) { mTransSizeWStack.Push(val); } else { mTransSizeWStack.Push(0); } } return(true); case HtmlTagType.TRANS_SIZE_H: { int val = 0; if (int.TryParse(value, out val)) { mTransSizeHStack.Push(val); } else { mTransSizeHStack.Push(0); } } return(true); case HtmlTagType.TRANS_POS_X: { int val = 0; if (int.TryParse(value, out val)) { mTransPosXStack.Push(val); } else { mTransPosXStack.Push(0); } } return(true); case HtmlTagType.TRANS_POS_Y: { int val = 0; if (int.TryParse(value, out val)) { mTransPosYStack.Push(val); } else { mTransPosYStack.Push(0); } } return(true); case HtmlTagType.IMAGE_ID: { string[] names = value.Split("/".ToCharArray()); if (names.Length != 2) { return(false); } if (!DoAddImage(names[0], names[1])) { return(false); } } return(true); case HtmlTagType.IMGANIM_ID: { string[] names = value.Split("/".ToCharArray()); if (names.Length != 4) { return(false); } int fps = 0; if (!int.TryParse(names[3], out fps)) { return(false); } if (!DoAddImageAnim(names[0], names[1], names[2], fps)) { return(false); } } return(true); case HtmlTagType.NUMBER_ID: { if (!DoAddNumber(value)) { return(false); } } return(true); case HtmlTagType.PARAM_ID: { int idx = int.Parse(value) - 1; if (idx < 0 || idx >= mParamList.Count) { return(false); } if (mParamList[idx] is string) { OnCreateText(mParamList[idx] as string); } else { OnCreateText(mParamList[idx].ToString()); } } return(true); case HtmlTagType.PARAM_PUSH: { mPushParamList.Add(value); } return(true); } return(true); }
private void TagEnd(string sTagName) { if (_normalizeXml) { HtmlTagType tagType = HtmlTags.GetHtmlTagType(sTagName); switch (tagType) { case HtmlTagType.Html: case HtmlTagType.Head: case HtmlTagType.Body: return; case HtmlTagType.Title: _currentNode = _currentTreeNode; return; case HtmlTagType.Table: if (_table == null) { return; } _currentNode = _currentTreeNode = GetParentXXNode(_table.Table); _table = null; if (_tableStack.Count != 0) { _table = _tableStack.Pop(); } return; case HtmlTagType.DL: if (_definitionList == null) { return; } _currentNode = _currentTreeNode = GetParentXXNode(_definitionList); _definitionList = null; if (_definitionListStack.Count != 0) { _definitionList = _definitionListStack.Pop(); } return; } if (_table != null) { switch (tagType) { case HtmlTagType.THead: case HtmlTagType.TBody: case HtmlTagType.TFoot: _currentNode = _currentTreeNode = _table.Table; _table.Body = null; return; case HtmlTagType.ColGroup: _currentNode = _currentTreeNode = _table.Table; _table.ColGroup = null; return; case HtmlTagType.Col: if (_table.Col != null) { _currentNode = _currentTreeNode = GetParentXXNode(_table.Col); _table.Col = null; } return; case HtmlTagType.TR: if (_table.Row != null) { _currentNode = _currentTreeNode = GetParentXXNode(_table.Row); _table.Row = null; } return; case HtmlTagType.TH: case HtmlTagType.TD: if (_table.Data != null) { _currentNode = _currentTreeNode = GetParentXXNode(_table.Data); _table.Data = null; } return; } } } XXXNode_v2 node = GetParentXXNodeByName(_currentTreeNode, sTagName); if (node != null) { _currentTreeNode = GetParentXXNode(node); } _currentNode = _currentTreeNode; }
protected virtual bool OnHandleTagEnd(HtmlTagType tag) { switch (tag) { case HtmlTagType.AEND: case HtmlTagType.A: { mNowHrefbData = ""; mNowHrefbColor = ""; //mNowEnableData = ""; } return(true); case HtmlTagType.A_HREF: mNowHrefbData = ""; return(true); case HtmlTagType.A_COLOR: mNowHrefbColor = ""; return(true); case HtmlTagType.A_ENABLE: mNowEnableData = ""; return(true); case HtmlTagType.FONT_SIZE: { if (mFontSizeTagStack.Count > 1) { mFontSizeTagStack.Pop(); } } return(true); case HtmlTagType.FONT_COLOR: { if (mFontColorTagStack.Count > 1) { mFontColorTagStack.Pop(); } } return(true); case HtmlTagType.FONT_EFFECT: { if (mFontEffectTagStack.Count > 1) { mFontEffectTagStack.Pop(); } } return(true); case HtmlTagType.SPACE_HOR: { if (mSpaceHorStack.Count > 1) { mSpaceHorStack.Pop(); } } return(true); case HtmlTagType.SPACE_VER: { if (mSpaceVerStack.Count > 1) { mSpaceVerStack.Pop(); } } return(true); case HtmlTagType.SPACE_SEGMENT: { if (mSpaceSegmentStack.Count > 1) { mSpaceSegmentStack.Pop(); } } return(true); case HtmlTagType.TRANS_SIZE_W: { if (mTransSizeWStack.Count > 1) { mTransSizeWStack.Pop(); } } return(true); case HtmlTagType.TRANS_SIZE_H: { if (mTransSizeHStack.Count > 1) { mTransSizeHStack.Pop(); } } return(true); case HtmlTagType.TRANS_POS_X: { if (mTransPosXStack.Count > 1) { mTransPosXStack.Pop(); } } return(true); case HtmlTagType.TRANS_POS_Y: { if (mTransPosYStack.Count > 1) { mTransPosYStack.Pop(); } } return(true); } return(true); }