From 3d646f0cd69c742ee61929cf6b246d9075d1e9f6 Mon Sep 17 00:00:00 2001 From: Elemento Date: Sat, 1 Feb 2025 12:58:15 +0530 Subject: [PATCH 1/2] Fixed link not dispalyed in markup in Style.cs and added unit test cases --- src/Spectre.Console/Style.cs | 5 ++++ .../Spectre.Console.Tests/Unit/StyleTests.cs | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/Spectre.Console/Style.cs b/src/Spectre.Console/Style.cs index ec652226a..cdb3642d7 100644 --- a/src/Spectre.Console/Style.cs +++ b/src/Spectre.Console/Style.cs @@ -226,6 +226,11 @@ public string ToMarkup() builder.Add("on " + Background.ToMarkup()); } + if (Link?.ToString() != null) + { + builder.Add($"link={Link.ToString()}"); + } + return string.Join(" ", builder); } diff --git a/src/Tests/Spectre.Console.Tests/Unit/StyleTests.cs b/src/Tests/Spectre.Console.Tests/Unit/StyleTests.cs index 379ab3e91..4d6d999a5 100644 --- a/src/Tests/Spectre.Console.Tests/Unit/StyleTests.cs +++ b/src/Tests/Spectre.Console.Tests/Unit/StyleTests.cs @@ -405,5 +405,31 @@ public void Should_Return_Expected_Markup_For_Style_With_Only_Background_Color() // Then result.ShouldBe("default on green"); } + + [Fact] + public void Should_Return_Expected_Markup_For_Style_With_Only_Link() + { + // Given + var style = new Style(link:"https://spectreconsole.net/"); + + // When + var result = style.ToMarkup(); + + // Then + result.ShouldBe("link=https://spectreconsole.net/"); + } + + [Fact] + public void Should_Return_Expected_Markup_For_Style_With_Background_And_Link() + { + // Given + var style = new Style(background: Color.Blue, link: "https://spectreconsole.net/"); + + // When + var result = style.ToMarkup(); + + // Then + result.ShouldBe("default on blue link=https://spectreconsole.net/"); + } } } From ebd888461ed22624012f785377c7292aad744ef3 Mon Sep 17 00:00:00 2001 From: Elemento Date: Mon, 2 Jun 2025 10:18:08 +0530 Subject: [PATCH 2/2] - Addressed review comments --- src/Spectre.Console/Style.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Spectre.Console/Style.cs b/src/Spectre.Console/Style.cs index cdb3642d7..398d0d6cb 100644 --- a/src/Spectre.Console/Style.cs +++ b/src/Spectre.Console/Style.cs @@ -226,9 +226,9 @@ public string ToMarkup() builder.Add("on " + Background.ToMarkup()); } - if (Link?.ToString() != null) + if (Link != null) { - builder.Add($"link={Link.ToString()}"); + builder.Add($"link={Link}"); } return string.Join(" ", builder);