Skip to content

Commit c37c4da

Browse files
committed
Merge branch 'refs/heads/main' into feature/navigation
# Conflicts: # src/Elastic.Markdown/Assets/fonts.css # src/Elastic.Markdown/Assets/main.ts # src/Elastic.Markdown/Assets/styles.css # src/Elastic.Markdown/Slices/_Layout.cshtml # src/Elastic.Markdown/package-lock.json # src/Elastic.Markdown/package.json
2 parents 25d17cf + d6bfa89 commit c37c4da

File tree

25 files changed

+144
-94
lines changed

25 files changed

+144
-94
lines changed

.github/workflows/comment-on-asciidoc-changes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
owner: context.repo.owner,
3737
repo: context.repo.repo,
3838
issue_number: context.payload.pull_request.number,
39-
body: 'It looks like this PR modifies one or more `.asciidoc` files. These files are being migrated to Markdown, and any changes merged now will be lost. See the [migration guide](https://elastic.github.io/docs-builder/migration/freeze/index.html) for details.'
39+
body: '> [!WARNING]\n> It looks like this PR modifies one or more `.asciidoc` files. These files are being migrated to Markdown, and any changes merged now will be lost. See the [migration guide](https://elastic.github.io/docs-builder/migration/freeze/index.html) for details.'
4040
})
4141
4242
- name: Error if .asciidoc files changed

docs/syntax/applies.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ Are equivalent, note `all` just means we won't be rendering the version portion
5252
## This section has its own applies annotations [#sections]
5353

5454
:::{applies}
55-
:stack: unavailable
56-
:serverless: tech-preview
57-
:cloud: ga
55+
:serverless: unavailable
5856
:::
5957

6058
:::{note}

