예제 #1
0
        public static XrefDetails From(HtmlAgilityPack.HtmlNode node)
        {
            if (node.Name != "xref")
            {
                throw new NotSupportedException("Only xref node is supported!");
            }
            var xref = new XrefDetails();

            xref.Uid = node.GetAttributeValue("href", null);
            var overrideName = node.InnerText;

            if (!string.IsNullOrEmpty(overrideName))
            {
                xref.AnchorDisplayName    = overrideName;
                xref.PlainTextDisplayName = overrideName;
            }
            else
            {
                // If name | fullName exists, use the one from xref because spec name is different from name for generic types
                // e.g. return type: IEnumerable<T>, spec name should be IEnumerable
                xref.AnchorDisplayName    = node.GetAttributeValue("name", null);
                xref.PlainTextDisplayName = node.GetAttributeValue("fullName", null);
            }

            xref.Title = node.GetAttributeValue("title", null);
            xref.Raw   = node.GetAttributeValue("data-raw", null);
            xref.ThrowIfNotResolved = node.GetAttributeValue("data-throw-if-not-resolved", false);

            return(xref);
        }
예제 #2
0
        public static XrefDetails From(HtmlAgilityPack.HtmlNode node)
        {
            if (node.Name != "xref") throw new NotSupportedException("Only xref node is supported!");
            var xref = new XrefDetails();
            xref.Uid = node.GetAttributeValue("href", null);
            var overrideName = node.InnerText;
            if (!string.IsNullOrEmpty(overrideName))
            {
                xref.AnchorDisplayName = overrideName;
                xref.PlainTextDisplayName = overrideName;
            }
            else
            {
                // If name | fullName exists, use the one from xref because spec name is different from name for generic types
                // e.g. return type: IEnumerable<T>, spec name should be IEnumerable
                xref.AnchorDisplayName = node.GetAttributeValue("name", null);
                xref.PlainTextDisplayName = node.GetAttributeValue("fullName", null);
            }

            xref.Title = node.GetAttributeValue("title", null);
            xref.Raw = node.GetAttributeValue("data-raw", null);
            xref.ThrowIfNotResolved = node.GetAttributeValue("data-throw-if-not-resolved", false);

            return xref;
        }
예제 #3
0
        private static void UpdateXref(HtmlAgilityPack.HtmlNode node, IDocumentBuildContext context, string language)
        {
            var xref = XrefDetails.From(node);

            // Resolve external xref map first, and then internal xref map.
            // Internal one overrides external one
            var xrefSpec = context.GetXrefSpec(xref.Uid);

            xref.ApplyXrefSpec(xrefSpec);
            bool resolved = xrefSpec != null;

            var convertedNode = xref.ConvertToHtmlNode(language);

            node.ParentNode.ReplaceChild(convertedNode, node);
            if (!resolved)
            {
                if (xref.ThrowIfNotResolved)
                {
                    throw new CrossReferenceNotResolvedException(xref.Uid, xref.Raw, null);
                }
            }
        }