Files
chapter-organizer/WebApp/Services/MarkdownTablePasteService.cs
T
poprhythm 84b31800ad Add MarkdownTablePasteService and integrate with NoteEditDialog and PageNoteDialog components
This commit introduces the MarkdownTablePasteService to facilitate markdown table pasting functionality. The service is registered in Program.cs and injected into NoteEditDialog and PageNoteDialog components. Additionally, OnAfterRenderAsync lifecycle methods are implemented in both dialog components to initialize the service after the editor is rendered, enhancing the user experience for note editing. This change supports improved markdown handling within the application.
2026-01-17 11:33:57 -05:00

42 lines
1.5 KiB
C#

using Microsoft.JSInterop;
namespace WebApp.Services;
/// <summary>
/// Service for initializing paste-markdown functionality in MarkdownEditor components.
/// Enables automatic conversion of pasted spreadsheet tables (Google Sheets, Excel) to Markdown tables.
/// </summary>
public class MarkdownTablePasteService
{
private readonly IJSRuntime _jsRuntime;
private readonly ILogger<MarkdownTablePasteService> _logger;
public MarkdownTablePasteService(IJSRuntime jsRuntime, ILogger<MarkdownTablePasteService> logger)
{
_jsRuntime = jsRuntime;
_logger = logger;
}
/// <summary>
/// Initializes paste-markdown for a MarkdownEditor instance.
/// Should be called after the editor has been rendered and EasyMDE has initialized.
/// </summary>
/// <param name="editorId">Optional ID of the editor wrapper element. If null, will attempt to find the most recent editor.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public async Task InitializeAsync(string? editorId = null)
{
try
{
await _jsRuntime.InvokeVoidAsync("markdownTablePaste.initialize", editorId);
}
catch (JSException ex)
{
_logger.LogWarning(ex, "Failed to initialize paste-markdown for editor {EditorId}", editorId ?? "unknown");
}
catch (Exception ex)
{
_logger.LogError(ex, "Unexpected error initializing paste-markdown for editor {EditorId}", editorId ?? "unknown");
}
}
}