|
5 | 5 | // This file is licensed under the BSD-Clause 2 license. |
6 | 6 | // See the license.txt file in the project root for more information. |
7 | 7 |
|
| 8 | +using System.IO.Abstractions; |
8 | 9 | using Elastic.Markdown.Diagnostics; |
9 | 10 | using Elastic.Markdown.Myst.CodeBlocks; |
10 | 11 | using Elastic.Markdown.Myst.FrontMatter; |
11 | 12 | using Elastic.Markdown.Myst.Settings; |
12 | 13 | using Elastic.Markdown.Myst.Substitution; |
13 | 14 | using Elastic.Markdown.Slices.Directives; |
14 | 15 | using Markdig; |
| 16 | +using Markdig.Parsers; |
15 | 17 | using Markdig.Renderers; |
16 | 18 | using Markdig.Renderers.Html; |
17 | 19 | using Markdig.Syntax; |
@@ -83,13 +85,28 @@ protected override void Write(HtmlRenderer renderer, DirectiveBlock directiveBlo |
83 | 85 | } |
84 | 86 | } |
85 | 87 |
|
| 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 | + |
86 | 94 | private void WriteImage(HtmlRenderer renderer, ImageBlock block) |
87 | 95 | { |
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 | + |
93 | 110 | var slice = Image.Create(new ImageViewModel |
94 | 111 | { |
95 | 112 | Label = block.Label, |
|
0 commit comments