Den här sidan är inte översatt än. Den visas på engelska.
Det här kapitlet finns på engelska och bulgariska.
Short answers to the questions that come up when the editor goes into a real application.
Keep revisions and comments in a database
The default stores are in memory; StorePath keeps them in files. For a database implement the two interfaces. A store gets the document id and returns plain records:
public sealed class EfRevisionStore(AppDbContext db) : IRteRevisionStore
{
public async Task<IReadOnlyList<RteRevision>> ListAsync(string documentId, CancellationToken cancellationToken = default) =>
await db.Revisions.Where(x => x.DocumentId == documentId).OrderByDescending(x => x.CreatedAt).ToListAsync(cancellationToken);
public async Task<RteRevision> SaveAsync(string documentId, string name, string html, string author, CancellationToken cancellationToken = default)
{
var revision = new RteRevision(Guid.NewGuid().ToString("N")[..12], documentId, name, html, author, DateTime.UtcNow);
db.Revisions.Add(revision);
await db.SaveChangesAsync(cancellationToken);
return revision;
}
// GetAsync, RenameAsync and DeleteAsync work the same way
}
builder.Services.AddScoped<IRteRevisionStore, EfRevisionStore>(); Register the store before or after AddRte; AddRte does not replace what is already there. IRteCommentStore and IRteAuditLog follow the same pattern.
Protect the upload
Map the folder of files with MapRteMedia(...).RequireAuthorization() instead of the static files middleware, put the page behind [Authorize] and keep Upload.MaxFileSize small. See Configuration.
Make HTML for e-mail
var html = await editor.GetHtmlAsync();
var mail = EmailHtml.Create(html); EmailHtml inlines the styles and uses tables where e-mail programs need them. Send mail with your own mail component.
Export a Word file with a header and page numbers
var options = new RteOptions { Docx = { HeaderText = "Contract", FooterText = "Confidential", PageNumbers = true, PageSize = "A4" } }; The Export menu and ExportDocxAsync use these values.
Make PDF files on the server
Implement IRtePdfExporter with the renderer you license or run (for example a headless browser or a PDF library) and register it. The Export menu then gives a real file.
public sealed class MyPdfExporter : IRtePdfExporter
{
public async Task<byte[]> ExportAsync(string html, PdfOptions? options = null, CancellationToken cancellationToken = default)
{
var page = StaticRender.Render(html);
return await MyRenderer.ToPdfAsync(page, options?.PageSize == PdfPageSize.A4, cancellationToken);
}
} Tell people when they are mentioned
public sealed class MailMentionNotifier(IMailSender mail) : IRteMentionNotifier
{
public Task NotifyAsync(RteMention mention, CancellationToken cancellationToken = default) =>
mail.SendAsync(mention.PersonId, $"{mention.ByUserName} mentioned you", mention.Snippet, cancellationToken);
}
builder.Services.AddSingleton<IRteMentionNotifier, MailMentionNotifier>(); A person is announced once per page, even when the name is inserted again.
Change a keyboard shortcut
var options = new RteOptions { Shortcuts = new() { ["strike"] = "Ctrl+Alt+S", ["underline"] = "" } }; An empty text removes the shortcut. The list of all shortcuts is in the dialog opened with Ctrl+/.
Show the saved HTML on a page
Show it with StaticRender.Render(html) and link _content/Rte/css/rte.css and the plugin styles you use (css/plugins/structure.css for the table of contents and notes, css/plugins/table-tools.css for table styles).
Redo att prova RayCraft Write?
Starta provperioden på 14 dagar, inget kort behövs.
Starta provperioden på 14 dagar