Real-time Markdown Editor with Toolbar
In Freshworks products, clear and effective communication is paramount. Our users frequently create rich content for knowledge base articles, ticket descriptions, and internal notes. A robust and intuitive markdown editor significantly enhances their productivity and content quality. This problem challenges you to build a core component of such an editor: a split-pane interface with real-time preview and interactive toolbar for common markdown formatting. This evaluates your ability to handle complex UI state, text manipulation, and performance optimizations in a React application.
Your goal is to build a functional markdown editor with the following features:
**text**)*text*)# Heading)- List item)[text](url))3. **Toolbar Functionality**: When a toolbar button is clicked:
* If text is selected in the editor, wrap/prefix the selected text with the appropriate markdown syntax.
* If no text is selected, insert the markdown syntax at the current cursor position, placing the cursor optimally for immediate typing (e.g., inside `**|**` for bold, or after `- ` for a list item).
4. **Real-time Preview**: The preview panel must update dynamically as the user types or applies formatting.
5. **Debounced Updates**: To ensure a smooth user experience and prevent performance issues during rapid typing, the preview update logic must be debounced (e.g., 300-500ms).
6. **Basic Markdown Parsing**: Implement a minimalistic markdown parser that can correctly render the specified markdown elements (Headings, Bold, Italic, Unordered Lists, Links, Code Blocks) into HTML for the preview panel.
## UI/UX expectations
* The editor should have a clear two-column layout: input on the left, preview on the right.
* The toolbar should be visually distinct and accessible, positioned above the input panel.
* Toolbar buttons should clearly indicate their function (e.g., 'B' for Bold, 'H1' for Heading 1).
* The input `textarea` should be resizable (if browser default allows) or have a fixed, reasonable height.
* The preview panel should display rendered HTML, not raw markdown.
* Ensure basic accessibility for interactive elements (e.g., keyboard focus, ARIA labels).
## Acceptance criteria
* The application renders a split-pane layout with an editable markdown input and a preview panel.
* A toolbar with functional buttons for Bold, Italic, Heading 1, Unordered List, Link, and Code Block is present.
* Typing markdown into the input panel updates the preview panel in a debounced manner.
* Clicking a toolbar button correctly applies the corresponding markdown syntax to the editor's content, respecting text selection and cursor position.
* The preview panel accurately renders the specified markdown elements (headings, bold, italic, lists, links, code blocks) into HTML.
* The editor remains responsive and performant even during rapid typing, thanks to debouncing.
Constraints
marked.js, react-markdown) for this core functionality. You can use dangerouslySetInnerHTML to render the parsed HTML.applyMarkdown logic (handling selection, cursor position) and the minimalistic parseMarkdownToHtml function.Loading editor...