Skip to content

Commit c8fc54d

Browse files
CopilotreakaleekMpdreamz
authored
Emit error for empty crosslink text (#1954)
* Initial plan * Implement crosslink empty text auto-title feature Co-authored-by: reakaleek <[email protected]> * Add comprehensive tests for crosslink empty text feature Co-authored-by: reakaleek <[email protected]> * Change empty crosslink text behavior to emit error when no title available Co-authored-by: Mpdreamz <[email protected]> * Remove Title property from LinkMetadata and TryGetLinkMetadata method Co-authored-by: Mpdreamz <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: reakaleek <[email protected]> Co-authored-by: Jan Calanog <[email protected]> Co-authored-by: Mpdreamz <[email protected]> Co-authored-by: Martijn Laarman <[email protected]>
1 parent 15eeaa5 commit c8fc54d

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ private static void ProcessCrossLink(LinkInline link, InlineProcessor processor,
184184
uri, out var resolvedUri)
185185
)
186186
link.Url = resolvedUri.ToString();
187+
188+
// Emit error for empty link text in crosslinks
189+
if (link.FirstChild == null)
190+
{
191+
processor.EmitError(link, $"Crosslink '{url}' has empty link text. Please provide explicit link text.");
192+
}
187193
}
188194

189195
private static void ProcessInternalLink(LinkInline link, InlineProcessor processor, ParserContext context)

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,62 @@ public void EmitsCrossLink()
164164
}
165165
}
166166

167+
public class CrossLinkEmptyTextTest(ITestOutputHelper output) : LinkTestBase(output,
168+
"""
169+
170+
Go to [](kibana://index.md)
171+
"""
172+
)
173+
{
174+
[Fact]
175+
public void GeneratesHtml() =>
176+
// language=html - empty crosslinks now emit an error
177+
Html.Should().Contain(
178+
"""<p>Go to <a href="https://docs-v3-preview.elastic.dev/elastic/kibana/tree/main/" hx-select-oob="#main-container" preload="mousedown"></a></p>"""
179+
);
180+
181+
[Fact]
182+
public void HasError() =>
183+
Collector.Diagnostics.Should().Contain(d =>
184+
d.Severity == Severity.Error &&
185+
d.Message.Contains("empty link text"));
186+
187+
[Fact]
188+
public void EmitsCrossLink()
189+
{
190+
Collector.CrossLinks.Should().HaveCount(1);
191+
Collector.CrossLinks.Should().Contain("kibana://index.md");
192+
}
193+
}
194+
195+
public class CrossLinkEmptyTextNoTitleTest(ITestOutputHelper output) : LinkTestBase(output,
196+
"""
197+
198+
Go to [](kibana://get-started/index.md)
199+
"""
200+
)
201+
{
202+
[Fact]
203+
public void GeneratesHtml() =>
204+
// language=html - empty crosslinks emit an error
205+
Html.Should().Contain(
206+
"""<p>Go to <a href="https://docs-v3-preview.elastic.dev/elastic/kibana/tree/main/get-started" hx-select-oob="#main-container" preload="mousedown"></a></p>"""
207+
);
208+
209+
[Fact]
210+
public void HasError() =>
211+
Collector.Diagnostics.Should().Contain(d =>
212+
d.Severity == Severity.Error &&
213+
d.Message.Contains("empty link text"));
214+
215+
[Fact]
216+
public void EmitsCrossLink()
217+
{
218+
Collector.CrossLinks.Should().HaveCount(1);
219+
Collector.CrossLinks.Should().Contain("kibana://get-started/index.md");
220+
}
221+
}
222+
167223
public class LinkWithUnresolvedInterpolationError(ITestOutputHelper output) : LinkTestBase(output,
168224
"""
169225
[global search field]({{this-variable-does-not-exist}}/introduction.html#kibana-navigation-search)

tests/authoring/Framework/TestCrossLinkResolver.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ type TestCrossLinkResolver (config: ConfigurationFile) =
9090
CrossLinkResolver.TryResolve(errorEmitter, crossLinks, uriResolver, crossLinkUri, &resolvedUri)
9191

9292

93+

0 commit comments

Comments
 (0)