Skip to main content

rc-markdown-editor

Rich/source Markdown editor with a formatting toolbar, backed by rc-textarea.

Package
@rcarls/rc-markdown-editor
Element
<rc-markdown-editor>
Native dependency
Requires a textarea child
State model
Native textarea value plus editor mode
Main events
rc-formatting-changerc-changerc-mode-change

Installation​

npm install @rcarls/rc-webcomponents@next
import '@rcarls/rc-webcomponents/rc-markdown-editor/define';

Usage​

Place a native <textarea> inside the element. Its content is the initial Markdown, and it keeps the value for form submission.

<label for="notes">Notes</label>
<rc-markdown-editor>
<textarea id="notes" name="notes"># Shopping list</textarea>
</rc-markdown-editor>

Live demo​

The editor composes its formatting surface from rc-toolbar, rc-button, and a native <select> for the heading level, allowing the selected theme to style the controls consistently with the rest of an application.

Accessibility​

The rich editing surface is a role="textbox" with aria-multiline="true", named by the native textarea's labels or aria-label; clicking a label focuses the active editing surface. Source mode is an rc-textarea named by the source message. The formatting toolbar is an rc-toolbar of native buttons that report active formats with aria-pressed, and the link editor is a labeled role="dialog" popover.

A wrapping label names the editor without including the textarea's initial Markdown content. Label click forwarding stops when the editor disconnects and follows its current labels when it reconnects.

