Skip to content

Commit

Permalink
Allow configuring global alignment settings
Browse files Browse the repository at this point in the history
  • Loading branch information
christiaanderidder committed Nov 8, 2024
1 parent 7723e30 commit 5dbf39c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/QuestPDF.Markdown/Extensions/TextExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using QuestPDF.Fluent;
using QuestPDF.Infrastructure;

namespace QuestPDF.Markdown.Extensions;

internal static class TextExtensions
{
internal static void Align(this TextDescriptor text, TextHorizontalAlignment alignment) =>
GetAlignment(text, alignment).Invoke();

private static Action GetAlignment(TextDescriptor text, TextHorizontalAlignment alignment) =>
alignment switch
{
TextHorizontalAlignment.Left => text.AlignLeft,
TextHorizontalAlignment.Center => text.AlignCenter,
TextHorizontalAlignment.Right => text.AlignRight,
TextHorizontalAlignment.Justify => text.Justify,
TextHorizontalAlignment.Start => text.AlignStart,
TextHorizontalAlignment.End => text.AlignEnd,
_ => throw new ArgumentOutOfRangeException(nameof(alignment), alignment, null)
};
}
2 changes: 2 additions & 0 deletions src/QuestPDF.Markdown/MarkdownRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ private void ProcessLeafBlock(LeafBlock block, IContainer pdf)
{
pdf.Text(text =>
{
text.Align(_options.ParagraphAlignment);

// Process the block's inline elements
foreach (var item in block.Inline)
{
Expand Down
2 changes: 2 additions & 0 deletions src/QuestPDF.Markdown/MarkdownRendererOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class MarkdownRendererOptions
/// </summary>
public bool Debug { get; set; }

public TextHorizontalAlignment ParagraphAlignment { get; set; } = TextHorizontalAlignment.Left;

public Color LinkTextColor { get; set; } = Colors.Blue.Medium;
public Color MarkedTextBackgroundColor { get; set; } = Colors.Yellow.Lighten2;

Expand Down

0 comments on commit 5dbf39c

Please sign in to comment.