QuestMark 0.0.4
dotnet add package QuestMark --version 0.0.4
NuGet\Install-Package QuestMark -Version 0.0.4
<PackageReference Include="QuestMark" Version="0.0.4" />
<PackageVersion Include="QuestMark" Version="0.0.4" />
<PackageReference Include="QuestMark" />
paket add QuestMark --version 0.0.4
#r "nuget: QuestMark, 0.0.4"
#:package QuestMark@0.0.4
#addin nuget:?package=QuestMark&version=0.0.4
#tool nuget:?package=QuestMark&version=0.0.4
QuestMark
This library allows you to render markdown to PDF. It uses the Markdig library to parse the markdown and the QuestPDF library to render the PDF component, hence the name. If you use these libraries, QuestMark might be of use to you.
The code in this library is heavily inspired by the HTML renderer found in the Markdig source code.
Note: This is extremely experimental!
Getting Started
This library uses the lovely Markdig and QuestPDF libraries to render simple markdown into a QuestPDF component. Most of the time you will be hand-crafting your PDFs using QuestPDF with fairly predictable and nearly static content, but sometimes you might have the need to render some arbitrary markdown into a component inside your document without it appearing ugly and unformatted. That's where QuestMark comes in.
Note: Only fairly basic markdown features are supported at the moment
Installation
QuestMark is available as a NuGet package. Otherwise, simply copy the parts you need - I'm not fussed.
Command line
dotnet add package QuestMark
Usage
Here's an example taken from this repository:
// Program.cs
using Markdig;
using QuestMark.Components;
using QuestPDF.Companion;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
// Select the approprate QuestPDF license for your usage:
QuestPDF.Settings.License = LicenseType.Community;
// Build the Markdig pipeline:
MarkdownPipeline pipeline = new MarkdownPipelineBuilder()
.UseAutoLinks()
.UseNonAsciiNoEscape()
.UseListExtras()
.UseAbbreviations()
.UseEmphasisExtras()
.UseSoftlineBreakAsHardlineBreak()
.DisableHtml()
.Build();
string markdown = File.ReadAllText("./your-file.md");
// Construct the MarkdownComponent (similar API to Markdig):
MarkdownComponent component = QuestMark.Markdown.ToMarkdownComponent(pipeline, markdown);
// Create QuestPDF document:
Document document = Document.Create(document =>
{
document.Page(page =>
{
page.Size(PageSizes.A4);
page.PageColor(Colors.White);
page.Margin(10);
// Add component to page:
IContainer content = page.Content();
content.Component(component);
});
});
bool imUsingTheQuestPDFCompanionApp = true;
if (imUsingTheQuestPDFCompanionApp)
{
document.ShowInCompanion();
}
else
{
document.GeneratePdfAndShow();
}
Customizing Renderer
There is basic support for customizing each renderer. You will need to create a PdfStyleOptions object and set any of the delegate functions found there with your own.
For example:
// Override default styling options for headings and lists:
PdfStyleOptions styleOptions = new()
{
HeadingTextStyler = (level) =>
{
Int32 size = 40 - level * 4;
TextStyle style = TextStyle.Default.FontSize(size).FontColor(Colors.Grey.Lighten1);
if (level < 2 && level >= 4)
{
style.SemiBold();
}
else if (level < 4)
{
style.Bold();
}
return style;
},
ListStyler = (container, depth) => container.PaddingLeft(depth * 4),
};
// Construct the MarkdownComponent (similar API to Markdig):
MarkdownComponent component = QuestMark.Markdown.ToMarkdownComponent(
pipeline,
markdown,
styleOptions // pass it in here
);
To Do
- render images instead of rendering a link to the image
- support as many Markdig extensions as possible
- tables
- alerts
- footnotes
- JIRA links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.