Skip to content

Commit 64e7c1e

Browse files
Copilotreakaleek
andcommitted
Require space before = when title is present, optional when no title
Co-authored-by: reakaleek <[email protected]>
1 parent 26d83bf commit 64e7c1e

File tree

3 files changed

+5
-23
lines changed

3 files changed

+5
-23
lines changed

docs/syntax/images.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ If `H` is omitted `W` is used as the height as well.
9696
![alt](img.png "=50%")
9797
```
9898

99-
The sizing syntax is flexible and works with or without spaces before the `=` sign. You can also combine it with a title:
99+
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 `=`:
100100

101101
```markdown
102-
![alt](img.png "My Title =50%")
103-
![alt](img.png "My Title=50%")
102+
![alt](img.png "=50%") <!-- Just size, no space needed -->
103+
![alt](img.png "My Title =50%") <!-- With title, space required -->
104104
```
105105

106106

src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { }
4040

4141
internal sealed partial class LinkRegexExtensions
4242
{
43-
[GeneratedRegex(@"\s*\=(?<width>\d+%?)(?:x(?<height>\d+%?))?$", RegexOptions.IgnoreCase, "en-US")]
43+
[GeneratedRegex(@"(?:^|\s)\=(?<width>\d+%?)(?:x(?<height>\d+%?))?$", RegexOptions.IgnoreCase, "en-US")]
4444
public static partial Regex MatchTitleStylingInstructions();
4545
}
4646

@@ -92,7 +92,7 @@ private static void ParseStylingInstructions(LinkInline link, ParserContext cont
9292
attributes.AddProperty("width", width);
9393
attributes.AddProperty("height", height);
9494

95-
title = title[..matches.Index];
95+
title = title[..matches.Index].TrimEnd();
9696
}
9797
link.Title = title.ReplaceSubstitutions(context);
9898
}

tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,6 @@ public void GeneratesAttributesInHtml() =>
7676
);
7777
}
7878

79-
// Test image sizing with title but no space before =
80-
public class InlineImageWithTitleNoSpaceBeforeTest(ITestOutputHelper output) : InlineTest<LinkInline>(output,
81-
"""
82-
![Elasticsearch](/_static/img/observability.png "My Title=50%")
83-
"""
84-
)
85-
{
86-
[Fact]
87-
public void ParsesBlock() => Block.Should().NotBeNull();
88-
89-
[Fact]
90-
public void GeneratesAttributesInHtml() =>
91-
// language=html
92-
Html.ShouldContainHtml(
93-
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" title="My Title" width="50%" height="50%" /></p>"""
94-
);
95-
}
96-
9779
// Test image sizing with pixels
9880
public class InlineImageWithPixelSizingTest(ITestOutputHelper output) : InlineTest<LinkInline>(output,
9981
"""

0 commit comments

Comments
 (0)