src/Elastic.Markdown/Assets/fonts.css

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
@font-face {
2-
font-family: "Inter";
3-
src: url("./fonts/InterVariable.woff2") format("woff2");
4-
font-display: swap;
5-
}
6-
7-
@font-face {
8-
font-family: "Mier B";
9-
src: url("./fonts/MierB-Regular.woff2") format("woff2");
10-
font-weight: normal;
11-
font-display: swap;
12-
}
13-
141
@font-face {
152
font-family: "Mier B";
163
src: url("./fonts/MierB-Bold.woff2") format("woff2");

src/Elastic.Markdown/DocumentationGenerator.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public async Task GenerateAll(Cancel ctx)
7272

7373
await ExtractEmbeddedStaticResources(ctx);
7474

75-
7675
_logger.LogInformation($"Completing diagnostics channel");
7776
Context.Collector.Channel.TryComplete();
7877

@@ -92,6 +91,7 @@ private async Task ProcessDocumentationFiles(HashSet<string> offendingFiles, Dat
9291
{
9392
var processedFileCount = 0;
9493
var exceptionCount = 0;
94+
var totalFileCount = DocumentationSet.Files.Count;
9595
_ = Context.Collector.StartAsync(ctx);
9696
await Parallel.ForEachAsync(DocumentationSet.Files, ctx, async (file, token) =>
9797
{
@@ -112,8 +112,9 @@ await Parallel.ForEachAsync(DocumentationSet.Files, ctx, async (file, token) =>
112112
}
113113

114114
if (processedFiles % 100 == 0)
115-
_logger.LogInformation($"-> Handled {processedFiles} files");
115+
_logger.LogInformation($"-> Processed {processedFiles}/{totalFileCount} files");
116116
});
117+
_logger.LogInformation($"-> Processed {processedFileCount}/{totalFileCount} files");
117118
}
118119

119120
private async Task ExtractEmbeddedStaticResources(Cancel ctx)
@@ -149,7 +150,7 @@ private async Task ProcessFile(HashSet<string> offendingFiles, DocumentationFile
149150
return;
150151
}
151152

152-
_logger.LogTrace($"{file.SourceFile.FullName}");
153+
_logger.LogTrace($"--> {file.SourceFile.FullName}");
153154
var outputFile = OutputFile(file.RelativePath);
154155
if (file is MarkdownFile markdown)
155156
await HtmlWriter.WriteAsync(outputFile, markdown, token);

src/Elastic.Markdown/Myst/CodeBlocks/CallOutParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace Elastic.Markdown.Myst.CodeBlocks;
88

99
public static partial class CallOutParser
1010
{
11-
[GeneratedRegex(@"^.+\S+.*?\s<\d+>$", RegexOptions.IgnoreCase, "en-US")]
11+
[GeneratedRegex(@"^.+\S+.*?\s<\d+>$", RegexOptions.IgnoreCase, 2000, "en-US")]
1212
public static partial Regex CallOutNumber();
1313

14-
[GeneratedRegex(@"^.+\S+.*?\s(?:\/\/|#)\s[^""\/#]+$", RegexOptions.IgnoreCase, "en-US")]
14+
[GeneratedRegex(@"^.+\S+.*?\s(?:\/\/|#)\s[^""\/#]+$", RegexOptions.IgnoreCase, 2000, "en-US")]
1515
public static partial Regex MathInlineAnnotation();
1616
}

src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public override bool Close(BlockProcessor processor, Block block)
119119
continue;
120120

121121
List<CallOut> callOuts = [];
122-
var hasClassicCallout = span.IndexOf("<") > 0;
122+
var hasClassicCallout = span.IndexOf("<") > 0 && span.LastIndexOf(">") == span.Length - 1;
123123
if (hasClassicCallout)
124124
{
125125
var matchClassicCallout = CallOutParser.CallOutNumber().EnumerateMatches(span);

src/Elastic.Markdown/Myst/Comments/CommentBlockParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public override bool Close(BlockProcessor processor, Block block)
155155
{
156156
if (!processor.TrackTrivia)
157157
{
158-
var heading = (HeadingBlock)block;
158+
var heading = (CommentBlock)block;
159159
heading.Lines.Trim();
160160
}
161161

src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ private static void ProcessInternalLink(InlineProcessor processor, LinkInline li
168168
{
169169
var (url, anchor) = SplitUrlAndAnchor(link.Url ?? string.Empty);
170170
var includeFrom = GetIncludeFromPath(url, context);
171-
171+
var file = ResolveFile(context, url);
172172
ValidateInternalUrl(processor, url, includeFrom, line, column, length, context);
173-
ProcessLinkText(processor, link, context, url, anchor, line, column, length);
174-
UpdateLinkUrl(link, url, anchor, context.Build.UrlPathPrefix ?? string.Empty);
173+
ProcessLinkText(processor, link, context, url, anchor, line, column, length, file);
174+
UpdateLinkUrl(link, url, context, anchor, file);
175175
}
176176

177177
private static (string url, string? anchor) SplitUrlAndAnchor(string fullUrl)
@@ -195,12 +195,11 @@ private static void ValidateInternalUrl(InlineProcessor processor, string url, s
195195
processor.EmitError(line, column, length, $"`{url}` does not exist. resolved to `{pathOnDisk}");
196196
}
197197

198-
private static void ProcessLinkText(InlineProcessor processor, LinkInline link, ParserContext context, string url, string? anchor, int line, int column, int length)
198+
private static void ProcessLinkText(InlineProcessor processor, LinkInline link, ParserContext context, string url, string? anchor, int line, int column, int length, IFileInfo file)
199199
{
200200
if (link.FirstChild != null && string.IsNullOrEmpty(anchor))
201201
return;
202202

203-
var file = ResolveFile(context, url);
204203
var markdown = context.GetDocumentationFile?.Invoke(file) as MarkdownFile;
205204

206205
if (markdown == null)
@@ -236,15 +235,26 @@ private static void ValidateAnchor(InlineProcessor processor, MarkdownFile markd
236235
processor.EmitError(line, column, length, $"`{anchor}` does not exist in {markdown.FileName}.");
237236
}
238237

239-
private static void UpdateLinkUrl(LinkInline link, string url, string? anchor, string urlPathPrefix)
238+
private static void UpdateLinkUrl(LinkInline link, string url, ParserContext context, string? anchor, IFileInfo file)
240239
{
240+
var urlPathPrefix = context.Build.UrlPathPrefix ?? string.Empty;
241+
242+
if (!url.StartsWith('/') && !string.IsNullOrEmpty(url))
243+
url = GetRootRelativePath(context, file);
244+
241245
if (url.EndsWith(".md"))
242246
url = Path.ChangeExtension(url, ".html");
243247

244-
if (url.StartsWith("/") && !string.IsNullOrWhiteSpace(urlPathPrefix))
248+
if (!string.IsNullOrWhiteSpace(url) && !string.IsNullOrWhiteSpace(urlPathPrefix))
245249
url = $"{urlPathPrefix.TrimEnd('/')}{url}";
246250

247-
link.Url = !string.IsNullOrEmpty(anchor) ? $"{url}#{anchor}" : url;
251+
link.Url = string.IsNullOrEmpty(anchor) ? url : $"{url}#{anchor}";
252+
}
253+
254+
private static string GetRootRelativePath(ParserContext context, IFileInfo file)
255+
{
256+
var docsetDirectory = context.Configuration.SourceFile.Directory;
257+
return file.FullName.Replace(docsetDirectory!.FullName, string.Empty);
248258
}
249259

250260
private static bool IsCrossLink(Uri? uri) =>

src/Elastic.Markdown/Myst/MarkdownParser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public static MarkdownPipeline Pipeline
6060
return _pipeline;
6161

6262
var builder = new MarkdownPipelineBuilder()
63-
.EnableTrackTrivia()
6463
.UseInlineAnchors()
6564
.UsePreciseSourceLocation()
6665
.UseDiagnosticLinks()

src/Elastic.Markdown/Slices/HtmlWriter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public HtmlWriter(DocumentationSet documentationSet, IFileSystem writeFileSystem
2828
public ILoggerFactory LoggerFactory { get; }
2929
public ServiceProvider ServiceProvider { get; }
3030

31+
private Task<string> RenderEmptyString(MarkdownFile markdown, Cancel ctx = default) =>
32+
Task.FromResult(string.Empty);
33+
3134
private async Task<string> RenderNavigation(MarkdownFile markdown, Cancel ctx = default)
3235
{
3336
var slice = Layout._TocTree.Create(new NavigationViewModel

0 commit comments

Comments
 (0)