static HtmlTextWriter ()
{
+#if NET_2_0
+ _tagTable = new Hashtable (tags.Length, StringComparer.OrdinalIgnoreCase);
+ _attributeTable = new Hashtable (htmlattrs.Length, StringComparer.OrdinalIgnoreCase);
+ _styleTable = new Hashtable (htmlstyles.Length, StringComparer.OrdinalIgnoreCase);
+#else
_tagTable = new Hashtable (tags.Length,
CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
_styleTable = new Hashtable (htmlstyles.Length,
CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
-
+#endif
foreach (HtmlTag tag in tags)
_tagTable.Add (tag.name, tag);
public virtual void AddAttribute (HtmlTextWriterAttribute key, string value, bool fEncode)
{
if (fEncode)
- value = EncodeAttributeValue (key, value);
+ value = HttpUtility.HtmlAttributeEncode (value);
+
AddAttribute (GetAttributeName (key), value, key);
}
public virtual void AddAttribute (HtmlTextWriterAttribute key, string value)
{
- bool fEncode = key != HtmlTextWriterAttribute.Name;
- AddAttribute (key, value, fEncode);
+ if ((key != HtmlTextWriterAttribute.Name) && (key != HtmlTextWriterAttribute.Id))
+ value = HttpUtility.HtmlAttributeEncode (value);
+
+ AddAttribute (GetAttributeName (key), value, key);
}
public virtual void AddAttribute (string name, string value)
{
- bool fEncode = String.Compare ("name", name, true, CultureInfo.InvariantCulture) != 0;
- AddAttribute (name, value, fEncode);
+ HtmlTextWriterAttribute key = GetAttributeKey (name);
+
+ if ((key != HtmlTextWriterAttribute.Name) && (key != HtmlTextWriterAttribute.Id))
+ value = HttpUtility.HtmlAttributeEncode (value);
+
+ AddAttribute (name, value, key);
}
protected virtual void AddAttribute (string name, string value, HtmlTextWriterAttribute key)
public virtual void RenderBeginTag (string tagName)
{
- if (!OnTagRender (tagName, GetTagKey (tagName)))
- return;
+ bool ignore = !OnTagRender (tagName, GetTagKey (tagName));
PushEndTag (tagName);
-
+ TagIgnore = ignore;
DoBeginTag ();
}
public virtual void RenderBeginTag (HtmlTextWriterTag tagKey)
{
- if (!OnTagRender (GetTagName (tagKey), tagKey))
- return;
+ bool ignore = !OnTagRender (GetTagName (tagKey), tagKey);
PushEndTag (tagKey);
-
DoBeginTag ();
+ TagIgnore = ignore;
}
void WriteIfNotNull (string s)
void DoBeginTag ()
{
WriteIfNotNull (RenderBeforeTag ());
- WriteBeginTag (TagName);
- FilterAttributes ();
-
- HtmlTextWriterTag key = (int) TagKey < tags.Length ? TagKey : HtmlTextWriterTag.Unknown;
-
- switch (tags [(int) key].tag_type) {
- case TagType.Inline:
- Write (TagRightChar);
- break;
- case TagType.Block:
- Write (TagRightChar);
- WriteLine ();
- Indent++;
- break;
- case TagType.SelfClosing:
- Write (SelfClosingTagEnd);
- break;
+ if (!TagIgnore) {
+ WriteBeginTag (TagName);
+ FilterAttributes ();
+
+ HtmlTextWriterTag key = (int) TagKey < tags.Length ? TagKey : HtmlTextWriterTag.Unknown;
+
+ switch (tags [(int) key].tag_type) {
+ case TagType.Inline:
+ Write (TagRightChar);
+ break;
+ case TagType.Block:
+ Write (TagRightChar);
+ WriteLine ();
+ Indent++;
+ break;
+ case TagType.SelfClosing:
+ Write (SelfClosingTagEnd);
+ break;
+ }
}
-
+
// FIXME what do i do for self close here?
WriteIfNotNull (RenderBeforeContent ());
}
public virtual void RenderEndTag ()
{
+
// FIXME what do i do for self close here?
WriteIfNotNull (RenderAfterContent ());
- HtmlTextWriterTag key = (int) TagKey < tags.Length ? TagKey : HtmlTextWriterTag.Unknown;
-
- switch (tags [(int) key].tag_type) {
- case TagType.Inline:
- WriteEndTag (TagName);
- break;
- case TagType.Block:
- Indent--;
- WriteLineNoTabs ("");
- WriteEndTag (TagName);
-
- break;
- case TagType.SelfClosing:
- // NADA
- break;
+ if (!TagIgnore) {
+ HtmlTextWriterTag key = (int) TagKey < tags.Length ? TagKey : HtmlTextWriterTag.Unknown;
+
+ switch (tags [(int) key].tag_type) {
+ case TagType.Inline:
+ WriteEndTag (TagName);
+ break;
+ case TagType.Block:
+ Indent--;
+ WriteLineNoTabs ("");
+ WriteEndTag (TagName);
+
+ break;
+ case TagType.SelfClosing:
+ // NADA
+ break;
+ }
}
+
WriteIfNotNull (RenderAfterTag ());
PopEndTag ();
}
}
+ bool TagIgnore {
+ get {
+ if (tagstack_pos == -1)
+ throw new InvalidOperationException ();
+
+ return tagstack [tagstack_pos].ignore;
+ }
+
+ set {
+ if (tagstack_pos == -1)
+ throw new InvalidOperationException ();
+
+ tagstack [tagstack_pos].ignore = value;
+ }
+ }
+
+ internal HttpWriter GetHttpWriter ()
+ {
+ return b as HttpWriter;
+ }
TextWriter b;
string tab_string;
AddedTag {
public string name;
public HtmlTextWriterTag key;
+ public bool ignore;
}
#if TARGET_JVM
{
throw new NotImplementedException ();
}
+
+ public virtual void BeginRender ()
+ {
+ }
+ public virtual void EndRender ()
+ {
+ }
#endif
}
-}
\ No newline at end of file
+}