Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DocTools.cs - github.com/xamarin/macdoc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 32f40f65ddb2ab6dbfc7575bc2dbcd514dff7e82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// A few routines that were copy-pasted from the docbrowser
//

using System;
using Monodoc;
using Monodoc.Generators;
using System.IO;

namespace macdoc
{
	public class DocTools
	{
		static IDocGenerator<string> generator = new HtmlGenerator (null);

		public static string GetHtml (string url, HelpSource helpSource)
		{
			Node _;
			return GetHtml (url, helpSource, out _);
		}
		
		public static string GetHtml (string url, HelpSource helpSource, out Node match)
		{
			string htmlContent = null;
			match = null;
			
			if (helpSource != null)
				htmlContent = AppDelegate.Root.RenderUrl (url, generator, out match, helpSource);
			if (htmlContent == null) {
				// the displayed url have a lower case type code (e.g. t: instead of T:) which confuse monodoc
				if (url.Length > 2 && url[1] == ':')
					url = char.ToUpperInvariant (url[0]) + url.Substring (1);
				// It may also be url encoded so decode it
				url = Uri.UnescapeDataString (url);
				htmlContent = AppDelegate.Root.RenderUrl (url, generator, out match, helpSource);
				if (htmlContent != null && match != null && match.Tree != null)
					helpSource = match.Tree.HelpSource;
			}
			if (htmlContent == null)
				return null;
			
			var html = new StringWriter ();
   			html.Write ("<html>\n<head><title>{0}</title>", url);
			
			if (helpSource != null) {
				if (HtmlGenerator.InlineCss != null)
                    html.Write (" <style type=\"text/css\">{0}</style>\n", HtmlGenerator.InlineCss);
				/*if (helpSource.InlineJavaScript != null)
                    html.Write ("<script type=\"text/JavaScript\">{0}</script>\n", helpSource.InlineJavaScript);*/
            }

            html.Write ("</head><body>");
            html.Write (htmlContent);
            html.Write ("</body></html>\n");
            return html.ToString ();
		}
	}
}