diff --git a/src/QuestPDF.Markdown/Extensions/TextExtensions.cs b/src/QuestPDF.Markdown/Extensions/TextExtensions.cs new file mode 100644 index 0000000..bba9302 --- /dev/null +++ b/src/QuestPDF.Markdown/Extensions/TextExtensions.cs @@ -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) + }; +} \ No newline at end of file diff --git a/src/QuestPDF.Markdown/MarkdownRenderer.cs b/src/QuestPDF.Markdown/MarkdownRenderer.cs index ad69d0c..01cb8b8 100644 --- a/src/QuestPDF.Markdown/MarkdownRenderer.cs +++ b/src/QuestPDF.Markdown/MarkdownRenderer.cs @@ -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) { diff --git a/src/QuestPDF.Markdown/MarkdownRendererOptions.cs b/src/QuestPDF.Markdown/MarkdownRendererOptions.cs index e1be733..81769f2 100644 --- a/src/QuestPDF.Markdown/MarkdownRendererOptions.cs +++ b/src/QuestPDF.Markdown/MarkdownRendererOptions.cs @@ -11,6 +11,8 @@ public class MarkdownRendererOptions /// 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;