Skip to content

Commit 0939b63

Browse files
committed
.
1 parent 5e2477e commit 0939b63

142 files changed

Lines changed: 98 additions & 124 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

readme.md

Lines changed: 2 additions & 2 deletions

src/Morph.Html/HtmlConverter.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ public abstract class HtmlConverter
1313
/// <param name="html">The HTML content to render.</param>
1414
/// <param name="outputDirectory">Directory where PNG files will be saved.</param>
1515
/// <param name="options">Conversion options (optional).</param>
16+
/// <param name="cancel">Cancellation token.</param>
1617
/// <returns>Result containing paths to generated images and page count.</returns>
17-
public ConversionResult ConvertToImages(string html, string outputDirectory, ConversionOptions? options = null)
18+
public async Task<ConversionResult> ConvertToImages(string html, string outputDirectory, ConversionOptions? options = null, CancellationToken cancel = default)
1819
{
1920
options ??= new();
2021
Directory.CreateDirectory(outputDirectory);
2122

22-
var document = ParseHtml(html);
23+
var document = await ParseHtml(html, cancel);
2324
var imagePaths = new List<string>();
2425

2526
var pageIndex = 0;
@@ -42,12 +43,13 @@ public ConversionResult ConvertToImages(string html, string outputDirectory, Con
4243
/// </summary>
4344
/// <param name="html">The HTML content to render.</param>
4445
/// <param name="options">Conversion options (optional).</param>
46+
/// <param name="cancel">Cancellation token.</param>
4547
/// <returns>List of PNG image data for each page.</returns>
46-
public IReadOnlyList<byte[]> ConvertToImageData(string html, ConversionOptions? options = null)
48+
public async Task<IReadOnlyList<byte[]>> ConvertToImageData(string html, ConversionOptions? options = null, CancellationToken cancel = default)
4749
{
4850
options ??= new();
4951

50-
var document = ParseHtml(html);
52+
var document = await ParseHtml(html, cancel);
5153
var imageData = new List<byte[]>();
5254

5355
RenderPages(document, options, writePng =>
@@ -60,12 +62,12 @@ public IReadOnlyList<byte[]> ConvertToImageData(string html, ConversionOptions?
6062
return imageData;
6163
}
6264

63-
static ParsedDocument ParseHtml(string html)
65+
static async Task<ParsedDocument> ParseHtml(string html, CancellationToken cancel)
6466
{
65-
var elements = HtmlParser.Parse(html);
66-
return new ParsedDocument
67+
var elements = await HtmlParser.Parse(html, cancel);
68+
return new()
6769
{
68-
PageSettings = new PageSettings
70+
PageSettings = new()
6971
{
7072
WidthPoints = DefaultPageSize.WidthPoints,
7173
HeightPoints = DefaultPageSize.HeightPoints,

src/Morph.Html/HtmlParser.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public static List<DocumentElement> Parse(string html)
2121
return elements;
2222
}
2323

24+
/// <summary>
25+
/// Async version of Parse. Currently delegates to the sync implementation,
26+
/// but will support async image fetching in the future.
27+
/// </summary>
28+
public static Task<List<DocumentElement>> Parse(string html, CancellationToken cancel)
29+
{
30+
cancel.ThrowIfCancellationRequested();
31+
return Task.FromResult(Parse(html));
32+
}
33+
2434
static void ParseNodes(INodeList nodes, List<DocumentElement> elements)
2535
{
2636
foreach (var node in nodes)
5.6 KB

src/Tests/Inputs/agendas-minutes/06/results_imagesharp.verified.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"PageDiffs": [
55
{
66
"Page": 1,
7-
"ErrorMetric": 0.0999,
7+
"ErrorMetric": 0.1057,
88
"ExpectedFile": "expected_0001.png",
99
"VerifiedFile": "results_imagesharp#page_0001.verified.png",
1010
"ReceivedFile": "results_imagesharp#page_0001.received.png"
1.28 KB

src/Tests/Inputs/agendas-minutes/06/results_skia.verified.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"PageDiffs": [
55
{
66
"Page": 1,
7-
"ErrorMetric": 0.0996,
7+
"ErrorMetric": 0.1055,
88
"ExpectedFile": "expected_0001.png",
99
"VerifiedFile": "results_skia#page_0001.verified.png",
1010
"ReceivedFile": "results_skia#page_0001.received.png"
-24.4 KB

src/Tests/Inputs/brochures/07/results_skia.verified.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"Page": 2,
14-
"ErrorMetric": 0.6782,
14+
"ErrorMetric": 0.6744,
1515
"ExpectedFile": "expected_0002.png",
1616
"VerifiedFile": "results_skia#page_0002.verified.png",
1717
"ReceivedFile": "results_skia#page_0002.received.png"
-871 Bytes

0 commit comments

Comments
 (0)