Пример #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();

            var rawUid = node.GetAttributeValue("href", null);

            if (!string.IsNullOrEmpty(rawUid))
            {
                var anchorIndex = rawUid.IndexOf("#");
                if (anchorIndex == -1)
                {
                    xref.Anchor = string.Empty;
                    xref.Uid    = HttpUtility.UrlDecode(rawUid);
                }
                else
                {
                    xref.Anchor = rawUid.Substring(anchorIndex);
                    xref.Uid    = HttpUtility.UrlDecode(rawUid.Remove(anchorIndex));
                }
            }

            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);

            // Both `data-raw-html` and `data-raw` are html encoded. Use `data-raw-html` with higher priority.
            // `data-raw-html` will be decoded then displayed, while `data-raw` will be displayed directly.
            var raw = node.GetAttributeValue("data-raw-html", null);

            if (!string.IsNullOrEmpty(raw))
            {
                xref.Raw = StringHelper.HtmlDecode(raw);
            }
            else
            {
                xref.Raw = node.GetAttributeValue("data-raw", null);
            }

            xref.ThrowIfNotResolved = node.GetAttributeValue("data-throw-if-not-resolved", false);

            return(xref);
        }
Пример #2
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);

            var convertedNode = xref.ConvertToHtmlNode(language);

            node.ParentNode.ReplaceChild(convertedNode, node);
            if (xrefSpec == null)
            {
                if (xref.ThrowIfNotResolved)
                {
                    throw new CrossReferenceNotResolvedException(xref.Uid, xref.Raw, null);
                }
            }
        }
Пример #3
0
        private static void TransformXrefLink(HtmlAgilityPack.HtmlNode node, IDocumentBuildContext context)
        {
            var convertedNode = XrefDetails.ConvertXrefLinkNodeToXrefNode(node);

            node.ParentNode.ReplaceChild(convertedNode, node);
        }