public bool RenderObject(object o, int depth, XhtmlTextWriter writer) { var objectType = o.GetType(); if(IsSimpleType(objectType)) { writer.RenderBeginTag(HtmlTextWriterTag.P); writer.Write(o.ToString()); writer.RenderEndTag(); writer.WriteLine(); return true; } //get the members (fields and properties) var members = GetMembers(objectType); //create a two column table containing member and then value writer.RenderBeginTag(HtmlTextWriterTag.Table); //write a header containing the class name writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2"); writer.RenderBeginTag(HtmlTextWriterTag.Th); writer.Write(objectType.Name); writer.RenderEndTag(); //th writer.RenderEndTag(); //tr foreach (var member in members) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.AddAttribute(HtmlTextWriterAttribute.Class, "left"); writer.RenderBeginTag(HtmlTextWriterTag.Th); writer.Write(member.Name); writer.RenderEndTag(); //th writer.RenderBeginTag(HtmlTextWriterTag.Td); RenderMember(member, o, depth, writer); writer.RenderEndTag(); //td writer.RenderEndTag(); //tr } writer.RenderEndTag(); //table writer.WriteLine(); return true; }
/// <summary> /// Renders this instance. /// </summary> public void Render() { using (var html = new XhtmlTextWriter(this.Context.Writer)) { // messages html.AddAttribute(HtmlTextWriterAttribute.Class, "messages"); html.AddAttribute(HtmlTextWriterAttribute.Id, "message"); html.RenderBeginTag(HtmlTextWriterTag.Div); switch (this.Scope) { case MessageScope.Error: WriteMessage(html, "error", Errors.GenericMessage); break; case MessageScope.Warning: WriteMessage(html, "warning", Titles.Warning); break; default: WriteMessage(html, "success", Titles.Success); break; } // end messages html.RenderEndTag(); } }
private void Reformat() { // // Write out the HTML document lead. // StringWriter sw = new StringWriter(); XhtmlTextWriter htmlWriter = new XhtmlTextWriter(sw, " "); htmlWriter.WriteLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); htmlWriter.AddAttribute("xmlns", "http://www.w3.org/1999/xhtml"); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Html); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Head); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Title); htmlWriter.WriteEncodedText(Path.GetFileNameWithoutExtension(Mask.EmptyString(DocumentPath, _defaultFileName))); htmlWriter.RenderEndTag(); htmlWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/css"); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Style); htmlWriter.Write(@"a:link{ color:#00c} body{ background:#fff; font-size:83%; font-family:arial,sans-serif} td, th{ font-size:100%} td{ border:solid 1px #aaa; padding:5px} table{ border-collapse:separate} h1{ font-size:x-large; margin-top:0px} h2{ font-size:large} h3{ font-size:medium} h4{ font-size:small} img{ border:0} pre{ margin-left:2em; padding:0.5em; border-left:3px solid #ccc}"); htmlWriter.RenderEndTag(/* style */); htmlWriter.RenderEndTag(/* head */); htmlWriter.RenderBeginTag(HtmlTextWriterTag.Body); // // Format the wiki into the HTML body. // new HtmlFormatter().Format(new WikiParser().Parse(new StringReader(_wikiBox.Text)), htmlWriter); // // Conclude the HTML document. // htmlWriter.RenderEndTag(/* body */); htmlWriter.RenderEndTag(/* html */); string html = sw.GetStringBuilder().ToString().Replace("\r", string.Empty); // // Update the WebBrowser with the HTML preview. // _webBrowser.AllowNavigation = true; _webBrowser.DocumentText = html; // // Update the RichTextBox with the HTML source and highlight // the markup. // _htmlBox.Clear(); _htmlBox.Text = html; HighlightMarkup(_htmlBox); // // The preview is now up to date with the wiki changes. // _wikiChanged = false; }