// // monohb-provider.cs: Handbook provider for Monodoc // // Authors: // Copyright 2003 Lee Mallabone // Johannes Roith // Miguel de Icaza // namespace Monodoc { using System.Xml; using System; /** * Processes the mono handbook to remove extra web-specific div sections. */ public class MonoHBHelpSource: XhtmlHelpSource { public MonoHBHelpSource (string base_file, bool create) : base (base_file, create) { } public override XmlDocument ProcessContent(XmlDocument docToProcess) { Console.WriteLine ("x1"); XmlNamespaceManager nsmgr = new XmlNamespaceManager(docToProcess.NameTable); nsmgr.AddNamespace("default", "http://www.w3.org/1999/xhtml"); nsmgr.AddNamespace("monodoc", "http://www.go-mono.org/xml/monodoc"); nsmgr.PushScope(); Console.WriteLine ("x2"); XmlElement root = docToProcess.DocumentElement; XmlNode body = root.SelectSingleNode("/default:html/default:body", nsmgr); // Use the DC.Description meta tag as sign, that the file is in the new format Console.WriteLine ("x3"); if (root.SelectNodes("/default:html/default:head/default:meta[@name='DC.Description']", nsmgr).Count != 0) { ////////////////////////////////////////////////////////////////////// // Start of temporary code, until the tutorial is converted completely ////////////////////////////////////////////////////////////////////// XmlNodeList nodeList = docToProcess.GetElementsByTagName("div"); /* Remove the mono handbook specific decorations */ foreach(XmlNode node in nodeList) { string cssClass = ((XmlElement)node).GetAttribute("class"); if (cssClass != null && (cssClass == "topframe" || cssClass == "navbar" || cssClass == "copyright")) { node.RemoveAll(); } } string headinginner = "Mono Handbook"; XmlNode firstheading = docToProcess.GetElementsByTagName("title")[0]; headinginner = firstheading.InnerXml; try { XmlNode bodynode = docToProcess.GetElementsByTagName("body")[0]; bodynode.InnerXml = "" + "
Mono Handbook

" + headinginner + "

" + bodynode.InnerXml; } catch { } Console.WriteLine ("x5"); ////////////////////////////////////////////////////////////////////// // End of temporary code, until the tutorial is converted completely ////////////////////////////////////////////////////////////////////// XmlNodeList nodeList2 = docToProcess.GetElementsByTagName("pre"); foreach(XmlNode node in nodeList2) { string cssClass = ((XmlElement)node).GetAttribute("class"); if (cssClass != null) { switch(cssClass) { case "code": node.InnerXml = "
" + "" + "" + "" + "" + "" + "" + "" + "" + "
" + "
" + "
" + 
	
						node.InnerXml +
		
							"
"; break; case "console": node.InnerXml = "
" + "" + "" + "" + "" + "" + "" + "" + "" + "
" + "
" + "
" + 
	
						node.InnerXml +
	
						"
"; break; default: break; } } } nodeList = root.SelectNodes("//monodoc:example", nsmgr); foreach (XmlNode node in nodeList) { //XmlNode csnode = root.SelectSingleNode("/monodoc:source[@lang='CS']", nsmgr); body.RemoveChild(node); } //string copyright_string = ""; // no string for now nodeList = root.SelectNodes("//default:link[@type='text/css']", nsmgr); if (nodeList.Count == 0) { // TODO: Stylesheet path maybe variable root.SelectSingleNode("/default:html/default:head", nsmgr).InnerXml += "\n "; } string contributor_string = "

Credits

"; nodeList = root.SelectNodes("//default:meta[@name='DC.Contributor']", nsmgr); foreach (XmlNode node in nodeList) { contributor_string += node.Attributes.GetNamedItem("content").Value + "
\n"; } // body.InnerXml += contributor_string + copyright_string; } else { Console.WriteLine ("x4"); XmlNodeList nodeList = docToProcess.GetElementsByTagName("div"); if (nodeList != null){ /* Remove the mono handbook specific decorations */ foreach(XmlNode node in nodeList) { string cssClass = ((XmlElement)node).GetAttribute("class"); if (cssClass != null && (cssClass == "topframe" || cssClass == "navbar" || cssClass == "copyright")){ node.RemoveAll(); } } } Console.WriteLine ("x6"); string headinginner = "Mono Handbook"; XmlNode firstheading = null; try { firstheading = docToProcess.GetElementsByTagName("h1")[0]; headinginner = firstheading.InnerXml; } catch { try { firstheading = docToProcess.GetElementsByTagName("h2")[0]; headinginner = firstheading.InnerXml; } catch {} } Console.WriteLine ("x8"); try { XmlNode bodynode = docToProcess.GetElementsByTagName("body")[0]; if (firstheading != null) bodynode.RemoveChild(firstheading); bodynode.InnerXml = "" + "
Mono Handbook

" + headinginner + "

" + bodynode.InnerXml; } catch { } Console.WriteLine ("x9"); XmlNodeList nodeList2 = docToProcess.GetElementsByTagName("pre"); foreach(XmlNode node in nodeList2){ string cssClass = ((XmlElement)node).GetAttribute("class"); if (cssClass != null){ switch(cssClass) { case "code": node.InnerXml = "
" + "" + "" + "" + "" + "" + "" + "" + "" + "
" + "
" + "
" + "
" +
						
						node.InnerXml +
						
						"
" + "
"; break; case "console": node.InnerXml = "
" + "" + "" + "" + "" + "" + "" + "" + "" + "
" + "
" + "
" + "
" +
						
						node.InnerXml +
						
						"
" + "
"; break; default: break; } } } } return docToProcess; } } }