Frontend School

Real-time Markdown Editor with Custom Blocks

Machine Coding
hard

Real-time Markdown Editor with Custom Blocks

Hard
Rich Text Editing
Frontend
React
Machine Coding
Parsing
Custom Syntax

Overview

Modern web applications frequently require users to input and display rich text content. Building a robust rich text editor from scratch can be complex, involving intricate state management, DOM manipulation, and parsing. This problem focuses on the core mechanics of translating user-friendly markdown input into a visually appealing, structured preview, including support for custom content blocks that go beyond standard markdown. This capability is crucial for tools like documentation platforms, content management systems, or internal knowledge bases.

What you need to do / Task

Your task is to build a simple, real-time markdown editor component with a live preview.

  1. Input Component: Create a textarea where users can type markdown.
  2. Preview Component: Display a live, rendered preview of the markdown content as the user types.
  3. Markdown Support: Implement parsing and rendering for the following markdown syntax:
    • Bold text: **your text** should render as <strong>your text</strong>.
    • Italic text: *your text* should render as <em>your text</em>.
    • Headings: # Heading 1 and ## Heading 2 should render as <h1>Heading 1</h1> and <h2>Heading 2</h2> respectively.
  4. Custom Block Support: Implement a custom block syntax for "Notes". Any content enclosed within [NOTE] and [/NOTE] tags should be rendered inside a div with a specific class note-block.
    • Example: [NOTE] This is an important note. [/NOTE] should render as <div class="note-block">This is an important note.</div>.
    • The content inside the [NOTE] block should also be parsed for basic inline markdown (bold/italic). Headings are out of scope inside a note block.
  5. Real-time Updates: The preview should update instantaneously as the user types in the textarea.

UI/UX expectations

  • The application should consist of two main panels: a textarea for input on the left and a preview area on the right.
  • The input textarea should be large enough to comfortably type several lines of text.
  • The preview area should clearly display the rendered rich text.
  • Basic styling for note-block, h1, h2, strong, em should be applied to make them visually distinct. Minimal styling is acceptable, focus on functionality.

Acceptance criteria

  • The textarea correctly captures user input.
  • The preview area updates in real-time as the user types.
  • **bold** and *italic* syntax are correctly parsed and rendered as <strong> and <em>.
  • # Heading 1 and ## Heading 2 are correctly parsed and rendered as <h1> and <h2>.
  • The custom [NOTE]...[/NOTE] block is correctly identified and rendered as a <div class="note-block">.
  • Basic markdown (bold/italic) is parsed within the [NOTE] block content.
  • The layout presents a clear input/preview split.

Constraints

Constraints & assumptions

  • You are free to use React for building the UI.
  • No external markdown parsing libraries (e.g., marked.js, react-markdown) are allowed. You must implement the parsing logic yourself using native JavaScript features (e.g., string methods, regular expressions).
  • The problem focuses on parsing the specified markdown subset. Do not attempt to implement a full markdown parser.
  • Performance for very large inputs (thousands of lines) is not a primary concern, but efficient state management for typical inputs is expected.
  • Assume a modern browser environment.

Out of scope

  • Complex markdown features (e.g., lists, code blocks, tables, images, blockquotes).
  • Nested custom blocks or other complex custom syntaxes.
  • Saving or loading content.
  • Accessibility features beyond basic semantic HTML elements.
  • Full-fledged UI toolbar for rich text editing.

What interviewers evaluate

  • Problem Decomposition & Logic: How well you break down the problem into manageable parts and implement the parsing logic, especially for the custom block.
  • React Fundamentals: Effective use of React components, state management (useState, useEffect), and rendering strategies.
  • Code Quality: Readability, maintainability, and organization of your code.
  • UI Implementation: Responsiveness and correctness of the real-time preview.

Loading editor...