WYSIWYG Editor
Markdown-OS uses a custom WYSIWYG (What You See Is What You Get) editor built oncontenteditable 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 div2
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/saveThe 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: BoldToolbar
The floating toolbar (wysiwyg-toolbar.js) provides quick access to formatting commands.
Inline Formatting Buttons
Buttons change state based on current selection:Heading Selector
Click the heading dropdown to convert the current paragraph: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:- Table
- Image
- Horizontal Rule
- Mermaid Diagram
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:- 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:- 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 Mathdata-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)
Conflict Detection
When external changes occur while you have unsaved edits, a conflict modal appears:- Save My Changes - Your edits win, overwriting external changes
- Discard My Changes - External changes win, your edits are lost
- Cancel - Keep editing, resolve manually later
Undo/Redo
The editor maintains an undo stack:Cmd/Ctrl + Z- UndoCmd/Ctrl + Shift + Z- Redo- Toolbar buttons also trigger undo/redo
Links
Links have special handling: Click to EditRegular click opens an edit dialog:
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)
Table of Contents
The TOC sidebar (toc.js) auto-generates navigation from headings:
- 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 (
Enterfor next,Shift+Enterfor previous)
Cmd/Ctrl + F- Open find dialogCmd/Ctrl + H- Open find and replace dialog