Skip to content

Commit

Permalink
fix: 🐛 fix break lines issue in markdown parser (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdihadeli authored Dec 5, 2024
1 parent e80a61a commit 0dea318
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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<IRenderable> renderablesElements) : Renderable
{
protected override IEnumerable<Segment> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ public IRenderable RenderBlock(

private IRenderable AppendBreakAfter(IRenderable renderable)
{
// // or using SpectreHorizontalCompositeRenderable
// return new SpectreHorizontalCompositeRenderable(new List<IRenderable> { renderable, new Text(string.Empty) });

return new SpectreVerticalCompositeRenderable(
new List<IRenderable> { renderable, new Text(Environment.NewLine) }
// break current line with `\n` and create a empty line with `NewLine`
new List<IRenderable> { renderable, new Text("\n"), new Text(Environment.NewLine) }
);
}

Expand All @@ -81,7 +85,13 @@ private IRenderable AppendBreakBefore(IRenderable renderable)
private IRenderable AppendBreakBeforeAfter(IRenderable renderable)
{
return new SpectreVerticalCompositeRenderable(
new List<IRenderable> { new Text(Environment.NewLine), renderable, new Text(Environment.NewLine) }
new List<IRenderable>
{
new Text(Environment.NewLine),
renderable,
new Text("\n"),
new Text(Environment.NewLine),
}
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Spectre.Console;
using Spectre.Console.Rendering;

namespace BuildingBlocks.SpectreConsole.Markdown;
Expand All @@ -10,14 +9,3 @@ protected override IEnumerable<Segment> 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<IRenderable> renderablesElements) : Renderable
{
protected override IEnumerable<Segment> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 0dea318

Please sign in to comment.