Exemplo n.º 1
0
        public static string GetDocumentationMarkup(string doc, DocumentationFormatOptions options)
        {
            if (string.IsNullOrEmpty(doc))
            {
                return(null);
            }
            System.IO.StringReader reader     = new System.IO.StringReader("<docroot>" + doc + "</docroot>");
            XmlTextReader          xml        = new XmlTextReader(reader);
            StringBuilder          ret        = new StringBuilder(70);
            StringBuilder          parameters = new StringBuilder();
            StringBuilder          exceptions = new StringBuilder();

            parameters.AppendLine(options.FormatHeading("Parameters:"));

            exceptions.AppendLine(options.FormatHeading("Exceptions:"));
            //		ret.Append ("<small>");
            int paramCount = 0, exceptionCount = 0, summaryEnd = -1;

            try {
                xml.Read();
                do
                {
                    if (xml.NodeType == XmlNodeType.Element)
                    {
                        switch (xml.Name.ToLower())
                        {
                        case "para":
                            ret.Append(options.FormatBody(ParseBody(xml, xml.Name, options)));
                            if (summaryEnd < 0)
                            {
                                summaryEnd = ret.Length;
                            }
                            break;

                        case "summary":
//							ret.AppendLine (GetHeading ("Summary:", options));
                            ret.Append(options.FormatBody(ParseBody(xml, xml.Name, options)));
                            if (summaryEnd < 0)
                            {
                                summaryEnd = ret.Length;
                            }
                            break;

                        case "remarks":
                            if (string.IsNullOrEmpty(options.HighlightParameter))
                            {
                                ret.AppendLine(options.FormatHeading("Remarks:"));
                                ret.Append(options.FormatBody(ParseBody(xml, xml.Name, options)));
                                if (summaryEnd < 0)
                                {
                                    summaryEnd = ret.Length;
                                }
                            }
                            else
                            {
                                options.FormatBody(ParseBody(xml, xml.Name, options));
                            }
                            break;

                        // skip <example>-nodes
                        case "example":
                            xml.Skip();
                            xml.Skip();
                            break;

                        case "exception":
                            exceptionCount++;
                            if (options.SmallText)
                            {
                                exceptions.Append("<small>");
                            }
                            exceptions.Append("<b>");
                            exceptions.Append(EscapeText(GetCref(xml["cref"])));
                            exceptions.Append(": ");
                            exceptions.Append("</b>");
                            if (options.SmallText)
                            {
                                exceptions.Append("</small>");
                            }

                            exceptions.AppendLine(options.FormatBody(ParseBody(xml, xml.Name, options)));
                            break;

                        case "returns":
                            if (string.IsNullOrEmpty(options.HighlightParameter))
                            {
                                ret.AppendLine(options.FormatHeading("Returns:"));
                                ret.Append(options.FormatBody(ParseBody(xml, xml.Name, options)));
                            }
                            else
                            {
                                options.FormatBody(ParseBody(xml, xml.Name, options));
                            }
                            break;

                        case "param":
                            paramCount++;
                            string paramName = xml["name"].Trim();
                            parameters.Append("<i>");
                            if (options.HighlightParameter == paramName)
                            {
                                parameters.Append("<b>");
                            }
                            if (options.SmallText)
                            {
                                parameters.Append("<small>");
                            }
                            parameters.Append(EscapeText(paramName));
                            if (options.SmallText)
                            {
                                parameters.Append("</small>");
                            }
                            if (options.HighlightParameter == paramName)
                            {
                                parameters.Append("</b>");
                            }
                            parameters.Append(":</i> ");
                            parameters.Append(options.FormatBody(ParseBody(xml, xml.Name, options)));
                            break;

                        case "value":
                            ret.AppendLine(options.FormatHeading("Value:"));
                            ret.AppendLine(options.FormatBody(ParseBody(xml, xml.Name, options)));
                            break;

                        case "seealso":
                            if (string.IsNullOrEmpty(options.HighlightParameter))
                            {
                                ret.Append(options.FormatHeading("See also:"));
                                ret.Append(" " + EscapeText(GetCref(xml["cref"]) + xml["langword"]));
                            }
                            break;
                        }
                    }
                } while (xml.Read());
            } catch (Exception ex) {
                MonoDevelop.Core.LoggingService.LogError(ex.ToString());
                return(EscapeText(doc));
            }
            if (IsEmptyDocumentation(ret.ToString()))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(options.HighlightParameter) && exceptionCount > 0)
            {
                ret.Append(exceptions.ToString());
            }

            string result = ret.ToString();

            if (summaryEnd < 0)
            {
                summaryEnd = result.Length;
            }
            if (paramCount > 0)
            {
                result = result.Insert(summaryEnd, parameters.ToString());
            }

            result = result.Trim();
            if (result.EndsWith(Environment.NewLine + "</small>"))
            {
                result = result.Substring(0, result.Length - (Environment.NewLine + "</small>").Length) + "</small>";
            }
            return(result);
        }
