diff --git a/src/BuildingBlocks/SpectreConsole/Markdown/SpectreHorizontalCompositeRenderable.cs b/src/BuildingBlocks/SpectreConsole/Markdown/SpectreHorizontalCompositeRenderable.cs new file mode 100644 index 0000000..c343a82 --- /dev/null +++ b/src/BuildingBlocks/SpectreConsole/Markdown/SpectreHorizontalCompositeRenderable.cs @@ -0,0 +1,15 @@ +using Spectre.Console; +using Spectre.Console.Rendering; + +namespace BuildingBlocks.SpectreConsole.Markdown; + +// Stacking elements vertically or adding multiple horizontal rows without extra space +internal class SpectreHorizontalCompositeRenderable(IEnumerable renderablesElements) : Renderable +{ + protected override IEnumerable Render(RenderOptions options, int maxWidth) + { + // Use Rows to combine renderables items in multiple horizontal rows without extra space + IRenderable rows = new Rows(renderablesElements); + return rows.Render(options, maxWidth); + } +} diff --git a/src/BuildingBlocks/SpectreConsole/Markdown/SpectreMarkdownBlockRendering.cs b/src/BuildingBlocks/SpectreConsole/Markdown/SpectreMarkdownBlockRendering.cs index 3808203..89b779a 100644 --- a/src/BuildingBlocks/SpectreConsole/Markdown/SpectreMarkdownBlockRendering.cs +++ b/src/BuildingBlocks/SpectreConsole/Markdown/SpectreMarkdownBlockRendering.cs @@ -66,8 +66,12 @@ public IRenderable RenderBlock( private IRenderable AppendBreakAfter(IRenderable renderable) { + // // or using SpectreHorizontalCompositeRenderable + // return new SpectreHorizontalCompositeRenderable(new List { renderable, new Text(string.Empty) }); + return new SpectreVerticalCompositeRenderable( - new List { renderable, new Text(Environment.NewLine) } + // break current line with `\n` and create a empty line with `NewLine` + new List { renderable, new Text("\n"), new Text(Environment.NewLine) } ); } @@ -81,7 +85,13 @@ private IRenderable AppendBreakBefore(IRenderable renderable) private IRenderable AppendBreakBeforeAfter(IRenderable renderable) { return new SpectreVerticalCompositeRenderable( - new List { new Text(Environment.NewLine), renderable, new Text(Environment.NewLine) } + new List + { + new Text(Environment.NewLine), + renderable, + new Text("\n"), + new Text(Environment.NewLine), + } ); } diff --git a/src/BuildingBlocks/SpectreConsole/Markdown/SpectreVerticalCompositeRenderable.cs b/src/BuildingBlocks/SpectreConsole/Markdown/SpectreVerticalCompositeRenderable.cs index 812229f..bfa547d 100644 --- a/src/BuildingBlocks/SpectreConsole/Markdown/SpectreVerticalCompositeRenderable.cs +++ b/src/BuildingBlocks/SpectreConsole/Markdown/SpectreVerticalCompositeRenderable.cs @@ -1,4 +1,3 @@ -using Spectre.Console; using Spectre.Console.Rendering; namespace BuildingBlocks.SpectreConsole.Markdown; @@ -10,14 +9,3 @@ protected override IEnumerable Render(RenderOptions options, int maxWid return renderables.SelectMany(x => x.Render(options, maxWidth)); } } - -// Stacking elements vertically or adding multiple horizontal rows without extra space -internal class SpectreHorizontalCompositeRenderable(IEnumerable renderablesElements) : Renderable -{ - protected override IEnumerable Render(RenderOptions options, int maxWidth) - { - // Use Rows to combine renderables items in multiple horizontal rows without extra space - IRenderable rows = new Rows(renderablesElements); - return rows.Render(options, maxWidth); - } -} diff --git a/tests/UnitTests/BuildingBlocks.UnitTests/SpectreConsole/Markdown/SpectreMarkdownTests.cs b/tests/UnitTests/BuildingBlocks.UnitTests/SpectreConsole/Markdown/SpectreMarkdownTests.cs index 2c2aea7..29935c1 100644 --- a/tests/UnitTests/BuildingBlocks.UnitTests/SpectreConsole/Markdown/SpectreMarkdownTests.cs +++ b/tests/UnitTests/BuildingBlocks.UnitTests/SpectreConsole/Markdown/SpectreMarkdownTests.cs @@ -36,13 +36,11 @@ public void Test2() public void Test3() { var s = new SpectreMarkdown( - @"To add a method overload to the `Add` class, we need to modify the `Add` class in the `Models/Add.cs` file. Since the current context does not provide the full implementation of the `Add` class, I will assume a basic structure and add an overloaded method. + @"method. Here's the updated code: -Update: Models/Add.cs -```csharp -namespace Calculator;" +Update: Models/Add.cs" ); AnsiConsole.Write(s); }