Naar de inhoud
LEREN

Configuratie

Opties, de werkbalk, plug-ins en de services die u kunt vervangen.

Dit hoofdstuk is beschikbaar in het Engels en Bulgaars.

There are two places to configure RayCraft Write: the server (AddRte) and the editor you show (RteOptions).

AddRte

builder.Services.AddRte(o =>
{
    o.MediaStore = new RteMediaStoreOptions { RootPath = "media", BaseUrl = "/rte-media" };
    o.Filter = new ContentFilterOptions { /* allow and block lists */ };
    o.FilterIncomingHtml = true;
});
SettingMeaning
MediaStoreenables the library of files: a folder on disk (RootPath) and the public address (BaseUrl). Without it, the gallery and the upload of documents are off, and small images (up to 300 KB) are embedded in the HTML.
Filterthe ContentFilterOptions used on every piece of HTML that comes from the browser: allowed and blocked elements and attributes, allowed hosts of frames
FilterIncomingHtmlon by default. The bound Value is always filtered. Turn it off only when you filter the content yourself.

AddRte registers default services with TryAdd, so anything you registered before or after it stays. Replace a part with the dependency injection:

builder.Services.AddSingleton<IRteMediaStore, MyBlobMediaStore>();
InterfaceDefaultReplace it to
IRteMediaStoreFileSystemMediaStore (when MediaStore is set)keep files in blob storage or a database
IRteTemplateProvidernine built-in layoutsload templates of your own
IRteRevisionStorein memory (lost on restart)keep named revisions
IRteCommentStorein memory (lost on restart)keep comments and replies
IRteSpellCheckera word listuse a real dictionary or service
IRteLinkPreviewProviderthe domain only, nothing is fetchedfetch titles of bookmark cards
IRtePeopleProvidernonepeople for @ mentions
IRteCollaborationnoneconnect a CRDT such as Yjs
IRteDocxExporter / IRteDocxImporterBasicDocxExporter / BasicDocxImporterricher Word files

The default stores for revisions and comments are in memory. For production keep them in your database.

The component

<RichTextEditor @bind-Value="html" Options="options" DocumentId="article-42"
                OnReady="Ready" OnEvent="Handle" Class="my-editor" />
ParameterMeaning
Valuethe HTML (two-way, filtered)
Optionsan RteOptions object
DocumentIdnames the document: revisions and comments are kept under it
Class, Style, Idfor the host element
OnReadythe editor is built in the browser
OnEventan editor event (command, modechange, paste, focus, blur ...) as name and JSON

Options are read when the editor starts. To change them later, give the component a new @key.

Methods you can call on the component: GetHtmlAsync, SetHtmlAsync, InsertHtmlAsync, FocusAsync, ExecuteAsync(command, argument), SetModeAsync, SetThemeAsync, SetFullscreenAsync, SetReadOnlyAsync, GetTextAsync, GetCleanHtmlAsync(xhtml, indent), GetMarkdownAsync, GetJsonAsync, GetEmailHtmlAsync, GetStaticHtmlAsync, CheckAccessibilityAsync, ExportDocxAsync, CheckLimitsAsync.

RteOptions

null keeps the default.

SettingMeaning
Toolbarthe buttons in order; `"" is a separator. The default is RteOptions.DefaultToolbar; all names are in RteOptions.AllButtons`.
Pluginsthe built-in plugins to load (null loads all 14)
EnterModeP, Br or Div; Shift+Enter is always a line break
Modestart mode: Design, Html or Preview
ThemeLight, Dark or Classic
DirectionLtr or Rtl
ReadOnlyshow without editing
Height, MinHeight, Placeholder, StatusBarsize and text
ContentCssstyle sheets of your site for the content and the preview, so the editor shows what your readers will see
LocalDraftEnabled, Key, IntervalSeconds: a draft saved in the browser, with a question to restore it
PasteDefaultMode (Keep, Characters, Plain), WordCleanup
UploadMaxFileSize, AllowedTypes, AllowedImageTypes
LimitsMaxHtmlLength, MaxTextLength (shown in the status bar; nothing is blocked)
UrlMode, BaseUrlkeep, relative or absolute addresses in the clean output
MarkdownInline (shortcuts as you type), Emoji (:shortcodes:)
EmbedAutoEmbed, AllowedHosts (www.youtube-nocookie.com and player.vimeo.com by default)
SpellcheckNative (the browser), Server, Language
MergeFields[{ Name, Label }] for mail merge
BlocksCallouts, Columns, Toggles, Equations, Diagrams, Bookmarks, Chips, DragHandles
FocusMode, TypewriterModewriting modes
A11y.Livethe live accessibility check
Userthe author name for comments and revisions
UiLanguagethe language of the interface (Languages)
Texts, Labelsreplace texts of the interface

Example

<RichTextEditor @bind-Value="html" DocumentId="@id" Options="options" />

@code {
    readonly RteOptions options = new()
    {
        Placeholder = "Write the article here...",
        MinHeight = "320px",
        UiLanguage = "de-DE",
        ContentCss = ["/css/site.css"],
        LocalDraft = { Enabled = true, Key = "article-42" },
        Upload = { MaxFileSize = 5 * 1024 * 1024 },
        Limits = { MaxTextLength = 20000 },
        User = { Name = "Ada Lovelace" },
        Toolbar = ["undo", "redo", "|", "bold", "italic", "link", "image", "table", "|", "mode", "fullscreen"]
    };
}

Property types shown here follow the names in RteOptions.cs; use the IntelliSense of your editor for the exact shape.

Protecting the upload

The library of files serves files from MediaStore.RootPath. In production, protect the upload endpoint and the folder with your own authorization and put limits on the size and the types of files (Upload). The built-in FileSystemMediaStore checks file extensions and, for images, the first bytes; paths from the browser are never trusted.

← InstallatieFuncties →

Klaar om uit te proberen RayCraft Write?

Start de proef van 14 dagen, geen kaart nodig.

Start de proef van 14 dagen