Skip to content

Commit f3983d0

Browse files
committed
Fix appearance of multiple API calls in console codeblock
1 parent a3c5033 commit f3983d0

File tree

10 files changed

+272
-68
lines changed

10 files changed

+272
-68
lines changed

docs/syntax/code.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ project:
267267

268268
### Console code blocks
269269

270-
:::{note}
271-
This feature is still being developed.
272-
:::
273-
274270
We document a lot of API endpoints at Elastic. For these endpoints, we support `console` as a language. The term console relates to the dev console in kibana which users can link to directly from these code snippets.
275271

276272
In a console code block, the first line is highlighted as a dev console string and the remainder as json:
@@ -309,6 +305,54 @@ GET /mydocuments/_search
309305

310306
::::
311307

308+
Console code blocks now support multiple API calls within a single code block. When you have multiple console commands, they are displayed as separate sections within the same block with proper visual separation:
309+
310+
::::{tab-set}
311+
312+
:::{tab-item} Output
313+
314+
```console
315+
GET /mydocuments/_search
316+
{
317+
"from": 1,
318+
"query": {
319+
"match_all" {}
320+
}
321+
}
322+
323+
POST /mydocuments/_doc
324+
{
325+
"title": "New Document",
326+
"content": "This is a sample document"
327+
}
328+
```
329+
330+
:::
331+
332+
:::{tab-item} Markdown
333+
334+
````markdown
335+
```console
336+
GET /mydocuments/_search
337+
{
338+
"from": 1,
339+
"query": {
340+
"match_all" {}
341+
}
342+
}
343+
344+
POST /mydocuments/_doc
345+
{
346+
"title": "New Document",
347+
"content": "This is a sample document"
348+
}
349+
```
350+
````
351+
352+
:::
353+
354+
::::
355+
312356
### Code block substitutions
313357

314358
You can use substitutions to insert reusable values into your code block examples.

docs/testing/index.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,34 @@ The files in this directory are used for testing purposes. Do not edit these fil
3131
"key": "value"
3232
}
3333
```
34+
35+
```console
36+
PUT metricbeat-2016.05.30/_doc/1?refresh
37+
{"system.cpu.idle.pct": 0.908}
38+
PUT metricbeat-2016.05.31/_doc/1?refresh
39+
{"system.cpu.idle.pct": 0.105}
40+
```
41+
42+
```console
43+
POST _reindex
44+
{
45+
"max_docs": 10,
46+
"source": {
47+
"index": "my-index-000001",
48+
"query": {
49+
"function_score" : {
50+
"random_score" : {},
51+
"min_score" : 0.9
52+
}
53+
}
54+
},
55+
"dest": {
56+
"index": "my-new-index-000001"
57+
}
58+
}
59+
```
60+
61+
```console
62+
GET metricbeat-2016.05.30-1/_doc/1
63+
GET metricbeat-2016.05.31-1/_doc/1
64+
```

src/Elastic.Documentation.Site/Assets/markdown/code.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@
1919
code:last-child {
2020
@apply rounded-b-sm;
2121
}
22-
code.language-apiheader {
23-
@apply border-b-grey-80 border-b-1;
22+
code.language-apiheader + code.language-json {
23+
@apply pt-0! -mt-3;
24+
}
25+
26+
code.language-json + code.language-apiheader {
27+
@apply border-t-grey-90 border-t-1;
28+
}
29+
30+
code.language-apiheader + code.language-apiheader {
31+
@apply border-t-grey-90 border-t-1;
2432
}
2533
}
2634

src/Elastic.Markdown/Myst/CodeBlocks/Code.cshtml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88
<a class="headerlink" href="@Model.CrossReferenceName" title="Link to this code">¶</a>
99
</div>
1010
}
11-
<pre>@if (!string.IsNullOrEmpty(Model.ApiCallHeader)) { <code class="language-apiheader">@Model.ApiCallHeader</code> }@(Model.RenderBlock())</pre>
11+
<pre>
12+
@if (Model.ApiSegments.Count > 0)
13+
{
14+
@foreach (var segment in Model.ApiSegments)
15+
{
16+
<code class="language-apiheader">@segment.Header</code>
17+
@if (segment.ContentLines.Count > 0)
18+
{
19+
<code class="language-json">@string.Join("\n", segment.ContentLines)</code>
20+
}
21+
}
22+
}
23+
else
24+
{
25+
@(Model.RenderBlock())
26+
}
27+
</pre>
1228
</div>
1329
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Elastic.Markdown.Myst.CodeBlocks;
99

1010
public class CodeViewModel
1111
{
12-
public required string? ApiCallHeader { get; init; }
12+
public required List<ApiSegment> ApiSegments { get; init; }
1313
public required string? Caption { get; init; }
1414
public required string Language { get; init; }
1515
public required string? CrossReferenceName { get; init; }

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
namespace Elastic.Markdown.Myst.CodeBlocks;
1212

13+
public class ApiSegment
14+
{
15+
public string Header { get; set; } = "";
16+
public List<string> ContentLines { get; set; } = [];
17+
}
18+
1319
public class EnhancedCodeBlock(BlockParser parser, ParserContext context)
1420
: FencedCodeBlock(parser), IBlockExtension
1521
{
@@ -31,5 +37,5 @@ public class EnhancedCodeBlock(BlockParser parser, ParserContext context)
3137

3238
public string? Caption { get; set; }
3339

34-
public string? ApiCallHeader { get; set; }
40+
public List<ApiSegment> ApiSegments { get; set; } = [];
3541
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected override void Write(HtmlRenderer renderer, EnhancedCodeBlock block)
128128
CrossReferenceName = string.Empty,// block.CrossReferenceName,
129129
Language = block.Language,
130130
Caption = block.Caption,
131-
ApiCallHeader = block.ApiCallHeader,
131+
ApiSegments = block.ApiSegments,
132132
EnhancedCodeBlock = block
133133
});
134134

0 commit comments

Comments
 (0)