Skip to content

Commit 61e09df

Browse files
theletterfclaude
andauthored
Settings: stop stripping {applies_to} inline role in descriptions (#3158)
The SettingsMarkdownNormalizer was unconditionally rewriting `{applies_to}` to the literal text "Applies to" and collapsing the following backtick span to parenthesized text. This swallowed the valid MyST inline role syntax, so per-version badges inside a setting `description` rendered as plain text instead of badges. Drop the rewrite so descriptions pass through to the MyST parser intact. Add a regression test and extend the example YAML + syntax reference page to document the usage. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a400430 commit 61e09df

4 files changed

Lines changed: 42 additions & 41 deletions

File tree

docs/syntax/automated_settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ It demonstrates:
7373
- `note`, `tip`, `warning`, `important`, and `deprecation_details`.
7474
- Nested `settings`.
7575
- `applies_to` inheritance and override behavior.
76+
- Inline `{applies_to}` badges inside a setting `description` (for example, to label per-version defaults in a bulleted list).
7677
- Top-level `page_description`.
7778

7879
### Result

docs/syntax/settings-with-applies-example.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ groups:
5454
xpack.example.mode: strict
5555
```
5656
57+
- setting: xpack.example.defaultModel
58+
id: xpack-example-default-model
59+
description: |
60+
Default model used by the feature. The default varies by version:
61+
62+
* {applies_to}`stack: ga 9.2` Defaults to `model-v2`.
63+
* {applies_to}`stack: ga 9.1` Defaults to `model-v1`.
64+
datatype: string
65+
5766
- group: Advanced settings
5867
id: advanced-settings
5968
description: |

src/Elastic.Markdown/Myst/Directives/Settings/SettingsMarkdownNormalizer.cs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public static string Normalize(string markdown, string? product = null)
1717
var result = markdown.Replace("\r\n", "\n", StringComparison.Ordinal);
1818
if (result.Contains("[source,", StringComparison.Ordinal))
1919
result = NormalizeAsciiDocSourceBlocks(result);
20-
if (result.Contains('{'))
21-
result = NormalizeKibanaMarkupArtifacts(result);
2220
if (result.Contains("](/", StringComparison.Ordinal)
2321
|| result.Contains("](docs-content://", StringComparison.Ordinal)
2422
|| result.Contains("(elasticsearch://", StringComparison.Ordinal)
@@ -28,45 +26,6 @@ public static string Normalize(string markdown, string? product = null)
2826
return result;
2927
}
3028

31-
private static string NormalizeKibanaMarkupArtifacts(string markdown)
32-
{
33-
var s = markdown.Replace("{applies_to}", "Applies to", StringComparison.Ordinal);
34-
return NormalizeAppliesToBacktickArtifacts(s);
35-
}
36-
37-
/// <summary>Kibana-exported blurbs sometimes emit `` `key: value` `` pairs that break markdown code spans.</summary>
38-
private static string NormalizeAppliesToBacktickArtifacts(string markdown)
39-
{
40-
const string prefix = "Applies to`";
41-
var idx = 0;
42-
var output = new StringBuilder(markdown.Length);
43-
while (idx < markdown.Length)
44-
{
45-
var found = markdown.IndexOf(prefix, idx, StringComparison.OrdinalIgnoreCase);
46-
if (found < 0)
47-
{
48-
_ = output.Append(markdown.AsSpan(idx));
49-
break;
50-
}
51-
52-
_ = output.Append(markdown.AsSpan(idx, found - idx));
53-
var valueStart = found + prefix.Length;
54-
var close = markdown.IndexOf('`', valueStart);
55-
if (close < 0)
56-
{
57-
_ = output.Append(markdown.AsSpan(found));
58-
break;
59-
}
60-
61-
_ = output.Append("Applies to (");
62-
_ = output.Append(markdown.AsSpan(valueStart, close - valueStart));
63-
_ = output.Append(')');
64-
idx = close + 1;
65-
}
66-
67-
return output.ToString();
68-
}
69-
7029
/// <summary>
7130
/// Kibana-generated YAML often uses repo-root paths and cross-repo schemes. For docsets that only ship settings fixtures
7231
/// (for example docs-builder), rewrite to resolvable targets.

tests/Elastic.Markdown.Tests/SettingsInclusion/IncludeTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,35 @@ public void DoesNotRenderGenericStackBadgeOrUnavailableSupportedOnEntry()
251251
Html.Should().NotContain("Unavailable");
252252
}
253253
}
254+
255+
public class AppliesToInlineRoleInDescriptionRendersAsBadge(ITestOutputHelper output) : DirectiveTest<SettingsBlock>(output,
256+
"""
257+
:::{settings} _settings/applies-to-in-description.yml
258+
::::
259+
"""
260+
)
261+
{
262+
protected override void AddToFileSystem(MockFileSystem fileSystem)
263+
{
264+
// language=yaml
265+
fileSystem.AddFile("docs/_settings/applies-to-in-description.yml", """
266+
groups:
267+
- group: Example
268+
settings:
269+
- setting: xpack.sample.versioned
270+
description: |
271+
Behavior depends on version:
272+
273+
* {applies_to}`stack: ga 9.2` Defaults to `model-a`.
274+
* {applies_to}`stack: ga 9.1` Defaults to `model-b`.
275+
""");
276+
}
277+
278+
[Fact]
279+
public void RendersAppliesToRoleAsBadgeNotLiteralText()
280+
{
281+
Html.Should().Contain("applies-to-popover");
282+
Html.Should().NotContain("Applies to (stack: ga 9.2)");
283+
Html.Should().NotContain("Applies to (stack: ga 9.1)");
284+
}
285+
}

0 commit comments

Comments
 (0)