5 using System
.Xml
.XPath
;
6 using System
.Collections
.Generic
;
8 namespace Monodoc
.Generators
.Html
10 public class Error2Html
: IHtmlExporter
12 public string Export (string input
, Dictionary
<string, string> extraArgs
)
14 return Htmlize (new XPathDocument (new StringReader (input
)));
17 public string Export (Stream input
, Dictionary
<string, string> extraArgs
)
19 return Htmlize (new XPathDocument (input
));
22 public string CssCode
{
27 border: 2px solid #782609;
39 border: 1px solid black;
51 border: 1px solid black;
54 text-transform: uppercase;
62 public string Htmlize (IXPathNavigable doc
)
64 var navigator
= doc
.CreateNavigator ();
65 var errorName
= navigator
.SelectSingleNode ("//ErrorDocumentation/ErrorName");
66 var details
= navigator
.SelectSingleNode ("//ErrorDocumentation/Details");
68 StringWriter sw
= new StringWriter ();
69 XmlWriter w
= new XmlTextWriter (sw
);
71 WriteElementWithClass (w
, "div", "header");
72 w
.WriteAttributeString ("id", "error_ref");
73 WriteElementWithClass (w
, "div", "subtitle", "Compiler Error Reference");
74 WriteElementWithClass (w
, "div", "title", "Error " + (errorName
== null ? string.Empty
: errorName
.Value
));
77 if (details
!= null) {
78 WriteElementWithClass (w
, "div", "summary", "Summary");
80 var summary
= details
.SelectSingleNode ("/Summary");
81 w
.WriteValue (summary
== null ? string.Empty
: summary
.Value
);
83 WriteElementWithClass (w
, "div", "details", "Details");
84 var de
= details
.SelectSingleNode ("/Details");
85 w
.WriteValue (de
== null ? string.Empty
: de
.Value
);
88 foreach (XPathNavigator xmp
in navigator
.Select ("//ErrorDocumentation/Examples/string")) {
89 WriteElementWithClass (w
, "div", "code_example");
90 WriteElementWithClass (w
, "div", "code_ex_title", "Example");
91 w
.WriteRaw (Mono
.Utilities
.Colorizer
.Colorize (xmp
.Value
, "c#"));;
97 return sw
.ToString ();
100 void WriteElementWithClass (XmlWriter w
, string element
, string cls
, string content
= null)
102 w
.WriteStartElement (element
);
103 w
.WriteAttributeString ("class", cls
);
104 if (!string.IsNullOrEmpty (content
)) {
105 w
.WriteValue (content
);
106 w
.WriteEndElement ();