Frontend School

Real-time Markdown Editor with Toolbar

Machine Coding
hard

Real-time Markdown Editor with Toolbar

Hard
React
JavaScript
UI/UX
Markdown
Editor

Overview

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.

What you need to do / Task

Your goal is to build a functional markdown editor with the following features:

  1. Split-Pane Layout: Create two distinct panels: an editable text area for markdown input and a read-only panel for real-time HTML preview.
  2. Interactive Toolbar: Implement a toolbar above the editor input. This toolbar should contain buttons for common markdown formatting:
    • Bold (**text**)
    • Italic (*text*)
    • Heading 1 (# Heading)
    • Unordered List (- List item)
    • Link ([text](url))
    • Code Block (multiline: ```` code
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

Constraints & assumptions

  • You must use React for the UI implementation.
  • The core markdown parsing logic for the specified elements (headings, bold, italic, lists, links, code blocks) must be implemented by you; avoid external full-fledged markdown parsing libraries (e.g., marked.js, react-markdown) for this core functionality. You can use dangerouslySetInnerHTML to render the parsed HTML.
  • Focus on functional styling; pixel-perfect design is not required.
  • Assume a modern browser environment.
  • No backend integration or persistence is needed.
  • The editor should handle basic newline characters and paragraph breaks.

Out of scope

  • Full CommonMark spec compliance for markdown parsing.
  • Advanced markdown features like tables, footnotes, image uploads, syntax highlighting within the editor input.
  • Real-time collaboration or undo/redo functionality.
  • Complex error handling for malformed markdown beyond basic rendering.
  • Extensive cross-browser compatibility testing for older browsers.

What interviewers evaluate

  • Architectural Design: Clarity and modularity of React components, effective use of hooks, and separation of concerns.
  • State Management & Performance: Efficient handling of editor state, correct implementation of debouncing for preview updates, and minimal re-renders.
  • Logic Implementation: Correctness and robustness of the applyMarkdown logic (handling selection, cursor position) and the minimalistic parseMarkdownToHtml function.
  • UI/UX & Accessibility: Intuitive user interactions, responsive layout, and basic accessibility considerations for interactive elements.
  • Problem-Solving: Ability to break down the problem, handle edge cases in text manipulation, and deliver a functional solution within time constraints.

Loading editor...