KeyAction
Ctrl/Cmd+BBold
Ctrl/Cmd+IItalic
Ctrl/Cmd+UUnderline
Ctrl/Cmd+`Inline code
Ctrl/Cmd+KOpens the link editor
Ctrl/Cmd+Shift+SSwitches between rich and source mode

Theming​

The default demo mode shows the component without a package theme. Use the shared preview controls on this page to compare inherited, light, and dark color schemes or to apply the optional Material theme only inside the demo frames.

Localization​

Built-in text follows the element's own lang, else <html lang>. Override it with messages, or register it for every instance under rc-markdown-editor: source, linkPopover, url, applyLink, openLink, removeLink, shortcut; the toolbar reads rc-editor-toolbar (toolbar, bold, italic, underline, strikethrough, inlineCode, link, headingLevel, paragraph, heading, blockquote, bulletList, orderedList, codeBlock, codeBlockLanguage, languagePlaceholder, languageHint, sourceMode, sourceModeHint, shortcut). See Localization.

API​

Properties​

PropertyMarkupTypeDefaultDescription
messagesJS property onlyPartial<RCMarkdownEditorMessages> | undefinedNot specifiedBuilt-in text overrides; unset keys fall back to registered text, then English.
defaultValuedefault-valuestringNot specifiedInitial uncontrolled Markdown value.
valuevaluestringNot specifiedCurrent Markdown value. Host writes are silent.
defaultSourceModedefault-source-modebooleanNot specifiedInitial uncontrolled source-mode state.
sourceModesource-modebooleanNot specifiedControlled: show the markdown source editor instead of the rich view. Host writes are silent; toolbar/keyboard toggles dispatch `rc-mode-change`.
hideToolbarhide-toolbarbooleanfalseHides the formatting toolbar.
readOnlyread-onlybooleanfalseMake the editor read-only.

Events​

EventDetail typeDescription
rc-formatting-changeCustomEventActive formats at cursor changed. Detail: `ActiveFormats`.
rc-changeCustomEventValue changed. Detail: `{ value: string }`.
rc-mode-changeCustomEventMode toggled. Detail: `{ mode: EditorMode }`.

Slots​

NameDescription
(default)Accepts a native `<textarea>` element (and optional `<label>`) for form wiring.

CSS Custom Properties​

PropertyDefaultDescription
--rc-markdown-editor-font-familyinheritFont family of the rich-text view
--rc-markdown-editor-font-sizeinheritFont size of the rich-text view
--rc-markdown-editor-line-height1.6Line height of the rich-text view
--rc-markdown-editor-padding0.75em 1emPadding inside the rich-text view
--rc-markdown-editor-backgroundCanvasBackground color of the rich-text view
--rc-markdown-editor-colorCanvasTextText color of the rich-text view
--rc-markdown-editor-border1px solid ButtonBorderBorder around the rich-text view
--rc-markdown-editor-border-radius0 0 4px 4pxBorder radius of the rich-text view
--rc-markdown-editor-focus-outline2px solid HighlightFocus ring outline on the rich-text view
--rc-markdown-editor-src-font-family'Cascadia Code', 'Fira Code', ui-monospace, monospaceFont family of the source editor
--rc-markdown-editor-toolbar-gap1pxGap between toolbar buttons
--rc-markdown-editor-toolbar-padding4pxPadding inside the toolbar
--rc-markdown-editor-toolbar-radius4px 4px 0 0Toolbar border radius
--rc-markdown-editor-toolbar-border1px solid ButtonBorderToolbar border
--rc-markdown-editor-toolbar-backgroundCanvasToolbar background
--rc-markdown-editor-toolbar-colorCanvasTextToolbar text color
--rc-markdown-editor-toolbar-button-size2remMinimum inline and block size of toolbar buttons
--rc-markdown-editor-toolbar-button-backgroundtransparentToolbar button background
--rc-markdown-editor-toolbar-button-colorButtonTextToolbar button text color
--rc-markdown-editor-toolbar-button-border1px solid transparentToolbar button border
--rc-markdown-editor-toolbar-button-radius3pxToolbar button border radius
--rc-markdown-editor-toolbar-button-hover-opacity0.08Toolbar button hover state-layer opacity
--rc-markdown-editor-toolbar-button-focus-opacity0.12Toolbar button focus state-layer opacity
--rc-markdown-editor-toolbar-button-pressed-opacity0.12Toolbar button pressed state-layer opacity
--rc-markdown-editor-toolbar-button-active-backgroundHighlightActive toolbar button background
--rc-markdown-editor-toolbar-button-active-colorHighlightTextActive toolbar button text color
--rc-markdown-editor-toolbar-button-active-border1px solid HighlightActive toolbar button border
--rc-markdown-editor-toolbar-focus-outline2px solid HighlightToolbar control focus outline
--rc-markdown-editor-toolbar-focus-outline-offset1pxToolbar control focus outline offset
--rc-markdown-editor-toolbar-select-border1px solid ButtonBorderToolbar select border
--rc-markdown-editor-toolbar-select-radius3pxToolbar select border radius
--rc-markdown-editor-toolbar-select-backgroundButtonFaceToolbar select background
--rc-markdown-editor-toolbar-select-colorButtonTextToolbar select text color
--rc-markdown-editor-toolbar-select-active-backgroundHighlightActive toolbar select background
--rc-markdown-editor-toolbar-select-active-colorHighlightTextActive toolbar select text color
--rc-markdown-editor-toolbar-select-active-border-colorHighlightActive toolbar select border color
--rc-markdown-editor-toolbar-input-border1px solid ButtonBorderToolbar input border
--rc-markdown-editor-toolbar-input-radius3pxToolbar input border radius
--rc-markdown-editor-toolbar-input-backgroundFieldToolbar input background
--rc-markdown-editor-toolbar-input-colorFieldTextToolbar input text color
--rc-markdown-editor-src-heading-colorlight-dark(#1d6fc4, #82b4f5)Source-mode heading token color
--rc-markdown-editor-src-code-colorlight-dark(#c94a1a, #f09060)Source-mode inline/fenced code token color
--rc-markdown-editor-src-link-colorlight-dark(#0370b0, #60b8e8)Source-mode link token color
--rc-markdown-editor-src-blockquote-colorlight-dark(#2d7a42, #70b880)Source-mode blockquote token color
--rc-markdown-editor-src-list-colorlight-dark(#7a5c0a, #d4ac48)Source-mode list marker token color
--rc-markdown-editor-src-dim-colorGrayTextSource-mode strikethrough token color

CSS Parts​

PartDescription
toolbarThe `<rc-editor-toolbar>` element.
rich-viewThe contenteditable rich-text view.