Skip to content

Commit be14bf5

Browse files
authored
Add support for screenshot class (#665)
* it actually works Signed-off-by: bmorelli25 <[email protected]> * Add newline Signed-off-by: bmorelli25 <[email protected]> * support :screenshot: instead * add docs * more realistic example --------- Signed-off-by: bmorelli25 <[email protected]>
1 parent d9c2e88 commit be14bf5

File tree

7 files changed

+32
-10
lines changed

7 files changed

+32
-10
lines changed

docs/syntax/images.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ Images include screenshots, inline images, icons, and more. Syntax for images is
66

77
Images can be referenced from the top-level `_static` dir or a local image dir.
88

9-
## Screenshots
10-
11-
Screenshots are images displayed with a box-shadow.
12-
13-
:::{warning}
14-
This feature is not currently supported in Elastic Docs V3.
15-
:::
16-
179
## Block-level images
1810

1911
```markdown
@@ -36,6 +28,20 @@ Or, use the `image` directive.
3628
:width: 250px
3729
:::
3830

31+
## Screenshots
32+
33+
Screenshots are images displayed with a box-shadow. Define a screenshot by adding the `:screenshot:` attribute to a block-level image directive.
34+
35+
```markdown
36+
:::{image} img/apm.png
37+
:screenshot:
38+
:::
39+
```
40+
41+
:::{image} img/apm.png
42+
:screenshot:
43+
:::
44+
3945
## Inline images
4046

4147
```markdown

src/Elastic.Markdown/Assets/markdown/images.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
display: initial;
1515
vertical-align: initial;
1616
}
17+
.screenshot {
18+
@apply border-1 border-grey-20 p-4 bg-grey-10 shadow-md;
19+
}
1720
}
1821
}

src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ private static void WriteImage(HtmlRenderer renderer, ImageBlock block)
107107
Scale = block.Scale,
108108
Target = block.Target,
109109
Width = block.Width,
110+
Screenshot = block.Screenshot,
110111
ImageUrl = imageUrl,
111112
});
112113
RenderRazorSlice(slice, renderer, block);
@@ -127,6 +128,7 @@ private static void WriteFigure(HtmlRenderer renderer, ImageBlock block)
127128
Scale = block.Scale,
128129
Target = block.Target,
129130
Width = block.Width,
131+
Screenshot = block.Screenshot,
130132
ImageUrl = imageUrl,
131133
});
132134
RenderRazorSlice(slice, renderer, block);

src/Elastic.Markdown/Myst/Directives/ImageBlock.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public class ImageBlock(DirectiveBlockParser parser, ParserContext context)
3232
/// </summary>
3333
public string? Width { get; set; }
3434

35+
/// <summary>
36+
/// When set, adds a custom screenshot class to the image.
37+
/// </summary>
38+
public string? Screenshot { get; set; }
39+
3540
/// <summary>
3641
/// The uniform scaling factor of the image. The default is “100 %”, i.e. no scaling.
3742
/// </summary>
@@ -67,8 +72,10 @@ public override void FinalizeAndValidate(ParserContext context)
6772
Scale = Prop("scale");
6873
Target = Prop("target");
6974

70-
ExtractImageUrl(context);
75+
// Set Screenshot to "screenshot" if the :screenshot: option is present
76+
Screenshot = Prop("screenshot") != null ? "screenshot" : null;
7177

78+
ExtractImageUrl(context);
7279
}
7380

7481
private void ExtractImageUrl(ParserContext context)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@inherits RazorSlice<ImageViewModel>
22
<a class="reference internal image-reference" href="@Model.ImageUrl">
3-
<img alt="@Model.Alt" src="@Model.ImageUrl" style="@Model.Style" />
3+
<img alt="@Model.Alt" src="@Model.ImageUrl" style="@Model.Style" class="@Model.Screenshot" />
44
[CONTENT]
55
</a>

src/Elastic.Markdown/Slices/Directives/_ViewModels.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public class ImageViewModel
5656
public required string? Width { get; init; }
5757
public required string? ImageUrl { get; init; }
5858

59+
public required string? Screenshot { get; init; }
60+
5961
public string Style
6062
{
6163
get

tests/Elastic.Markdown.Tests/Directives/ImageTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class ImageBlockTests(ITestOutputHelper output) : DirectiveTest<ImageBloc
1414
:::{image} img/observability.png
1515
:alt: Elasticsearch
1616
:width: 250px
17+
:screenshot:
1718
:::
1819
"""
1920
)
@@ -30,6 +31,7 @@ public void ParsesBreakPoint()
3031
Block!.Alt.Should().Be("Elasticsearch");
3132
Block!.Width.Should().Be("250px");
3233
Block!.ImageUrl.Should().Be("img/observability.png");
34+
Block!.Screenshot.Should().Be("screenshot");
3335
}
3436

3537
[Fact]

0 commit comments

Comments
 (0)