Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 fix break lines issue in markdown parser #24

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 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 Expand Up @@ -255,7 +265,7 @@
bool suppressNewLine = false
)
{
var text = _inlineRendering.RenderContainerInline(paragraphBlock.Inline, style, alignment: alignment);

Check warning on line 268 in src/BuildingBlocks/SpectreConsole/Markdown/SpectreMarkdownBlockRendering.cs

View workflow job for this annotation

GitHub Actions / build-test

Possible null reference argument for parameter 'inline' in 'IRenderable SpectreMarkdownInlineRendering.RenderContainerInline(ContainerInline inline, Style? style = null, Justify alignment = Justify.Left)'.

return suppressNewLine ? text : AppendBreakAfter(text);
}
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
Loading