Skip to content

Commit

Permalink
refactor pathing to allow member documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed Jul 1, 2024
1 parent 1c5751d commit 700fe7b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
37 changes: 29 additions & 8 deletions src/Doki.Output.Markdown/InternalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down Expand Up @@ -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<string> GetPathList(DocumentationObject documentationObject)
{
var pathParts = new List<string>();

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)
Expand All @@ -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);

Check warning on line 192 in src/Doki.Output.Markdown/InternalExtensions.cs

View workflow job for this annotation

GitHub Actions / Test

Possible null reference argument for parameter 'documentationObject' in 'List<string> InternalExtensions.GetPathList(DocumentationObject documentationObject)'.

Check warning on line 192 in src/Doki.Output.Markdown/InternalExtensions.cs

View workflow job for this annotation

GitHub Actions / Test

Possible null reference argument for parameter 'documentationObject' in 'List<string> InternalExtensions.GetPathList(DocumentationObject documentationObject)'.

parentPathList.Add(memberDocumentation.GetPathId());

return parentPathList.CombineToPath();
}

var pathList = GetPathList(documentationObject);

return pathList.CombineToPath();
}

public static string CombineToPath(this ICollection<string> parts)
Expand Down
4 changes: 3 additions & 1 deletion src/Doki.Output.Markdown/MarkdownBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public static void AddHeadingWithMemberTable<T>(this MarkdownBuilder markdown, s
{
text.Append(markdown.BuildText(summary));
}


// var link = markdown.BuildLinkTo(item);

table.AddRow(new Text(item.Name), text);
}

Expand Down

0 comments on commit 700fe7b

Please sign in to comment.