Skip to content

Commit a625b05

Browse files
authored
Rework applies blocks to applies_to with new semantics (#527)
* Rework applies blocks to applies_to with new semantics * Add directive block parsing for applies_to * update styling * cleanup and fix tests * formatting and BOM files cleanup * fix visibility on constructor * update {applies} to {applies_to}
1 parent 4d1df99 commit a625b05

34 files changed

+1138
-545
lines changed

docs-builder.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Markdown", "src\Elastic.Markdown\Elastic.Markdown.csproj", "{4D198E25-C211-41DC-9E84-B15E89BD7048}"
44
EndProject

docs/syntax/applies.md

Lines changed: 159 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,56 @@
11
---
2-
applies:
3-
stack: ga 8.1
4-
serverless: tech-preview
5-
hosted: beta 8.1.1
6-
eck: beta 3.0.2
7-
ece: unavailable
2+
applies_to:
3+
stack: ga 9.1
4+
deployment:
5+
eck: ga 9.0
6+
ess: beta 9.1
7+
ece: discontinued 9.2.0
8+
self: unavailable 9.3.0
9+
serverless:
10+
security: ga 9.0.0
11+
elasticsearch: beta 9.1.0
12+
observability: discontinued 9.2.0
13+
product: coming 9.5, discontinued 9.7
814
---
915

1016
# Applies to
1117

18+
Allows you to annotate a page or section's applicability.
1219

13-
Using yaml frontmatter pages can explicitly indicate to each deployment targets availability and lifecycle status
14-
20+
### Syntax
1521

16-
```yaml
17-
applies:
18-
stack: ga 8.1
19-
serverless: tech-preview
20-
hosted: beta 8.1.1
21-
eck: beta 3.0.2
22-
ece: unavailable
2322
```
23+
<life-cycle> [version], <life-cycle> [version]
24+
```
25+
26+
Taking a mandatory [life-cycle](#life-cycle) with an optional version.
2427

25-
Its syntax is
28+
#### Life cycle:
29+
* `preview`
30+
* `beta`
31+
* `development`
32+
* `deprecated`
33+
* `coming`
34+
* `discontinued`
35+
* `unavailable`
36+
* `ga`
37+
38+
#### Version
39+
40+
Can be in either `major.minor` or `major.minor.patch` format
41+
42+
#### Examples
2643

2744
```
28-
<product>: <lifecycle> [version]
45+
coming 9.5, discontinued 9.7
46+
discontinued 9.2.0
47+
all
2948
```
3049

31-
Where version is optional.
32-
3350
`all` and empty string mean generally available for all active versions
3451

3552
```yaml
3653
applies:
37-
stack:
3854
serverless: all
3955
```
4056
@@ -46,19 +62,134 @@ applies:
4662
serverless: beta
4763
```
4864

49-
Are equivalent, note `all` just means we won't be rendering the version portion in the html.
65+
Both are equivalent, note `all` just means we won't be rendering the version portion in the html.
5066

5167

52-
## This section has its own applies annotations [#sections]
68+
## Structured model
5369

54-
:::{applies}
55-
:serverless: unavailable
56-
:::
70+
![Applies To Model](img/applies.png)
71+
72+
The above model is projected to the following structured yaml.
73+
74+
```yaml
75+
---
76+
applies_to:
77+
stack:
78+
deployment:
79+
eck:
80+
ess:
81+
ece:
82+
self:
83+
serverless:
84+
security:
85+
elasticsearch:
86+
observability:
87+
product:
88+
---
89+
```
90+
This allows you to annotate various facets as defined in [](../migration/versioning.md)
91+
92+
## Page annotations
93+
94+
Using yaml frontmatter pages can explicitly indicate to each deployment targets availability and lifecycle status
95+
96+
97+
```yaml
98+
---
99+
applies_to:
100+
stack: ga 9.1
101+
deployment:
102+
eck: ga 9.0
103+
ess: beta 9.1
104+
ece: discontinued 9.2.0
105+
self: unavailable 9.3.0
106+
serverless:
107+
security: ga 9.0.0
108+
elasticsearch: beta 9.1.0
109+
observability: discontinued 9.2.0
110+
product: coming 9.5, discontinued 9.7
111+
---
112+
```
113+
114+
115+
## Section annotation [#sections]
116+
117+
```yaml {applies_to}
118+
stack: ga 9.1
119+
deployment:
120+
eck: ga 9.0
121+
ess: beta 9.1
122+
ece: discontinued 9.2.0
123+
self: unavailable 9.3.0
124+
serverless:
125+
security: ga 9.0.0
126+
elasticsearch: beta 9.1.0
127+
observability: discontinued 9.2.0
128+
product: coming 9.5, discontinued 9.7
129+
```
130+
131+
A header may be followed by an `{applies_to}` directive which will contextualize the applicability
132+
of the section further.
57133

58134
:::{note}
59-
the `{applies}` directive **MUST** be preceded by a heading.
135+
the `{applies_to}` directive **MUST** be preceded by a heading directly.
60136
:::
61137

62138

63-
This section describes a feature that's unavailable in `stack` and `ga` in all cloud products
64-
however its tech preview on `serverless` since it overrides what `cloud` specified.
139+
Note that this directive needs triple backticks since its content is literal. See also [](index.md#literal-directives)
140+
141+
````markdown
142+
```{applies_to}
143+
stack: ga 9.1
144+
```
145+
````
146+
147+
In order to play even better with markdown editors the following is also supported:
148+
149+
````markdown
150+
```yaml {applies_to}
151+
stack: ga 9.1
152+
```
153+
````
154+
155+
This will allow the yaml inside the `{applies-to}` directive to be fully highlighted.
156+
157+
158+
## Examples
159+
160+
#### Stack only
161+
```yaml {applies_to}
162+
stack: ga 9.1
163+
```
164+
165+
#### Stack with deployment
166+
```yaml {applies_to}
167+
stack: ga 9.1
168+
deployment:
169+
eck: ga 9.0
170+
ess: beta 9.1
171+
```
172+
173+
#### Deployment only
174+
```yaml {applies_to}
175+
deployment:
176+
ece: discontinued 9.2.0
177+
self: unavailable 9.3.0
178+
```
179+
180+
#### Serverless only
181+
```yaml {applies_to}
182+
serverless: ga 9.0.0
183+
```
184+
185+
#### Serverless with project differences
186+
```yaml {applies_to}
187+
serverless:
188+
security: ga 9.0.0
189+
elasticsearch: beta 9.1.0
190+
observability: discontinued 9.2.0
191+
```
192+
#### Stack with product
193+
```yaml {applies_to}
194+
stack: ga 9.1
195+
```

docs/syntax/img/applies.png

246 KB
Loading

docs/syntax/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Nested content that will be parsed as markdown
2929

3030
Defining directives with `:::` allows the nested markdown syntax to be highlighted properly by editors and web viewers.
3131

32+
33+
3234
### Nesting Directives
3335

3436
Increase the number of leading semicolons to include nested directives.
@@ -46,6 +48,13 @@ Content displayed in the note admonition
4648

4749
## Literal directives
4850

51+
All directive are indicated with semicolons except literal blocks. For these you need to use triple backticks.
52+
53+
* [Code blocks](code.md)
54+
* [{applies-to} blocks](applies.md)
55+
56+
Since their contents **should not** be parsed as markdown they use backticks. This also ensures maximum interopability with existing markdown editors and previews.
57+
4958
Many Markdown editors support syntax highlighting for embedded code blocks. For compatibility with this feature, use triple backticks instead of triple colons for content that needs to be displayed literally:
5059

5160
````markdown

docs/versions/content-patterns.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ See [Versions and lifecycle states](/versions/index.md#versions-and-lifecycle-st
3131

3232
## Section/heading-level `applies` tags
3333

34-
:::{applies}
35-
:ece: all
36-
:hosted: all
37-
:eck: all
38-
:stack: all
39-
:::
34+
```yaml {applies_to}
35+
stack: ga 9.1
36+
deployment:
37+
eck: ga 9.0
38+
ece: discontinued 9.2.0
39+
self: unavailable 9.3.0
40+
```
4041
4142
*see [`applies`](/syntax/applies.md#sections)*
4243

src/Elastic.Markdown.Refactor/Elastic.Markdown.Refactor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>

src/Elastic.Markdown/Assets/styles.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,30 @@
8787
.content-container {
8888
@apply w-full max-w-[80ch];
8989
}
90+
91+
.applies {
92+
border-bottom: 1px solid var(--color-gray-300);
93+
padding-bottom: calc(var(--spacing) * 3);
94+
font-family: "Mier B", "Inter", sans-serif;
95+
96+
.applies-to-label {
97+
display: block;
98+
font-size: 1.5em;
99+
font-weight: var(--font-weight-extrabold);
100+
padding-bottom: calc(var(--spacing) * 3);
101+
}
102+
.applicable-info {
103+
padding: calc(var(--spacing) * 0.5);
104+
padding-left: calc(var(--spacing) * 2);
105+
padding-right: calc(var(--spacing) * 2);
106+
margin: calc(var(--spacing) * 0.5);
107+
display: inline-block;
108+
font-size: 0.8em;
109+
border-radius: 0.4em;
110+
background-color: var(--color-white);
111+
border: 1px solid var(--color-gray-300);
112+
}
113+
}
90114
}
91115

92116
* {

src/Elastic.Markdown/Elastic.Markdown.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Razor">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
using System.IO.Abstractions;
66
using Elastic.Markdown.Myst.Directives;
7+
using Elastic.Markdown.Myst.FrontMatter;
78
using Markdig.Parsers;
89
using Markdig.Syntax;
910

1011
namespace Elastic.Markdown.Myst.CodeBlocks;
1112

13+
public class AppliesToDirective(BlockParser parser, ParserContext context)
14+
: EnhancedCodeBlock(parser, context)
15+
{
16+
public ApplicableTo? AppliesTo { get; set; }
17+
}
18+
1219
public class EnhancedCodeBlock(BlockParser parser, ParserContext context)
1320
: FencedCodeBlock(parser), IBlockExtension
1421
{

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ private static int CountIndentation(StringSlice slice)
108108

109109
protected override void Write(HtmlRenderer renderer, EnhancedCodeBlock block)
110110
{
111+
if (block is AppliesToDirective appliesToDirective)
112+
{
113+
RenderAppliesToHtml(renderer, appliesToDirective);
114+
return;
115+
}
116+
111117
var callOuts = block.UniqueCallOuts;
112118

113119
var slice = Code.Create(new CodeViewModel
@@ -184,4 +190,14 @@ protected override void Write(HtmlRenderer renderer, EnhancedCodeBlock block)
184190
renderer.WriteLine("</ol>");
185191
}
186192
}
193+
194+
private static void RenderAppliesToHtml(HtmlRenderer renderer, AppliesToDirective appliesToDirective)
195+
{
196+
var appliesTo = appliesToDirective.AppliesTo;
197+
var slice2 = ApplicableTo.Create(appliesTo);
198+
if (appliesTo is null || appliesTo == FrontMatter.ApplicableTo.All)
199+
return;
200+
var html = slice2.RenderAsync().GetAwaiter().GetResult();
201+
renderer.Write(html);
202+
}
187203
}

0 commit comments

Comments
 (0)