public void ReportExternalXRefSpec(XRefSpec spec) { ExternalXRefSpec.AddOrUpdate( spec.Uid, spec, (uid, old) => old + spec); }
private static XRefSpec GetXRefSpecFromReference(ReferenceViewModel item) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = item.Href, CommentId = item.CommentId, }; if (item.NameInDevLangs.Count > 0) { foreach (var pair in item.NameInDevLangs) { result["name." + pair.Key] = pair.Value; } } if (!string.IsNullOrEmpty(item.FullName)) { result["fullName"] = item.FullName; } if (item.FullNameInDevLangs.Count > 0) { foreach (var pair in item.FullNameInDevLangs) { result["fullName." + pair.Key] = pair.Value; } } if (!string.IsNullOrEmpty(item.NameWithType)) { result["nameWithType"] = item.NameWithType; } if (item.NameWithTypeInDevLangs.Count > 0) { foreach (var pair in item.NameWithTypeInDevLangs) { result["nameWithType." + pair.Key] = pair.Value; } } if (item.Additional != null) { foreach (var pair in item.Additional) { var s = pair.Value as string; if (s != null) { result[pair.Key] = s; } } } return(result); }
private static IEnumerable <XRefSpec> GetXRefInfo(ItemViewModel item, string key, List <ReferenceViewModel> references) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = ((RelativePath)key).UrlEncode().ToString(), CommentId = item.CommentId, }; if (item.Names.Count > 0) { foreach (var pair in item.Names) { result["name." + pair.Key] = pair.Value; } } if (!string.IsNullOrEmpty(item.FullName)) { result["fullName"] = item.FullName; } if (item.FullNames.Count > 0) { foreach (var pair in item.FullNames) { result["fullName." + pair.Key] = pair.Value; } } if (!string.IsNullOrEmpty(item.NameWithType)) { result["nameWithType"] = item.NameWithType; } if (item.NamesWithType.Count > 0) { foreach (var pair in item.NamesWithType) { result["nameWithType." + pair.Key] = pair.Value; } } yield return(result); // generate overload xref spec. if (item.Overload != null) { var reference = references.Find(r => r.Uid == item.Overload); if (reference != null) { yield return(GetXRefInfo(reference, key)); } } }
public static XRefSpecObject ToXRefSpecObject(this XRefSpec spec) { if (spec == null) { throw new ArgumentNullException(nameof(spec)); } return(new XRefSpecObject { HashedUid = MD5Encryption.CalculateMD5Hash(spec.Uid), Uid = spec.Uid, XRefSpecJson = spec.ToJsonString(), }); }
public object Interpret(BaseSchema schema, object value, IProcessContext context, string path) { if (value == null || !CanInterpret(schema)) { return(value); } if (!(JsonPointer.GetChild(value, "uid") is string uid)) { // schema validation threw error when uid is required, so here when uid is null, it must be optional, which is allowed return(value); } if (string.IsNullOrEmpty(uid)) { Logger.LogWarning($"Invalid xrefProperties for /{path}: empty uid is not allowed."); return(value); } var xrefSpec = new XRefSpec { Uid = uid }; var parts = schema.XrefProperties ?? new List <string> { "name", "fullName" }; var root = context.GetModel <object>(); foreach (var part in parts.Distinct()) { var jsonPointer = new JsonPointer(path + "/" + part); var property = jsonPointer.GetValue(root); if (property != null) { xrefSpec[part] = property; } } if (IsInternalXrefSpec(schema)) { context.Uids.Add(new UidDefinition(uid, context.OriginalFileAndType.FullPath, path: path + "/uid")); xrefSpec.Href = ((RelativePath)context.OriginalFileAndType.File).GetPathFromWorkingFolder().UrlEncode().ToString(); context.XRefSpecs.Add(xrefSpec); } else { context.ExternalXRefSpecs.Add(xrefSpec); } return(value); }
public IActionResult Create([FromBody] XRefSpec spec) { if (spec == null) { return(BadRequest()); } _db.XRefSpecObjects.Add(new XRefSpecObject { HashedUid = MD5Encryption.CalculateMD5Hash(spec.Uid), Uid = spec.Uid, XRefSpecJson = JsonUtility.Serialize(spec) }); _db.SaveChanges(); return(Ok()); }
private static IEnumerable <XRefSpec> GetXRefInfo(ItemViewModel item, string key) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = key, CommentId = item.CommentId, }; if (!string.IsNullOrEmpty(item.NameForCSharp)) { result["name.csharp"] = item.NameForCSharp; } if (!string.IsNullOrEmpty(item.NameForVB)) { result["name.vb"] = item.NameForVB; } if (!string.IsNullOrEmpty(item.FullName)) { result["fullName"] = item.FullName; } if (!string.IsNullOrEmpty(item.FullNameForCSharp)) { result["fullName.csharp"] = item.FullNameForCSharp; } if (!string.IsNullOrEmpty(item.FullNameForVB)) { result["fullName.vb"] = item.FullNameForVB; } yield return(result); // generate overload xref spec. if (item.Type != null) { switch (item.Type.Value) { case MemberType.Property: case MemberType.Constructor: case MemberType.Method: case MemberType.Operator: yield return(GenerateOverloadXrefSpec(item, key)); break; default: break; } } }
public async Task <IHttpActionResult> GetByUid(string uid) { uidt ut = await db.uidts.Where(b => b.uid == uid) .Select(c => c) .FirstOrDefaultAsync(); if (ut == null) { return(NotFound()); } XRefSpec xf = Newtonsoft.Json.JsonConvert.DeserializeObject <XRefSpec>(ut.objectStr); return(Ok(xf)); }
public void ApplyXrefSpec(XRefSpec spec) { if (spec == null) { return; } // TODO: What if href is not html? if (!string.IsNullOrEmpty(spec.Href)) { var href = UriUtility.MergeHref(spec.Href, Query + Anchor); (Href, Query, Anchor) = UriUtility.Split(href); } Spec = spec; }
// TODO: use this method instead of directly accessing UidMap public void RegisterInternalXrefSpec(XRefSpec xrefSpec) { if (xrefSpec == null) { throw new ArgumentNullException(nameof(xrefSpec)); } if (string.IsNullOrEmpty(xrefSpec.Href)) { throw new ArgumentException("Href for xref spec must contain value"); } if (!PathUtility.IsRelativePath(xrefSpec.Href)) { throw new ArgumentException("Only relative href path is supported"); } XRefSpecMap[xrefSpec.Uid] = xrefSpec; }
private static XRefSpec GetXRefInfo(DataContracts.Common.ReferenceViewModel item, string key) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = key, CommentId = item.CommentId, }; string name; if (item.NameInDevLangs.TryGetValue("csharp", out name)) { result["name.csharp"] = name; } if (item.NameInDevLangs.TryGetValue("vb", out name)) { result["name.vb"] = name; } if (!string.IsNullOrEmpty(item.FullName)) { result["fullName"] = item.FullName; } if (item.FullNameInDevLangs.TryGetValue("csharp", out name)) { result["fullName.csharp"] = name; } if (item.FullNameInDevLangs.TryGetValue("vb", out name)) { result["fullName.vb"] = name; } if (!string.IsNullOrEmpty(item.NameWithType)) { result["nameWithType"] = item.NameWithType; } if (item.NameWithTypeInDevLangs.TryGetValue("csharp", out name)) { result["nameWithType.csharp"] = name; } if (item.NameWithTypeInDevLangs.TryGetValue("vb", out name)) { result["nameWithType.vb"] = name; } return(result); }
private async Task <List <XRefSpec> > GetXRefSpecAsync(ClassEntry entry) { var result = new List <XRefSpec>(entry.Items.Count); var type = entry.Items.Find(item => item.Uid == entry.EntryName); XRefSpec typeSpec = null; if (type != null) { typeSpec = await GetXRefSpecAsync(type); if (typeSpec != null) { result.Add(typeSpec); } } int size = 0; foreach (var specsTask in from block in (from item in entry.Items where item != type select item).BlockBuffer(() => size = size * 2 + 1) select Task.WhenAll(from item in block select GetXRefSpecAsync(item))) { result.AddRange(from s in await specsTask where s != null select s); } result.AddRange(await GetOverloadXRefSpecAsync(result)); if (typeSpec != null && typeSpec.Href != null) { // handle enum field, or other one-page-member foreach (var item in result) { if (item.Href == null) { item.Href = typeSpec.Href; } } } else { result.RemoveAll(item => item.Href == null); } result.Sort(XRefSpecUidComparer.Instance); return(result); }
public void ApplyXrefSpec(XRefSpec spec) { if (spec == null) { return; } // TODO: What if href is not html? if (!string.IsNullOrEmpty(spec.Href)) { Href = UriUtility.GetNonFragment(spec.Href); if (string.IsNullOrEmpty(Anchor)) { Anchor = UriUtility.GetFragment(spec.Href); } } Spec = spec; }
public static bool TryGetStringValue(this XRefSpec spec, string key, out string value) { if (spec.TryGetValue(key, out var objValue) && objValue != null) { if (objValue is string) { value = (string)objValue; return(true); } else { Logger.LogWarning( $"The value of property '{key}' in uid '{spec.Uid}' is not string", code: WarningCodes.Build.ReferencedXrefPropertyNotString); } } value = null; return(false); }
private static CommentIdAndUid GetOverloadIdBody(XRefSpec pair) { switch (pair.CommentId[0]) { case 'M': case 'P': var body = pair.Uid; var index = body.IndexOf('('); if (index != -1) { body = body.Remove(index); } body = GenericMethodPostFix.Replace(body, string.Empty); return(new CommentIdAndUid("Overload:" + body, body + "*")); default: return(null); } }
public void ApplyXrefSpec(XRefSpec spec) { if (spec == null) { return; } var href = spec.Href; if (PathUtility.IsRelativePath(href)) { if (string.IsNullOrEmpty(Anchor)) { // TODO: hashtag from tempalte // TODO: What if href is not html? Anchor = "#" + GetHtmlId(Uid); } } Href = HttpUtility.UrlDecode(href); Spec = spec; }
public void TestXrefWithTemplate() { var xrefTmpl = CreateFile("partials/xref.html.tmpl", @"<h2>{{uid}}</h2><p>{{summary}}</p>", _templateFolder); var tmpl = CreateFile("index.html.tmpl", @" <xref uid=""{{reference}}"" template=""partials/xref.html.tmpl"" /> ", _templateFolder); var xref = new XRefSpec { Uid = "reference", Href = "ref.html", ["summary"] = "hello world" }; var output = Process("index", "input", new { reference = "reference" }, xref); Assert.Equal($"{_outputFolder}/input.html".ToNormalizedFullPath(), output.OutputFiles[".html"].RelativePath.ToNormalizedPath()); Assert.Equal(@" <h2>reference</h2><p>hello world</p> ", File.ReadAllText(Path.Combine(_outputFolder, "input.html"))); }
private static IEnumerable <XRefSpec> GetXRefInfo(ItemViewModel item, string key, List <DataContracts.Common.ReferenceViewModel> references) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = key, }; if (!string.IsNullOrEmpty(item.FullName)) { result["fullName"] = item.FullName; } if (!string.IsNullOrEmpty(item.NameWithType)) { result["nameWithType"] = item.NameWithType; } yield return(result); }
private async Task <List <XRefSpec> > ResolveCoreAsync(string url) { using (var stream = await _client.GetStreamAsync(url)) using (var sr = new StreamReader(stream)) { var xsList = JsonUtility.Deserialize <List <Dictionary <string, object> > >(sr); return(xsList.ConvertAll(item => { var spec = new XRefSpec(); foreach (var pair in item) { if (pair.Value is string s) { spec[pair.Key] = s; } } return spec; })); } }
internal async Task <IList <XRefSpec> > QueryByHttpRequestAsync(HttpClient client, string requestUrl, string uid) { string url = requestUrl.Replace("{uid}", Uri.EscapeDataString(uid)); try { var data = await client.GetStreamAsync(url); using (var sr = new StreamReader(data)) { var xsList = JsonUtility.Deserialize <List <Dictionary <string, object> > >(sr); return(xsList.ConvertAll(item => { var spec = new XRefSpec(); foreach (var pair in item) { if (pair.Value is string s) { spec[pair.Key] = s; } } return spec; })); } } catch (HttpRequestException e) { Logger.LogWarning($"Error occurs when resolve {uid} from {requestUrl}.{e.InnerException.Message}"); return(null); } catch (Newtonsoft.Json.JsonReaderException e) { Logger.LogWarning($"Response from {requestUrl} is not in valid JSON format.{e.Message}"); return(null); } catch (Exception e) { Logger.LogWarning($"Error occurs when resolve {uid} from {requestUrl}.{e.Message}"); return(null); } }
private static XRefSpec GetXRefInfo(ReferenceViewModel item, string key) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = ((RelativePath)key).UrlEncode().ToString(), CommentId = item.CommentId, }; if (item.NameInDevLangs.Count > 0) { foreach (var pair in item.NameInDevLangs) { result["name." + pair.Key] = pair.Value; } } if (!string.IsNullOrEmpty(item.FullName)) { result["fullName"] = item.FullName; } if (item.FullNameInDevLangs.Count > 0) { foreach (var pair in item.FullNameInDevLangs) { result["fullName." + pair.Key] = pair.Value; } } if (!string.IsNullOrEmpty(item.NameWithType)) { result["nameWithType"] = item.NameWithType; } if (item.NameWithTypeInDevLangs.Count > 0) { foreach (var pair in item.NameWithTypeInDevLangs) { result["nameWithType." + pair.Key] = pair.Value; } } return(result); }
private (bool resolved, bool warn) UpdateXref(HtmlNode node, IDocumentBuildContext context, string language, out XRefDetails xref) { xref = XRefDetails.From(node); XRefSpec xrefSpec = null; if (!string.IsNullOrEmpty(xref.Uid)) { // Resolve external xref map first, and then internal xref map. // Internal one overrides external one xrefSpec = context.GetXrefSpec(HttpUtility.HtmlDecode(xref.Uid)); xref.ApplyXrefSpec(xrefSpec); } var renderer = xref.TemplatePath == null ? null : _rendererLoader.Load(xref.TemplatePath); var(convertedNode, resolved) = xref.ConvertToHtmlNode(language, renderer); node.ParentNode.ReplaceChild(convertedNode, node); var warn = xrefSpec == null && xref.ThrowIfNotResolved; return(resolved, warn); }
public void ApplyXrefSpec(XRefSpec spec) { if (spec == null) { return; } var href = spec.Href; if (PathUtility.IsRelativePath(href)) { var hashtagIndex = href.IndexOf('#'); if (hashtagIndex == -1) { // TODO: hashtag from tempalte var htmlId = GetHtmlId(Uid); // TODO: What if href is not html? href = href + "#" + htmlId; } } Href = href; Spec = spec; }
private static bool UpdateXref(HtmlNode node, IDocumentBuildContext context, string language, out XRefDetails xref) { xref = XRefDetails.From(node); XRefSpec xrefSpec = null; if (!string.IsNullOrEmpty(xref.Uid)) { // Resolve external xref map first, and then internal xref map. // Internal one overrides external one xrefSpec = context.GetXrefSpec(HttpUtility.HtmlDecode(xref.Uid)); xref.ApplyXrefSpec(xrefSpec); } var convertedNode = xref.ConvertToHtmlNode(language); node.ParentNode.ReplaceChild(convertedNode, node); if (xrefSpec == null && xref.ThrowIfNotResolved == true) { return(false); } return(true); }
// TODO: use this method instead of directly accessing UidMap public void RegisterInternalXrefSpec(XRefSpec xrefSpec) { if (xrefSpec == null) { throw new ArgumentNullException(nameof(xrefSpec)); } if (string.IsNullOrEmpty(xrefSpec.Href)) { throw new ArgumentException("Href for xref spec must contain value"); } if (!PathUtility.IsRelativePath(xrefSpec.Href)) { throw new ArgumentException("Only relative href path is supported"); } XRefSpecMap.AddOrUpdate( xrefSpec.Uid, xrefSpec, (_, old) => { Logger.LogWarning($"Uid({xrefSpec.Uid}) has already been defined in {((RelativePath)old.Href).RemoveWorkingFolder()}.", code: WarningCodes.Build.DuplicateUids); return(FilePathComparer.OSPlatformSensitiveStringComparer.Compare(old.Href, xrefSpec.Href) > 0 ? xrefSpec : old); }); }
private static IEnumerable <XRefSpec> GetXRefInfo(ItemViewModel item, string key, List <DataContracts.ReferenceViewModel> references) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = key, }; //additional properties /* * if (!string.IsNullOrEmpty(item.FullName)) * { * result["fullName"] = item.FullName; * } * if (!string.IsNullOrEmpty(item.NameWithType)) * { * result["nameWithType"] = item.NameWithType; * } */ yield return(result); }
private IEnumerable<XRefSpec> GetXRefFromReference(PageViewModel vm) { if (vm.References == null) { yield break; } foreach (var reference in vm.References) { if (reference != null && reference.IsExternal != false) { var dict = YamlUtility.ConvertTo<Dictionary<string, object>>(reference); if (dict != null) { var spec = new XRefSpec(); foreach (var pair in dict) { var s = pair.Value as string; if (s != null) { spec[pair.Key] = s; } } yield return spec; } } } }
private static CommentIdAndUid GetOverloadIdBody(XRefSpec pair) { switch (pair.CommentId[0]) { case 'M': case 'P': var body = pair.Uid; var index = body.IndexOf('('); if (index != -1) { body = body.Remove(index); } body = GenericMethodPostFix.Replace(body, string.Empty); return new CommentIdAndUid("Overload:" + body, body + "*"); default: return null; } }
// TODO: use this method instead of directly accessing UidMap public void RegisterInternalXrefSpec(XRefSpec xrefSpec) { if (xrefSpec == null) throw new ArgumentNullException(nameof(xrefSpec)); if (string.IsNullOrEmpty(xrefSpec.Href)) throw new ArgumentException("Href for xref spec must contain value"); if (!TypeForwardedToPathUtility.IsRelativePath(xrefSpec.Href)) throw new ArgumentException("Only relative href path is supported"); XRefSpecMap[xrefSpec.Uid] = xrefSpec; }
private static string GetLanguageSpecificAttribute(XRefSpec spec, string language, string defaultValue, params string[] keyInFallbackOrder) { if (keyInFallbackOrder == null || keyInFallbackOrder.Length == 0) throw new ArgumentException("key must be provided!", nameof(keyInFallbackOrder)); string suffix = string.Empty; if (!string.IsNullOrEmpty(language)) suffix = "." + language; foreach(var key in keyInFallbackOrder) { string value; var keyWithSuffix = key + suffix; if (spec.TryGetValue(keyWithSuffix, out value)) { return value; } if (spec.TryGetValue(key, out value)) { return value; } } return defaultValue; }
private ManifestItem Process(string documentType, string fileName, object content, XRefSpec spec) { var reader = new LocalFileResourceReader(_templateFolder); var context = new DocumentBuildContext(_outputFolder); context.RegisterInternalXrefSpec(spec); var processor = new TemplateProcessor(reader, context, 64); var inputItem = new InternalManifestItem { DocumentType = documentType, Extension = "html", FileWithoutExtension = Path.GetFullPath(Path.Combine(_outputFolder, Path.GetFileNameWithoutExtension(fileName))), LocalPathFromRoot = fileName, Model = new ModelWithCache(content), }; return(processor.Process(new List <InternalManifestItem> { inputItem }, new ApplyTemplateSettings(_inputFolder, _outputFolder))[0]); }
private static IEnumerable<XRefSpec> GetXRefInfo(ItemViewModel item, string key, List<DataContracts.Common.ReferenceViewModel> references) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = key, CommentId = item.CommentId, }; if (!string.IsNullOrEmpty(item.NameForCSharp)) { result["name.csharp"] = item.NameForCSharp; } if (!string.IsNullOrEmpty(item.NameForVB)) { result["name.vb"] = item.NameForVB; } if (!string.IsNullOrEmpty(item.FullName)) { result["fullName"] = item.FullName; } if (!string.IsNullOrEmpty(item.FullNameForCSharp)) { result["fullName.csharp"] = item.FullNameForCSharp; } if (!string.IsNullOrEmpty(item.FullNameForVB)) { result["fullName.vb"] = item.FullNameForVB; } if (!string.IsNullOrEmpty(item.NameWithType)) { result["nameWithType"] = item.NameWithType; } if (!string.IsNullOrEmpty(item.NameWithTypeForCSharp)) { result["nameWithType.csharp"] = item.NameWithTypeForCSharp; } if (!string.IsNullOrEmpty(item.NameWithTypeForVB)) { result["nameWithType.vb"] = item.NameWithTypeForVB; } yield return result; // generate overload xref spec. if (item.Overload != null) { var reference = references.Find(r => r.Uid == item.Overload); if (reference != null) { yield return GetXRefInfo(reference, key); } } }
private static XRefSpec GetXRefInfo(DataContracts.Common.ReferenceViewModel item, string key) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = key, CommentId = item.CommentId, }; string name; if (item.NameInDevLangs.TryGetValue("csharp", out name)) { result["name.csharp"] = name; } if (item.NameInDevLangs.TryGetValue("vb", out name)) { result["name.vb"] = name; } if (!string.IsNullOrEmpty(item.FullName)) { result["fullName"] = item.FullName; } if (item.FullNameInDevLangs.TryGetValue("csharp", out name)) { result["fullName.csharp"] = name; } if (item.FullNameInDevLangs.TryGetValue("vb", out name)) { result["fullName.vb"] = name; } if (!string.IsNullOrEmpty(item.NameWithType)) { result["nameWithType"] = item.NameWithType; } if (item.NameWithTypeInDevLangs.TryGetValue("csharp", out name)) { result["nameWithType.csharp"] = name; } if (item.NameWithTypeInDevLangs.TryGetValue("vb", out name)) { result["nameWithType.vb"] = name; } return result; }
/// <summary> /// Work around, remove when overload is ready in yaml file. /// </summary> private static XRefSpec GenerateOverloadXrefSpec(ItemViewModel item, string key) { var uidBody = item.Uid; { var index = uidBody.IndexOf('('); if (index != -1) { uidBody = uidBody.Remove(index); } } uidBody = System.Text.RegularExpressions.Regex.Replace(uidBody, @"``\d+$", string.Empty); var result = new XRefSpec { Uid = uidBody + "*", Href = key, CommentId = "Overload:" + uidBody, }; { if (!string.IsNullOrEmpty(item.Name)) { var index = item.Name.IndexOfAny(new char[] { '(', '[' }); if (index != -1) { result.Name = item.Name.Remove(index); } else { result.Name = item.Name; } } } if (!string.IsNullOrEmpty(item.NameForCSharp)) { var index = item.NameForCSharp.IndexOfAny(new char[] { '(', '[' }); if (index != -1) { result["name.csharp"] = item.NameForCSharp.Remove(index); } else { result["name.csharp"] = item.NameForCSharp; } } if (!string.IsNullOrEmpty(item.NameForVB)) { var index = item.NameForVB.IndexOfAny(new char[] { '(', '[' }); if (index != -1) { result["name.vb"] = item.NameForVB.Remove(index); } else { result["name.vb"] = item.NameForVB; } } if (!string.IsNullOrEmpty(item.FullName)) { var index = item.FullName.IndexOfAny(new char[] { '(', '[' }); if (index != -1) { result["fullName"] = item.FullName.Remove(index); } else { result["fullName"] = item.FullName; } result["fullName"] = item.FullName; } if (!string.IsNullOrEmpty(item.FullNameForCSharp)) { var index = item.FullNameForCSharp.IndexOfAny(new char[] { '(', '[' }); if (index != -1) { result["fullName.csharp"] = item.FullNameForCSharp.Remove(index); } else { result["fullName.csharp"] = item.FullNameForCSharp; } } if (!string.IsNullOrEmpty(item.FullNameForVB)) { var index = item.FullNameForVB.IndexOfAny(new char[] { '(', '[' }); if (index != -1) { result["fullName.vb"] = item.FullNameForVB.Remove(index); } else { result["fullName.vb"] = item.FullNameForVB; } } return(result); }
private static XRefSpec GetXRefInfo(ItemViewModel item, string href) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = ((RelativePath)href).GetPathFromWorkingFolder(), }; if (!string.IsNullOrEmpty(item.NameForCSharp)) { result["name.csharp"] = item.NameForCSharp; } if (!string.IsNullOrEmpty(item.NameForVB)) { result["name.vb"] = item.NameForVB; } if (!string.IsNullOrEmpty(item.FullName)) { result["fullName"] = item.FullName; } if (!string.IsNullOrEmpty(item.FullNameForCSharp)) { result["fullName.csharp"] = item.FullNameForCSharp; } if (!string.IsNullOrEmpty(item.FullNameForVB)) { result["fullName.vb"] = item.FullNameForVB; } return result; }
private static void UpdateXref(HtmlAgilityPack.HtmlNode xref, Dictionary <string, XRefSpec> internalXRefMap, Dictionary <string, XRefSpec> externalXRefMap, Func <string, string> updater, string language) { var key = xref.GetAttributeValue("href", null); // 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 var name = xref.GetAttributeValue("name", null); var fullName = xref.GetAttributeValue("fullName", null); string displayName; string href = null; XRefSpec spec = null; if (internalXRefMap.TryGetValue(key, out spec)) { href = updater(spec.Href); var hashtagIndex = href.IndexOf('#'); if (hashtagIndex == -1) { var htmlId = GetHtmlId(key); // TODO: What if href is not html? href = href + "#" + htmlId; } } else if (externalXRefMap.TryGetValue(key, out spec) && !string.IsNullOrEmpty(spec.Href)) { href = spec.Href; } // If href is not null, use name if (href != null) { if (!string.IsNullOrEmpty(name)) { displayName = name; } else { displayName = string.IsNullOrEmpty(fullName) ? key : fullName; if (spec != null) { displayName = StringHelper.HtmlEncode(GetLanguageSpecificAttribute(spec, language, displayName, "name")); } } var anchorNode = $"<a class=\"xref\" href=\"{href}\">{displayName}</a>"; xref.ParentNode.ReplaceChild(HtmlAgilityPack.HtmlNode.CreateNode(anchorNode), xref); } else { // If href is null, use fullName if (!string.IsNullOrEmpty(fullName)) { displayName = fullName; } else { displayName = string.IsNullOrEmpty(name) ? key : name; if (spec != null) { displayName = StringHelper.HtmlEncode(GetLanguageSpecificAttribute(spec, language, displayName, "fullName", "name")); } } var spanNode = $"<span class=\"xref\">{displayName}</span>"; xref.ParentNode.ReplaceChild(HtmlAgilityPack.HtmlNode.CreateNode(spanNode), xref); } }