// Rendu d'un élément HTML public string renderHtmlElement(HtmlElement elem) { string res = ""; //on détermine le type de balise bool multiline = HtmlElement.multiLineTags.Exists(v => v == elem.getTagname()); bool monoline = HtmlElement.monoLineTags.Exists(v => v == elem.getTagname()); bool inline = (!multiline && !monoline); //chaine des attributs string resattr = ""; if (elem.attributes.Count > 0) { foreach (HtmlTagAttribute attr in elem.attributes) { resattr += " "; resattr += renderHtmlTagAttribute(attr); } } //OpenTag //if (multiline) res += '\n'; res += renderHtmlTag(elem.getOpenTag(), resattr); //retour à la ligne post-OpenTag multiline if (multiline) res += '\n'; //content if (elem.tagContent.Count > 0) { foreach (HtmlTagContent e in elem.tagContent) { if (e is HtmlElement) res += renderHtmlElement(e as HtmlElement); else if (e is HtmlText) res += renderHtmlText(e as HtmlText); } } //indentation avant les multilines (intent ='' pour les inlines) if (multiline) res += '\n'; //EndTag if (elem.isClosed()) res += renderHtmlTag(elem.getEndTag()); //retour à la ligne post-non-inline if (!inline) res += '\n'; return res; }
// Rendu d'un élément HTML public List<StrTypePair> renderHtmlElement(HtmlElement elem) { List<StrTypePair> res = new List<StrTypePair>(); //on détermine le type de balise bool multiline = HtmlElement.multiLineTags.Exists(v => v == elem.getTagname()); bool monoline = HtmlElement.monoLineTags.Exists(v => v == elem.getTagname()); bool inline = (!multiline && !monoline); _isAutoTag = _htmlAutoTags.Exists(v => v == elem.getTagname()); //chaine des attributs List<StrTypePair> resattr = new List<StrTypePair>(); if (elem.attributes.Count > 0) { foreach (HtmlTagAttribute attr in elem.attributes) { resattr.Add(new StrTypePair(" ", (_isAutoTag) ? StrTypePair.StrType.AUTO_TAG : StrTypePair.StrType.USR_TAG)); resattr.AddRange(renderHtmlTagAttribute(attr)); } } //OpenTag //if (multiline) res += '\n'; res.AddRange(renderHtmlTag(elem.getOpenTag(), resattr)); //retour à la ligne post-OpenTag multiline if (multiline) res.Add(new StrTypePair("\n", StrTypePair.StrType.LINE_BREAK)); //content if (elem.tagContent.Count > 0) { foreach (HtmlTagContent e in elem.tagContent) { if(e is HtmlElement) res.AddRange(renderHtmlElement(e as HtmlElement)); else if(e is HtmlText) res.Add(renderHtmlText(e as HtmlText)); } } //indentation avant les multilines (intent ='' pour les inlines) if (multiline) res.Add(new StrTypePair("\n", StrTypePair.StrType.LINE_BREAK)); //EndTag if (elem.isClosed()) res.AddRange(renderHtmlTag(elem.getEndTag())); //retour à la ligne post-non-inline if (!inline) res.Add(new StrTypePair("\n", StrTypePair.StrType.LINE_BREAK)); return res; }