Repository navigation
Expand file tree
/
Copy pathMarkdownExamples.cs
More file actions
101 lines (81 loc) · 2.91 KB
/
Copy pathMarkdownExamples.cs
File metadata and controls
101 lines (81 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.IO;
using NUnit.Framework;
using ShinyPDF.Examples.Engine;
using ShinyPDF.Fluent;
using ShinyPDF.Helpers;
namespace ShinyPDF.Examples
{
public class MarkdownExamples
{
private const string ReleaseNotes = """
# Release notes
Version **2.1** adds *Markdown* rendering to ShinyPDF. Content is laid out by the
regular engine, so it pages and wraps like any other text. See [the repository](https://github.com/LM-Development/ShinyPDF).
## What is new
1. A `Markdown()` element for any container
2. Headings, lists, quotes and code blocks
3. ~~Manual conversion~~ is no longer needed
### Supported inline styles
- **Bold**, *italic* and ***both***
- `inline code` and [links](https://example.com)
- nested lists work too
- with their own bullets
> Markdown in, PDF out.
> Quotes can span several lines.
---
```csharp
page.Content().Markdown(markdown, options =>
{
options.BaseFontSize = 11;
});
```
""";
private const string ExtendedFeatures = """
## Tables, tasks and alerts
| Package | Version | Downloads |
|:--------|:-------:|----------:|
| ShinyPDF | 2.1 | 12,400 |
| ShinyPDF.Markdown | 2.1 | 1,250 |
- [x] Tables with column alignment
- [x] Task lists
- [ ] Math formulas
> [!NOTE]
> Alerts use the GitHub syntax and colors.
> [!WARNING]
> Images are only loaded through `ImageResolver` or `data:` URIs.

```csharp
// syntax highlighting for common languages
public static int Add(int a, int b) => a + b;
var text = $"Sum: {Add(1, 2)}";
```
```json
{ "name": "ShinyPDF", "version": 2.1, "stable": true }
```
```sql
SELECT Name, COUNT(*) FROM Packages WHERE Version = '2.1' -- latest
```
""";
[Test]
public void MarkdownExtendedFeatures()
{
RenderingTest
.Create()
.PageSize(PageSizes.A4)
.ProduceImages()
.Render(container => container.Padding(40).Markdown(ExtendedFeatures, options =>
{
options.ImageResolver = path => path == "logo.png" ? File.ReadAllBytes(path) : null;
}));
}
[Test]
public void Markdown()
{
RenderingTest
.Create()
.PageSize(PageSizes.A4)
.ProduceImages()
.Render(container => container.Padding(40).Markdown(ReleaseNotes));
}
}
}