From 700fe7b4a4babfaab6b9d04ca563b2cec34fc434 Mon Sep 17 00:00:00 2001 From: dvolper Date: Mon, 1 Jul 2024 19:50:56 +0200 Subject: [PATCH] refactor pathing to allow member documentation --- .../InternalExtensions.cs | 37 +++++++++++++++---- .../MarkdownBuilderExtensions.cs | 4 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/Doki.Output.Markdown/InternalExtensions.cs b/src/Doki.Output.Markdown/InternalExtensions.cs index b2f558c..8767ba1 100644 --- a/src/Doki.Output.Markdown/InternalExtensions.cs +++ b/src/Doki.Output.Markdown/InternalExtensions.cs @@ -100,7 +100,7 @@ public static Element BuildLinkTo(this MarkdownBuilder builder, DocumentationObj } else { - relativePath = builder.BuildRelativePath(to) + ".md"; + relativePath = builder.BuildRelativePath(to, "README.md"); } break; @@ -111,7 +111,7 @@ public static Element BuildLinkTo(this MarkdownBuilder builder, DocumentationObj asText = !memberDocumentation.IsDocumented; - relativePath = builder.BuildRelativePath(memberDocumentation.Parent!) + ".md"; + relativePath = builder.BuildRelativePath(memberDocumentation) + ".md"; break; } default: @@ -151,21 +151,26 @@ public static Element BuildLinkTo(this MarkdownBuilder builder, DocumentationObj return container; } - public static string GetPath(this DocumentationObject element) + private static string GetPathId(this DocumentationObject documentationObject) + { + return documentationObject.Id.Replace('`', '_'); + } + + private static List GetPathList(DocumentationObject documentationObject) { var pathParts = new List(); - var current = element; - if (element is TypeDocumentationReference typeDocumentationReference) + var current = documentationObject; + if (documentationObject is TypeDocumentationReference typeDocumentationReference) { // We cannot use TryGetParent because it will return the wrong namespace/assembly for base type references coming from a different namespace/assembly. if (typeDocumentationReference.Assembly != null) pathParts.Add(typeDocumentationReference.Assembly); if (typeDocumentationReference.Namespace != null) pathParts.Add(typeDocumentationReference.Namespace); - pathParts.Add(typeDocumentationReference.Id.Replace('`', '_')); + pathParts.Add(typeDocumentationReference.GetPathId()); - return pathParts.CombineToPath(); + return pathParts; } while (current.Parent != null) @@ -177,7 +182,23 @@ public static string GetPath(this DocumentationObject element) pathParts.Reverse(); - return pathParts.CombineToPath(); + return pathParts; + } + + public static string GetPath(this DocumentationObject documentationObject) + { + if (documentationObject is MemberDocumentation { Parent: not null } memberDocumentation) + { + var parentPathList = GetPathList(memberDocumentation.Parent); + + parentPathList.Add(memberDocumentation.GetPathId()); + + return parentPathList.CombineToPath(); + } + + var pathList = GetPathList(documentationObject); + + return pathList.CombineToPath(); } public static string CombineToPath(this ICollection parts) diff --git a/src/Doki.Output.Markdown/MarkdownBuilderExtensions.cs b/src/Doki.Output.Markdown/MarkdownBuilderExtensions.cs index 3d2afe0..e4d371b 100644 --- a/src/Doki.Output.Markdown/MarkdownBuilderExtensions.cs +++ b/src/Doki.Output.Markdown/MarkdownBuilderExtensions.cs @@ -72,7 +72,9 @@ public static void AddHeadingWithMemberTable(this MarkdownBuilder markdown, s { text.Append(markdown.BuildText(summary)); } - + + // var link = markdown.BuildLinkTo(item); + table.AddRow(new Text(item.Name), text); }