diff --git a/docs/syntax/applies.md b/docs/syntax/applies.md index fafffc82..5ca89b4b 100644 --- a/docs/syntax/applies.md +++ b/docs/syntax/applies.md @@ -47,14 +47,14 @@ discontinued 9.2.0 all ``` -`all` and empty string mean generally available for all active versions +`all` means generally available for all active versions ```yaml applies_to: serverless: all ``` -`all` and empty string can also be specified at a version level +`all` can also be specified at a version level ```yaml applies_to: @@ -62,7 +62,7 @@ applies_to: serverless: beta ``` -Both are equivalent, note `all` just means we won't be rendering the version portion in the html. +Note `all` just means we won't be rendering the version portion in the HTML. ## Structured model diff --git a/src/Elastic.Markdown/Myst/FrontMatter/ApplicableTo.cs b/src/Elastic.Markdown/Myst/FrontMatter/ApplicableTo.cs index a085ce6b..c2e00fdd 100644 --- a/src/Elastic.Markdown/Myst/FrontMatter/ApplicableTo.cs +++ b/src/Elastic.Markdown/Myst/FrontMatter/ApplicableTo.cs @@ -122,10 +122,17 @@ public class ApplicableToConverter : IYamlTypeConverter public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer) { + var warnings = new List(); + var applicableTo = new ApplicableTo(); + if (parser.TryConsume(out var value)) { if (string.IsNullOrWhiteSpace(value.Value)) - return ApplicableTo.All; + { + warnings.Add("The 'applies_to' field is present but empty. No applicability will be assumed."); + return null; + } + if (string.Equals(value.Value, "all", StringComparison.InvariantCultureIgnoreCase)) return ApplicableTo.All; } @@ -134,10 +141,6 @@ public class ApplicableToConverter : IYamlTypeConverter if (deserialized is not Dictionary { Count: > 0 } dictionary) return null; - - var applicableTo = new ApplicableTo(); - var warnings = new List(); - var keys = dictionary.Keys.OfType().ToArray(); var oldStyleKeys = keys.Where(k => k.StartsWith(':')).ToList(); if (oldStyleKeys.Count > 0) diff --git a/tests/authoring/Applicability/AppliesToFrontMatter.fs b/tests/authoring/Applicability/AppliesToFrontMatter.fs index 7932d3b1..357e75bf 100644 --- a/tests/authoring/Applicability/AppliesToFrontMatter.fs +++ b/tests/authoring/Applicability/AppliesToFrontMatter.fs @@ -186,3 +186,11 @@ applies_to: Stack=AppliesCollection.op_Explicit "ga 9.1.0", Product=AppliesCollection.op_Explicit "coming 9.5, discontinued 9.7" )) + +type ``parses empty applies_to as null`` () = + static let markdown = frontMatter """ +applies_to: +""" + [] + let ``does not render label`` () = + markdown |> appliesTo null