Skip to main content

WYSIWYG Editor

Markdown-OS uses a custom WYSIWYG (What You See Is What You Get) editor built on contenteditable with real-time markdown rendering.

How It Works

The editor uses a bidirectional content flow:
1

Load markdown

Server markdown → marked.parse() → rendered HTML in contenteditable div
2

Edit visually

Users edit rich text directly. Changes are captured via input and keydown events.
3

Save as markdown

contenteditable HTML → TurndownService → markdown string → POST /api/save
The editor is implemented in markdown_os/static/js/wysiwyg.js (~2000 lines) with no build step required.

Inline Formatting

Keyboard Shortcuts

Apply formatting with standard keyboard shortcuts:

Inline Markdown Shortcuts

The editor detects markdown patterns as you type and applies formatting automatically: Bold
Italic
Strikethrough
Inline Code
Links
Inline shortcuts are detected on input and keydown events. Patterns must be complete (closing delimiter entered) to trigger conversion.

Toolbar

The floating toolbar (wysiwyg-toolbar.js) provides quick access to formatting commands.

Inline Formatting Buttons

Buttons change state based on current selection:
Active buttons are highlighted to show current formatting.

Heading Selector

Click the heading dropdown to convert the current paragraph:
Headings are detected and the dropdown shows the current level:

List Toggles

Convert paragraphs to lists:
  • Bullet List - Unordered list with - or * markers
  • Ordered List - Numbered list with 1. , 2. , etc.

Insert Menu

The insert menu provides templates for complex structures:
Inserts a 3×3 table template:

Block Editing

Code Blocks

Code blocks are click-to-edit. The rendered code block shows a modal when clicked:
Features:
  • Syntax highlighting via highlight.js
  • Language labels (e.g., python, javascript)
  • Copy button with success feedback
  • Line numbers for long blocks
Code blocks preserve exact indentation and whitespace. The raw content is stored separately from the rendered HTML.

Mermaid Diagrams

Mermaid blocks are also click-to-edit:
Rendered diagrams support:
  • Pan and Zoom - Interactive navigation with svg-pan-zoom
  • Click to Edit - Modify the Mermaid source code
  • Error Display - Syntax errors show in red with helpful messages

Math Equations

KaTeX renders inline and display math: Inline Math
Display Math
Math blocks are click-to-edit like code blocks. LaTeX source is stored in data-original-content.

Auto-save

The editor auto-saves after 1 second of inactivity:

Save Status Indicator

The save status indicator shows:
  • Saving… - Request in progress
  • Saved - Last save succeeded (shows timestamp)
  • Error - Save failed (shows error message)
You can manually save with Cmd/Ctrl + S, but auto-save handles it automatically in most cases.

Conflict Detection

When external changes occur while you have unsaved edits, a conflict modal appears:
Options:
  1. Save My Changes - Your edits win, overwriting external changes
  2. Discard My Changes - External changes win, your edits are lost
  3. Cancel - Keep editing, resolve manually later

Undo/Redo

The editor maintains an undo stack:
Shortcuts:
  • Cmd/Ctrl + Z - Undo
  • Cmd/Ctrl + Shift + Z - Redo
  • Toolbar buttons also trigger undo/redo
History is stored in memory only. Refreshing the page clears the undo stack.
Links have special handling: Click to Edit
Regular click opens an edit dialog:
Cmd/Ctrl+Click to Open
Holding Cmd (Mac) or Ctrl (Windows/Linux) opens the link in a new tab:

Image Upload

Images can be added by:
  • Dragging and dropping onto the editor
  • Pasting from clipboard (Cmd/Ctrl + V)
  • Insert menu toolbar button (prompts for URL)
See the Images guide for detailed upload documentation.

Table of Contents

The TOC sidebar (toc.js) auto-generates navigation from headings:
Features:
  • Nested indentation based on heading levels
  • Smooth scrolling to sections
  • Active section highlighting
  • Automatically updates when headings change

Search and Replace

The search dialog supports:
  • Case-sensitive and case-insensitive modes
  • Match highlighting in the editor
  • Replace and Replace All actions
  • Keyboard navigation (Enter for next, Shift+Enter for previous)
Access search with:
  • Cmd/Ctrl + F - Open find dialog
  • Cmd/Ctrl + H - Open find and replace dialog

Accessibility

Keyboard Navigation

All toolbar buttons and menus are keyboard accessible:

ARIA Labels

UI elements include descriptive ARIA labels for screen readers:

Focus Management

Dialogs trap focus and restore it after closing:

Performance Optimizations

Debounced Rendering

Markdown rendering is debounced to avoid blocking on rapid input:

Virtual Scrolling

Large files with hundreds of headings use virtual scrolling in the TOC to maintain smooth performance.

Lazy Loading

Code highlighting and Mermaid rendering happen on-demand using Intersection Observer: