From 72631921f8df070293b16121995b50c1734ad647 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 07:27:14 +0000 Subject: [PATCH 1/4] Initial plan From 3146e9c7258df682e51430752b26c153097fb33f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 07:38:56 +0000 Subject: [PATCH 2/4] Update regex to make space before = optional in image sizing Co-authored-by: reakaleek <16325797+reakaleek@users.noreply.github.com> --- .../DiagnosticLinkInlineParser.cs | 2 +- .../Inline/InlineImageTest.cs | 108 ++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index 0f2f1b614..4079e7543 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -40,7 +40,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { } internal sealed partial class LinkRegexExtensions { - [GeneratedRegex(@"\s\=(?\d+%?)(?:x(?\d+%?))?$", RegexOptions.IgnoreCase, "en-US")] + [GeneratedRegex(@"\s*\=(?\d+%?)(?:x(?\d+%?))?$", RegexOptions.IgnoreCase, "en-US")] public static partial Regex MatchTitleStylingInstructions(); } diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs index 40af3f948..2499fafdf 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs @@ -39,3 +39,111 @@ public void GeneratesAttributesInHtml() => """

Elasticsearch

""" ); } + +// Test image sizing with space before = +public class InlineImageWithSizingSpaceBeforeTest(ITestOutputHelper output) : InlineTest(output, +""" +![Elasticsearch](/_static/img/observability.png " =50%") +""" +) +{ + [Fact] + public void ParsesBlock() => Block.Should().NotBeNull(); + + [Fact] + public void GeneratesAttributesInHtml() => + // language=html + Html.ShouldContainHtml( + """

Elasticsearch

""" + ); +} + +// Test image sizing without space before = +public class InlineImageWithSizingNoSpaceBeforeTest(ITestOutputHelper output) : InlineTest(output, +""" +![Elasticsearch](/_static/img/observability.png "=50%") +""" +) +{ + [Fact] + public void ParsesBlock() => Block.Should().NotBeNull(); + + [Fact] + public void GeneratesAttributesInHtml() => + // language=html + Html.ShouldContainHtml( + """

Elasticsearch

""" + ); +} + +// Test image sizing with space after = +public class InlineImageWithSizingSpaceAfterTest(ITestOutputHelper output) : InlineTest(output, +""" +![Elasticsearch](/_static/img/observability.png "=50% ") +""" +) +{ + [Fact] + public void ParsesBlock() => Block.Should().NotBeNull(); + + [Fact] + public void GeneratesAttributesInHtml() => + // language=html + Html.ShouldContainHtml( + """

Elasticsearch

""" + ); +} + +// Test image sizing with pixels +public class InlineImageWithPixelSizingTest(ITestOutputHelper output) : InlineTest(output, +""" +![Elasticsearch](/_static/img/observability.png "=250x330") +""" +) +{ + [Fact] + public void ParsesBlock() => Block.Should().NotBeNull(); + + [Fact] + public void GeneratesAttributesInHtml() => + // language=html + Html.ShouldContainHtml( + """

Elasticsearch

""" + ); +} + +// Test image sizing with title and sizing +public class InlineImageWithTitleAndSizingTest(ITestOutputHelper output) : InlineTest(output, +""" +![Elasticsearch](/_static/img/observability.png "My Title =50%") +""" +) +{ + [Fact] + public void ParsesBlock() => Block.Should().NotBeNull(); + + [Fact] + public void GeneratesAttributesInHtml() => + // language=html + Html.ShouldContainHtml( + """

Elasticsearch

""" + ); +} + +// Test image sizing with width only +public class InlineImageWithWidthOnlyTest(ITestOutputHelper output) : InlineTest(output, +""" +![Elasticsearch](/_static/img/observability.png "=250") +""" +) +{ + [Fact] + public void ParsesBlock() => Block.Should().NotBeNull(); + + [Fact] + public void GeneratesAttributesInHtml() => + // language=html + Html.ShouldContainHtml( + """

Elasticsearch

""" + ); +} From 26d83bf377a74901a67acf4bea1e1a5071cc16a7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 07:40:29 +0000 Subject: [PATCH 3/4] Update tests and documentation for flexible image sizing syntax Co-authored-by: reakaleek <16325797+reakaleek@users.noreply.github.com> --- docs/syntax/images.md | 7 +++++++ tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/syntax/images.md b/docs/syntax/images.md index ebcafdcb6..6d57f3f20 100644 --- a/docs/syntax/images.md +++ b/docs/syntax/images.md @@ -96,6 +96,13 @@ If `H` is omitted `W` is used as the height as well. ![alt](img.png "=50%") ``` +The sizing syntax is flexible and works with or without spaces before the `=` sign. You can also combine it with a title: + +```markdown +![alt](img.png "My Title =50%") +![alt](img.png "My Title=50%") +``` + ### SVG diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs index 2499fafdf..2a96c06f3 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs @@ -76,10 +76,10 @@ public void GeneratesAttributesInHtml() => ); } -// Test image sizing with space after = -public class InlineImageWithSizingSpaceAfterTest(ITestOutputHelper output) : InlineTest(output, +// Test image sizing with title but no space before = +public class InlineImageWithTitleNoSpaceBeforeTest(ITestOutputHelper output) : InlineTest(output, """ -![Elasticsearch](/_static/img/observability.png "=50% ") +![Elasticsearch](/_static/img/observability.png "My Title=50%") """ ) { @@ -90,7 +90,7 @@ public class InlineImageWithSizingSpaceAfterTest(ITestOutputHelper output) : Inl public void GeneratesAttributesInHtml() => // language=html Html.ShouldContainHtml( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } From 64e7c1ee62c2de49b6b74a603fc3e2958f8d1c5a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 07:54:50 +0000 Subject: [PATCH 4/4] Require space before = when title is present, optional when no title Co-authored-by: reakaleek <16325797+reakaleek@users.noreply.github.com> --- docs/syntax/images.md | 6 +++--- .../DiagnosticLinkInlineParser.cs | 4 ++-- .../Inline/InlineImageTest.cs | 18 ------------------ 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/docs/syntax/images.md b/docs/syntax/images.md index 6d57f3f20..97b92f01e 100644 --- a/docs/syntax/images.md +++ b/docs/syntax/images.md @@ -96,11 +96,11 @@ If `H` is omitted `W` is used as the height as well. ![alt](img.png "=50%") ``` -The sizing syntax is flexible and works with or without spaces before the `=` sign. You can also combine it with a title: +When specifying just the size without a title, no space is required before the `=` sign. When combining a title with sizing, a space is required before the `=`: ```markdown -![alt](img.png "My Title =50%") -![alt](img.png "My Title=50%") +![alt](img.png "=50%") +![alt](img.png "My Title =50%") ``` diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index 4079e7543..2880646f5 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -40,7 +40,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { } internal sealed partial class LinkRegexExtensions { - [GeneratedRegex(@"\s*\=(?\d+%?)(?:x(?\d+%?))?$", RegexOptions.IgnoreCase, "en-US")] + [GeneratedRegex(@"(?:^|\s)\=(?\d+%?)(?:x(?\d+%?))?$", RegexOptions.IgnoreCase, "en-US")] public static partial Regex MatchTitleStylingInstructions(); } @@ -92,7 +92,7 @@ private static void ParseStylingInstructions(LinkInline link, ParserContext cont attributes.AddProperty("width", width); attributes.AddProperty("height", height); - title = title[..matches.Index]; + title = title[..matches.Index].TrimEnd(); } link.Title = title.ReplaceSubstitutions(context); } diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs index 2a96c06f3..3bcaae6a1 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs @@ -76,24 +76,6 @@ public void GeneratesAttributesInHtml() => ); } -// Test image sizing with title but no space before = -public class InlineImageWithTitleNoSpaceBeforeTest(ITestOutputHelper output) : InlineTest(output, -""" -![Elasticsearch](/_static/img/observability.png "My Title=50%") -""" -) -{ - [Fact] - public void ParsesBlock() => Block.Should().NotBeNull(); - - [Fact] - public void GeneratesAttributesInHtml() => - // language=html - Html.ShouldContainHtml( - """

Elasticsearch

""" - ); -} - // Test image sizing with pixels public class InlineImageWithPixelSizingTest(ITestOutputHelper output) : InlineTest(output, """