From c4b83a83dce4f2d6f87312b948bcc41b960925be Mon Sep 17 00:00:00 2001
From: Steven Luiten
Date: Fri, 3 Jan 2025 10:59:39 +0100
Subject: [PATCH] Add GetHTMLAsStream method.
---
README.md | 1 +
.../BlazorServerSide/BlazorServerSide.csproj | 2 +-
samples/BlazorServerSide/Pages/Index.razor | 20 ++++++++++++++++++-
samples/BlazorServerSide/_Imports.razor | 3 ++-
.../Blazored.TextEditor.csproj | 6 +++++-
.../BlazoredTextEditor.razor | 14 +++++++++++++
src/Blazored.TextEditor/Interop.cs | 13 ++++++++++++
.../wwwroot/Blazored-BlazorQuill.js | 3 +++
8 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 4cf5f50..45fc5a4 100644
--- a/README.md
+++ b/README.md
@@ -78,6 +78,7 @@ Below is a list of all the options available on the Text Editor.
- `GetText` - Gets the content of the editor as Text.
- `GetHTML` - Gets the content of the editor as HTML.
+- `GetHTMLAsStream` - Gets the content of the editor as HTML stream (requires .NET 6.0 or later).
- `GetContent` - Gets the content of the editor in the native Quill JSON Delta format.
- `LoadContent` (`json`) - Allows the content of the editor to be programmatically set.
- `LoadHTMLContent` (`string`) - Allows the content of the editor to be programmatically set.
diff --git a/samples/BlazorServerSide/BlazorServerSide.csproj b/samples/BlazorServerSide/BlazorServerSide.csproj
index aef4ac3..86eb6c5 100644
--- a/samples/BlazorServerSide/BlazorServerSide.csproj
+++ b/samples/BlazorServerSide/BlazorServerSide.csproj
@@ -1,7 +1,7 @@
- netcoreapp3.1
+ netcoreapp3.1;net6.0
diff --git a/samples/BlazorServerSide/Pages/Index.razor b/samples/BlazorServerSide/Pages/Index.razor
index 25a8f74..fc9b0c1 100644
--- a/samples/BlazorServerSide/Pages/Index.razor
+++ b/samples/BlazorServerSide/Pages/Index.razor
@@ -27,6 +27,7 @@
+
@@ -224,9 +225,26 @@ console.log("I love " ERROR: Maximum allowed size exceeded ({streamReference.Length} / {MaxAllowedSize})
";
+ }
+ else
+ {
+ using var stream = await streamReference.OpenReadStreamAsync(MaxAllowedSize, cts.Token);
+ using var streamReader = new StreamReader(stream);
+ QuillHTMLContent = await streamReader.ReadToEndAsync().WaitAsync(cts.Token);
+ }
+#else
QuillHTMLContent = await this.QuillHtml.GetHTML(cts.Token);
+#endif
}
- catch (TaskCanceledException e)
+ catch (TaskCanceledException)
{
QuillHTMLContent = "