-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathSnippets.cs
More file actions
116 lines (94 loc) · 3.35 KB
/
Snippets.cs
File metadata and controls
116 lines (94 loc) · 3.35 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Threading.Tasks;
using ReverseMarkdown;
using VerifyXunit;
using Xunit;
public class Snippets
{
[Fact]
public async Task Usage()
{
#region Usage
var converter = new ReverseMarkdown.Converter();
string html = "This a sample <strong>paragraph</strong> from <a href=\"http://test.com\">my site</a>";
string result = converter.Convert(html);
#endregion
await Verifier.Verify(result);
}
[Fact]
public void UsageWithConfig()
{
#region UsageWithConfig
var config = new ReverseMarkdown.Config
{
// Include the unknown tag completely in the result (default as well)
UnknownTags = Config.UnknownTagsOption.PassThrough,
// generate GitHub flavoured markdown, supported for BR, PRE and table tags
GithubFlavored = true,
// will ignore all comments
RemoveComments = true,
// remove markdown output for links where appropriate
SmartHrefHandling = true
};
var converter = new ReverseMarkdown.Converter(config);
#endregion
}
[Fact]
public void Base64ImageInclude()
{
#region Base64ImageInclude
var converter = new ReverseMarkdown.Converter();
string html = "<img src=\"data:image/png;base64,iVBORw0KGg...\" alt=\"Sample Image\"/>";
string result = converter.Convert(html);
// Output: 
#endregion
}
[Fact]
public void Base64ImageSkip()
{
#region Base64ImageSkip
var config = new ReverseMarkdown.Config
{
Base64Images = Config.Base64ImageHandling.Skip
};
var converter = new ReverseMarkdown.Converter(config);
string html = "<img src=\"data:image/png;base64,iVBORw0KGg...\" alt=\"Sample Image\"/>";
string result = converter.Convert(html);
// Output: (empty - image is skipped)
#endregion
}
[Fact]
public void Base64ImageSaveToFile()
{
#region Base64ImageSaveToFile
var config = new ReverseMarkdown.Config
{
Base64Images = Config.Base64ImageHandling.SaveToFile,
Base64ImageSaveDirectory = "/path/to/images"
};
var converter = new ReverseMarkdown.Converter(config);
string html = "<img src=\"data:image/png;base64,iVBORw0KGg...\" alt=\"Sample Image\"/>";
string result = converter.Convert(html);
// Output: 
// Image file saved to: /path/to/images/image_0.png
#endregion
}
[Fact]
public void Base64ImageCustomFilename()
{
#region Base64ImageCustomFilename
var config = new ReverseMarkdown.Config
{
Base64Images = Config.Base64ImageHandling.SaveToFile,
Base64ImageSaveDirectory = "/path/to/images",
Base64ImageFileNameGenerator = (index, mimeType) =>
{
var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
return $"converted_{timestamp}_{index}";
}
};
var converter = new ReverseMarkdown.Converter(config);
// Images will be saved as: converted_20260108_143022_0.png, converted_20260108_143022_1.jpg, etc.
#endregion
}
}