Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Elastic.Markdown/Myst/Directives/ImageBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private void ExtractImageUrl(ParserContext context)

ImageUrl = DiagnosticLinkInlineParser.UpdateRelativeUrl(context, imageUrl);


var file = DiagnosticLinkInlineParser.ResolveFile(context, imageUrl);
if (file.Exists)
Found = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,25 @@ public static string UpdateRelativeUrl(ParserContext context, string url)

// if we are trying to resolve a relative url from a _snippet folder ensure we eat the _snippet folder
// as it's not part of url by chopping of the extra parent navigation
if (newUrl.StartsWith("../") && context.DocumentationFileLookup(context.MarkdownSourcePath) is SnippetFile)
newUrl = url[3..];
if (newUrl.StartsWith("../") && context.DocumentationFileLookup(context.MarkdownSourcePath) is SnippetFile snippet)
{
//figure out how many nested folders inside `_snippets` we need to ignore.
var d = snippet.SourceFile.Directory;
var offset = 0;
while (d is not null && d.Name != "_snippets")
{
d = d.Parent;
if (d is not null && d.Name != "_snippets")
offset++;
}

//Because we ignore these folders in the url structure we need to eat the relative paths
while (offset >= 0 && newUrl.StartsWith("../"))
{
newUrl = newUrl[3..];
offset--;
}
}

// TODO check through context.DocumentationFileLookup if file is index vs "index.md" check
var markdownPath = context.MarkdownSourcePath;
Expand Down
Loading