From 614082bc98c8c6bf42b1e567790f189233e58c9d Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 18 Dec 2024 11:51:39 +0100 Subject: [PATCH 1/3] Update parsing of :open: on admonitions to be nullable --- .../Myst/Directives/AdmonitionBlock.cs | 2 +- src/Elastic.Markdown/Myst/Directives/DirectiveBlock.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Elastic.Markdown/Myst/Directives/AdmonitionBlock.cs b/src/Elastic.Markdown/Myst/Directives/AdmonitionBlock.cs index 39b3f74b..092c37e0 100644 --- a/src/Elastic.Markdown/Myst/Directives/AdmonitionBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/AdmonitionBlock.cs @@ -34,7 +34,7 @@ public string Title public override void FinalizeAndValidate(ParserContext context) { CrossReferenceName = Properties.GetValueOrDefault("name"); - DropdownOpen = PropBool("open"); + DropdownOpen = TryPropBool("open"); if (DropdownOpen.HasValue) Classes = "dropdown"; } diff --git a/src/Elastic.Markdown/Myst/Directives/DirectiveBlock.cs b/src/Elastic.Markdown/Myst/Directives/DirectiveBlock.cs index cc4d6245..8740ece8 100644 --- a/src/Elastic.Markdown/Myst/Directives/DirectiveBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/DirectiveBlock.cs @@ -93,6 +93,16 @@ protected bool PropBool(params string[] keys) return bool.TryParse(value, out var result) && result; } + protected bool? TryPropBool(params string[] keys) + { + var value = Prop(keys); + if (string.IsNullOrEmpty(value)) + return keys.Any(k => Properties.ContainsKey(k)) ? true : null; + + return bool.TryParse(value, out var result) ? result : null; + } + + protected string? Prop(params string[] keys) { foreach (var key in keys) From 9ad983aa75e050b58a7629aa3d4b71d2094b1362 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 18 Dec 2024 17:24:29 +0100 Subject: [PATCH 2/3] fix test with missing docset.yml --- src/Elastic.Markdown/IO/ConfigurationFile.cs | 3 +++ tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs | 1 + 2 files changed, 4 insertions(+) diff --git a/src/Elastic.Markdown/IO/ConfigurationFile.cs b/src/Elastic.Markdown/IO/ConfigurationFile.cs index 1543470d..4fd08bcf 100644 --- a/src/Elastic.Markdown/IO/ConfigurationFile.cs +++ b/src/Elastic.Markdown/IO/ConfigurationFile.cs @@ -49,7 +49,10 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon yaml.Load(textReader); if (yaml.Documents.Count == 0) + { context.EmitWarning(sourceFile, "empty configuration"); + return; + } // Examine the stream var mapping = (YamlMappingNode)yaml.Documents[0].RootNode; diff --git a/tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs b/tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs index 281ef0bc..01cfb171 100644 --- a/tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs +++ b/tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs @@ -18,6 +18,7 @@ public async Task CreatesDefaultOutputDirectory() var logger = new TestLoggerFactory(output); var fileSystem = new MockFileSystem(new Dictionary { + { "docs/source/docset.yml", new MockFileData("") }, { "docs/source/index.md", new MockFileData("test") } }, new MockFileSystemOptions { From 42cc2225581ee094fe0e39bf1b0d4d6b68167175 Mon Sep 17 00:00:00 2001 From: Brandon Morelli Date: Wed, 18 Dec 2024 08:55:02 -0800 Subject: [PATCH 3/3] Update Serve command (#116) Co-authored-by: Martijn Laarman --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81ad5705..b22e5842 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Through the `serve` command you can continuously and partially compile your docu ```bash docker run -v "./.git:/app/.git" -v "./docs:/app/docs" -v "./.artifacts:/app/.artifacts" \ - --expose 8080 ghcr.io/elastic/docs-builder:edge serve + -p 8080:8080 ghcr.io/elastic/docs-builder:edge serve ``` Each page is compiled on demand as you browse http://localhost:8080 and is never cached so changes to files and @@ -148,4 +148,4 @@ The resulting binary `./.artifacts/publish/docs-builder` will run on machines wi To test performance it's best to build the binary and run outside of docker: For refence here's the `markitpy-doc` docset (50k markdown files) currently takes `14s` vs `several minutes` compared to -existing surveyed tools \ No newline at end of file +existing surveyed tools