Skip to main content

sp-markdown-editor

Full-featured markdown editor web component with source, WYSIWYG, and split view modes. Includes a formatting toolbar, syntax highlighting (via Prism.js), voice dictation, file import/export, undo/redo history, and auto-save support.

Peer Dependencies

Full WYSIWYG and preview mode functionality requires the following peer dependencies to be loaded before the component:

<!-- Markdown parsing -->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<!-- HTML sanitization -->
<script src="https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js"></script>
<!-- Syntax highlighting -->
<script src="https://cdn.jsdelivr.net/npm/prismjs/prism.min.js"></script>

Without these, the editor works fully in source mode but WYSIWYG/preview rendering will be limited.

Installation

Install from a GitHub Release with peer dependencies:

npm install https://github.com/StephanWald/trm-ai-webcomponents/releases/download/v0.0.1/skillspilot-webcomponents-0.0.1.tgz marked dompurify prismjs

Or load via script tags:

<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs/prism.min.js"></script>
<script type="module" src="https://stephanwald.github.io/trm-ai-webcomponents/wc/skillspilot.esm.js"></script>

Examples

Basic Editor

A minimal markdown editor with default configuration. Starts in source mode with the formatting toolbar.

View / Edit Source

With Initial Content

Use the value property to set initial markdown content. The editor renders the content in source mode on load.

View / Edit Source

Toolbar and Split View

The editor's toolbar includes formatting buttons (B, I, S, H1-H3, lists, blockquote, code, link, image). Switch between Source, Split, and WYSIWYG modes using the mode tabs at the right end of the toolbar.

View / Edit Source

Event Handling

Listen to contentChange, save, modeChange, importFile, and exportFile events.

View / Edit Source

Dark Mode

Apply the theme-dark class or set theme="dark" to use the dark color scheme with DWC design tokens.

View / Edit Source

API Reference

Properties

PropertyAttributeTypeDefaultDescription
autoSaveauto-savebooleantrue
autoSaveDelayauto-save-delaynumber2000
maxHistorymax-historynumber50
modemode"source" | "split" | "wysiwyg"'source'
placeholderplaceholderstring'Start typing markdown...'
valuevaluestring''

Events

EventDetail TypeDescription
contentChangeContentChangeEvent
exportFileExportEvent
imagePasteImagePasteEvent
importFileImportEvent
modeChangeModeChangeEvent
saveSaveEvent

Methods

MethodSignatureDescription
clear() => Promise<void>
focusEditor() => Promise<void>
getContent() => Promise<string>
getMode() => Promise<EditorMode>
isDirty() => Promise<boolean>
setContent(value: string) => Promise<void>
setMode(mode: EditorMode) => Promise<void>

CSS Custom Properties

PropertyDescription
--dwc-border-colorAlias border color used for toolbar separators and toolbar button hover borders
--dwc-border-radiusBorder radius for toolbar buttons, mode switcher container, inline code chips, and the host element outline
--dwc-color-borderBorder color for the host element, toolbar bottom border, footer top border, mode switcher, split source pane divider, and WYSIWYG heading underlines
--dwc-color-primaryPrimary accent color for active toolbar button borders, active mode tab background, blockquote left-border accent, link color, and active-mode tab background
--dwc-color-primary-lighterLight primary tint for pressed toolbar button state and listening-pulse animation peak
--dwc-color-primary-lightestVery light primary tint for hovered and active toolbar buttons
--dwc-color-successSuccess color for the "saved" save indicator state in the footer
--dwc-color-surfaceBackground color for the overall editor border, mode switcher, split preview pane, and WYSIWYG pane
--dwc-color-surface-secondarySecondary surface color for the toolbar container background, footer background, inline code chips, and table header cells
--dwc-color-textPrimary text color for toolbar buttons, mode tabs, source editor content, and WYSIWYG preview prose
--dwc-color-text-secondarySecondary text color for source editor placeholder and WYSIWYG blockquote and footer labels
--dwc-color-warningWarning color for the "saving" and "dirty" save indicator states in the footer
--dwc-font-familyBase proportional font family for editor UI and preview prose
--dwc-font-family-monoMonospace font family for the source textarea and code blocks in preview
--dwc-font-size-baseBase font size for toolbar buttons, mode tabs, and source editor text
--dwc-font-size-smSmall font size for the footer stats and word/character counts
--dwc-font-weight-mediumMedium font weight for mode tabs and footer save indicator
--dwc-line-height-relaxedRelaxed line height for the source editor textarea (improves readability)

CSS Parts

PartDescription
footerThe status footer showing character count, word count, and auto-save indicator
mode-switcherThe mode switching tabs (Source / WYSIWYG / Split) at the right end of the toolbar
source-editorThe raw markdown source textarea used in source and split modes
toolbarThe formatting toolbar containing bold, italic, heading, list, and utility buttons
wysiwyg-editorThe rendered HTML preview container used in WYSIWYG mode