Why I Built TinyMDE: A Zero-Dependency Markdown Editor in TypeScript
Whenever I needed a simple Markdown editor for a classic web form, I ran into the same two extremes: Massive editor frameworks pulling in ProseMirror, CodeMirror, or heavy React/Vue wrappers just to format a <textarea
Whenever I needed a simple Markdown editor for a classic web form, I ran into the same two extremes:
-
Massive editor frameworks pulling in ProseMirror, CodeMirror, or heavy React/Vue wrappers just to format a
<textarea>. - Abandoned libraries from 2016 with unpatched security issues and outdated jQuery dependencies.
I wanted something as simple and self-contained as tinymce.init()βjust for Markdown. So I started building TinyMDE (v0.1.0), a lightweight, framework-agnostic drop-in Markdown editor written in strict TypeScript with zero runtime dependencies.
π Try the Live Demo
π» Source Code on GitHub (MIT)
Drop-In Integration
The main design goal was making integration effortlessβwhether you are using a modern bundler or dropping a single <script> tag into a classic server-rendered PHP/HTML form:
<textarea id="editor"># Hello TinyMDE</textarea>
<script type="module">
import { TinyMDE } from 'tinymde';
import 'tinymde/style.css';
TinyMDE.init({
selector: '#editor',
preview: true
});
</script>
Under the hood, TinyMDE.init() hides the original <textarea>, mounts a split-screen editor + live preview container, and keeps the underlying <textarea> value synchronized on every keystrokeβdispatching standard input and change events so native form submissions and validation work out of the box.
Why Write a Custom Markdown Parser?
Bundling a full CommonMark parser like marked or markdown-it easily adds tens of kilobytes before you even write a line of UI code. For v0.1.0, I implemented a focused, line- and regex-based parser (src/core/parser.ts) covering the core syntax needed in everyday web forms:
- Headings (
#through######) - Bold, italic, and combined inline formatting
- Inline code and fenced code blocks with language tags
- Ordered and unordered lists
- Hyperlinks
Built-In XSS Protection
Rendering user-typed Markdown directly into innerHTML is a classic XSS trap. TinyMDE escapes raw HTML entities by default and sanitizes link URLs so dangerous protocols like javascript: or vbscript: are neutralized before anything reaches the preview pane.
What's Next on the Roadmap?
v0.1.0 is the initial MVP with 22 unit tests covering parser rules and XSS edge cases. Over the next releases, I'm building:
-
v0.2.0: Configurable toolbar (
bold,italic,heading,link,quote,code), keyboard shortcuts (Ctrl+B,Ctrl+I,Tab), and a custom undo/redo history stack. -
v0.3.0: Smart list continuation on
Enter, a toolbar table generator, and GFM table/task-list parsing. - v0.4.0: Switchable view modes (Editor-only, Split-view, Preview-only), CSS variables theming (Light/Dark), and fullscreen mode.
Feedback Welcome!
If you've ever built or integrated a lightweight Markdown editor, what's the one feature you always missβor the parser edge case that always trips up custom implementations?
Feel free to test the live playground or open an issue/discussion on GitHub!
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.