Exemplo n.º 2
0
        public static string GetDocumentationMarkup(ISymbol member, string doc, DocumentationFormatOptions options)
        {
            if (string.IsNullOrEmpty(doc))
            {
                return(null);
            }
            System.IO.StringReader reader           = new System.IO.StringReader("<docroot>" + doc + "</docroot>");
            XmlTextReader          xml              = new XmlTextReader(reader);
            StringBuilder          ret              = StringBuilderCache.Allocate();
            StringBuilder          parameterBuilder = StringBuilderCache.Allocate();
            StringBuilder          exceptions       = StringBuilderCache.Allocate();

            exceptions.AppendLine(options.FormatHeading(GettextCatalog.GetString("Exceptions:")));
            //		ret.Append ("<small>");
            int paramCount = 0, exceptionCount = 0, summaryEnd = -1;

            try {
                xml.Read();
                do
                {
                    if (xml.NodeType == XmlNodeType.Element)
                    {
                        switch (xml.Name.ToLower())
                        {
                        case "para":
                            ret.Append(options.FormatBody(ParseBody(member, xml, xml.Name, options)));
                            if (summaryEnd < 0)
                            {
                                summaryEnd = ret.Length;
                            }
                            break;

                        case "member":
                        case "summary":
                            var summary = options.FormatBody(ParseBody(member, xml, xml.Name, options));
                            if (!IsEmptyDocumentation(summary))
                            {
                                //							ret.AppendLine (GetHeading ("Summary:", options));
                                ret.Append(summary);
                                if (summaryEnd < 0)
                                {
                                    summaryEnd = ret.Length;
                                }
                            }
                            break;

                        case "remarks":
                            if (string.IsNullOrEmpty(options.HighlightParameter))
                            {
                                ret.AppendLine(options.FormatHeading(GettextCatalog.GetString("Remarks:")));
                                ret.Append(options.FormatBody(ParseBody(member, xml, xml.Name, options)));
                                if (summaryEnd < 0)
                                {
                                    summaryEnd = ret.Length;
                                }
                            }
                            else
                            {
                                options.FormatBody(ParseBody(member, xml, xml.Name, options));
                            }
                            break;

                        // skip <example>-nodes
                        case "example":
                            xml.Skip();
                            xml.Skip();
                            break;

                        case "exception":
                            exceptionCount++;
                            if (options.SmallText)
                            {
                                exceptions.Append("<small>");
                            }
                            exceptions.Append("<b>");
                            exceptions.Append(EscapeText(xml ["cref"]));
                            exceptions.Append(": ");
                            exceptions.Append("</b>");
                            if (options.SmallText)
                            {
                                exceptions.Append("</small>");
                            }

                            exceptions.AppendLine(options.FormatBody(ParseBody(member, xml, xml.Name, options)));
                            break;

                        case "returns":
                            if (string.IsNullOrEmpty(options.HighlightParameter))
                            {
                                ret.AppendLine(options.FormatHeading(GettextCatalog.GetString("Returns:")));
                                ret.Append(options.FormatBody(ParseBody(member, xml, xml.Name, options)));
                            }
                            else
                            {
                                options.FormatBody(ParseBody(member, xml, xml.Name, options));
                            }
                            break;

                        case "param":
                            string paramName = xml.GetAttribute("name") != null ? xml ["name"].Trim() : "";

                            var body = options.FormatBody(ParseBody(member, xml, xml.Name, options));
                            if (!IsEmptyDocumentation(body))
                            {
                                paramCount++;
                                parameterBuilder.Append("<i>");
                                if (options.HighlightParameter == paramName)
                                {
                                    parameterBuilder.Append("<b>");
                                }
                                if (options.SmallText)
                                {
                                    parameterBuilder.Append("<small>");
                                }
                                parameterBuilder.Append(EscapeText(paramName));
                                if (options.SmallText)
                                {
                                    parameterBuilder.Append("</small>");
                                }
                                if (options.HighlightParameter == paramName)
                                {
                                    parameterBuilder.Append("</b>");
                                }
                                parameterBuilder.Append(":</i> ");
                                parameterBuilder.Append(body);
                            }
                            else
                            {
                                return(null);
                            }
                            break;

                        case "value":
                            ret.AppendLine(options.FormatHeading(GettextCatalog.GetString("Value:")));
                            ret.AppendLine(options.FormatBody(ParseBody(member, xml, xml.Name, options)));
                            break;

                        case "seealso":
                            if (string.IsNullOrEmpty(options.HighlightParameter))
                            {
                                ret.Append(options.FormatHeading(GettextCatalog.GetString("See also:")));
                                ret.Append(" ");
                                ret.Append(EscapeText(xml ["cref"]));
                                ret.Append(EscapeText(xml ["langword"]));
                            }
                            break;
                        }
                    }
                } while (xml.Read());

                if (IsEmptyDocumentation(ret.ToString()) && IsEmptyDocumentation(parameterBuilder.ToString()))
                {
                    return(EscapeText(doc));
                }
                if (string.IsNullOrEmpty(options.HighlightParameter) && exceptionCount > 0)
                {
                    ret.Append(exceptions.ToString());
                }

                string result = ret.ToString();
                if (summaryEnd < 0)
                {
                    summaryEnd = result.Length;
                }
                if (paramCount > 0)
                {
                    var paramSb = StringBuilderCache.Allocate();
                    if (result.Length > 0)
                    {
                        paramSb.AppendLine();                         /*
                                                                       * paramSb.Append ("<small>");
                                                                       * paramSb.AppendLine (options.FormatHeading (GettextCatalog.GetPluralString ("Parameter:", "Parameters:", paramCount)));
                                                                       * paramSb.Append ("</small>");*/
                    }
                    paramSb.Append(parameterBuilder.ToString());
                    result = result.Insert(summaryEnd, StringBuilderCache.ReturnAndFree(paramSb));
                }
                result = result.Trim();
                if (result.EndsWith(Environment.NewLine + "</small>"))
                {
                    result = result.Substring(0, result.Length - (Environment.NewLine + "</small>").Length) + "</small>";
                }
                return(result);
            } catch (Exception ex) {
                MonoDevelop.Core.LoggingService.LogError(ex.ToString());
                return(EscapeText(doc));
            } finally {
                StringBuilderCache.Free(ret);
                StringBuilderCache.Free(parameterBuilder);
                StringBuilderCache.Free(exceptions);
            }
        }
Exemplo n.º 3
0
		public static string GetDocumentationMarkup (ISymbol member, string doc, DocumentationFormatOptions options)
		{
			if (string.IsNullOrEmpty (doc))
				return null;
			System.IO.StringReader reader = new System.IO.StringReader ("<docroot>" + doc + "</docroot>");
			XmlTextReader xml = new XmlTextReader (reader);
			StringBuilder ret = new StringBuilder (70);
			StringBuilder parameterBuilder = new StringBuilder ();
			StringBuilder exceptions = new StringBuilder ();
			exceptions.AppendLine (options.FormatHeading (GettextCatalog.GetString ("Exceptions:")));
			//		ret.Append ("<small>");
			int paramCount = 0, exceptionCount = 0, summaryEnd = -1;
			try {
				xml.Read ();
				do {
					if (xml.NodeType == XmlNodeType.Element) {
						switch (xml.Name.ToLower ()) {
						case "para":
							ret.Append (options.FormatBody (ParseBody (member, xml, xml.Name, options)));
							if (summaryEnd < 0)
								summaryEnd = ret.Length;
							break;
						case "summary":
							var summary = options.FormatBody (ParseBody (member, xml, xml.Name, options));
							if (!IsEmptyDocumentation (summary)) {
								//							ret.AppendLine (GetHeading ("Summary:", options));
								ret.Append (summary);
								if (summaryEnd < 0)
									summaryEnd = ret.Length;
							}
							break;
						case "remarks":
							if (string.IsNullOrEmpty (options.HighlightParameter)) {
								ret.AppendLine (options.FormatHeading (GettextCatalog.GetString ("Remarks:")));
								ret.Append (options.FormatBody (ParseBody (member, xml, xml.Name, options)));
								if (summaryEnd < 0)
									summaryEnd = ret.Length;
							} else {
								options.FormatBody (ParseBody (member, xml, xml.Name, options));
							}
							break;
						// skip <example>-nodes
						case "example":
							xml.Skip ();
							xml.Skip ();
							break;
						case "exception":
							exceptionCount++;
							if (options.SmallText)
								exceptions.Append ("<small>");
							exceptions.Append ("<b>");
							exceptions.Append (EscapeText (xml ["cref"]));
							exceptions.Append (": ");
							exceptions.Append ("</b>");
							if (options.SmallText)
								exceptions.Append ("</small>");
							
							exceptions.AppendLine (options.FormatBody (ParseBody (member, xml, xml.Name, options)));
							break;
						case "returns":
							if (string.IsNullOrEmpty (options.HighlightParameter)) {
								ret.AppendLine (options.FormatHeading (GettextCatalog.GetString ("Returns:")));
								ret.Append (options.FormatBody (ParseBody (member, xml, xml.Name, options)));
							} else {
								options.FormatBody (ParseBody (member, xml, xml.Name, options));
							}
							break;
						case "param":
							string paramName = xml.GetAttribute ("name") != null ? xml ["name"].Trim () : "";
								
							var body = options.FormatBody (ParseBody (member, xml, xml.Name, options));
							if (!IsEmptyDocumentation (body)) {
								paramCount++;
								parameterBuilder.Append ("<i>");
								if (options.HighlightParameter == paramName)
									parameterBuilder.Append ("<b>");
								if (options.SmallText)
									parameterBuilder.Append ("<small>");
								parameterBuilder.Append (EscapeText (paramName));
								if (options.SmallText)
									parameterBuilder.Append ("</small>");
								if (options.HighlightParameter == paramName)
									parameterBuilder.Append ("</b>");
								parameterBuilder.Append (":</i> ");
								parameterBuilder.Append (body);
							} else {
								return null;
							}
							break;
						case "value":
							ret.AppendLine (options.FormatHeading (GettextCatalog.GetString ("Value:")));
							ret.AppendLine (options.FormatBody (ParseBody (member, xml, xml.Name, options)));
							break;
						case "seealso":
							if (string.IsNullOrEmpty (options.HighlightParameter)) {
								ret.Append (options.FormatHeading (GettextCatalog.GetString ("See also:")));
								ret.Append (" " + EscapeText (xml ["cref"] + xml ["langword"]));
							}
							break;
						}
					}
				} while (xml.Read ());
			
			} catch (Exception ex) {
				MonoDevelop.Core.LoggingService.LogError (ex.ToString ());
				return EscapeText (doc);
			}

			if (IsEmptyDocumentation (ret.ToString ()) && IsEmptyDocumentation (parameterBuilder.ToString ()))
				return EscapeText (doc);
			if (string.IsNullOrEmpty (options.HighlightParameter) && exceptionCount > 0)
				ret.Append (exceptions.ToString ());
			
			string result = ret.ToString ();
			if (summaryEnd < 0)
				summaryEnd = result.Length;
			if (paramCount > 0) {
				var paramSb = new StringBuilder ();
				if (result.Length > 0)
					paramSb.AppendLine ();/*
				paramSb.Append ("<small>");
				paramSb.AppendLine (options.FormatHeading (GettextCatalog.GetPluralString ("Parameter:", "Parameters:", paramCount)));
				paramSb.Append ("</small>");*/
				paramSb.Append (parameterBuilder.ToString ());
				result = result.Insert (summaryEnd, paramSb.ToString ());
			}
			result = result.Trim ();
			if (result.EndsWith (Environment.NewLine + "</small>"))
				result = result.Substring (0, result.Length - (Environment.NewLine + "</small>").Length) + "</small>";
			return result;
		}