Skip to content

Commit a590bb2

Browse files
committed
Fix img src url
1 parent 7baf876 commit a590bb2

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
// This file is licensed under the BSD-Clause 2 license.
66
// See the license.txt file in the project root for more information.
77

8+
using System.IO.Abstractions;
89
using Elastic.Markdown.Diagnostics;
910
using Elastic.Markdown.Myst.CodeBlocks;
1011
using Elastic.Markdown.Myst.FrontMatter;
1112
using Elastic.Markdown.Myst.Settings;
1213
using Elastic.Markdown.Myst.Substitution;
1314
using Elastic.Markdown.Slices.Directives;
1415
using Markdig;
16+
using Markdig.Parsers;
1517
using Markdig.Renderers;
1618
using Markdig.Renderers.Html;
1719
using Markdig.Syntax;
@@ -83,13 +85,28 @@ protected override void Write(HtmlRenderer renderer, DirectiveBlock directiveBlo
8385
}
8486
}
8587

88+
private static string GetRootRelativePath(ParserContext context, IFileInfo file)
89+
{
90+
var docsetDirectory = context.Configuration.SourceFile.Directory;
91+
return file.FullName.Replace(docsetDirectory!.FullName, string.Empty);
92+
}
93+
8694
private void WriteImage(HtmlRenderer renderer, ImageBlock block)
8795
{
88-
var imageUrl =
89-
block.ImageUrl != null &&
90-
(block.ImageUrl.StartsWith("/_static") || block.ImageUrl.StartsWith("_static"))
91-
? $"{block.Build.UrlPathPrefix}/{block.ImageUrl.TrimStart('/')}"
92-
: block.ImageUrl;
96+
string imageUrl;
97+
98+
if (block.ImageUrl != null)
99+
{
100+
if (block.ImageUrl.StartsWith("/_static") || block.ImageUrl.StartsWith("_static"))
101+
imageUrl = $"{block.Build.UrlPathPrefix}/{block.ImageUrl.TrimStart('/')}";
102+
else if (block.ImageUrl.StartsWith('/'))
103+
imageUrl = $"{block.Build.UrlPathPrefix}/{block.ImageUrl.TrimStart('/')}";
104+
else
105+
imageUrl = block.Build.UrlPathPrefix + block.CurrentFile.DirectoryName!.Replace(block.Build.ConfigurationPath.DirectoryName!, "") + "/" + block.ImageUrl;
106+
}
107+
else
108+
imageUrl = block.ImageUrl!;
109+
93110
var slice = Image.Create(new ImageViewModel
94111
{
95112
Label = block.Label,

0 commit comments

Comments
 (0)