Frontend School

Basic Markdown Editor with Live Preview

Machine Coding
medium

Basic Markdown Editor with Live Preview

Medium
React
Frontend
UI
Markdown
Parsing

Overview

At OYO, we manage a vast amount of content, from property descriptions to internal knowledge base articles. Ensuring this content is easily authorable and consistently formatted is crucial. Markdown offers a lightweight solution for rich text editing. This problem challenges you to build a simple web-based Markdown editor that provides a real-time preview of the rendered HTML, mimicking a core feature of many modern content management systems.

What you need to do / Task

Your primary task is to create a React component that functions as a basic Markdown editor with a live preview pane. Specifically, you must:

  1. Implement a Two-Pane Layout: Display a text area on one side for Markdown input and a separate pane on the other side to show the rendered HTML preview.
  2. Real-time Preview: As the user types Markdown into the editor, the preview pane must update instantly to reflect the HTML rendering of the content.
  3. Basic Markdown Parsing: Your editor should correctly parse and render the following Markdown syntax into their corresponding HTML elements:
    • Headings: Support <h1> for # Heading 1 and <h2> for ## Heading 2.
    • Bold Text: Render **bold text** as <strong>bold text</strong>.
    • Italic Text: Render *italic text* as <em>italic text</em>.
    • Unordered Lists: Render lines starting with - or * as <li> items within a <ul> block.

UI/UX expectations

  • The editor should feature a clear, responsive two-pane layout, ideally side-by-side (editor on the left, preview on the right).
  • The input text area should be resizable (if browser default allows) and allow for multiline input.
  • The preview pane should display the actual rendered HTML, not just the raw Markdown text.
  • Focus on functionality and clear separation of concerns rather than extensive styling or pixel-perfect design.

Acceptance criteria

  • [ ] A textarea for Markdown input and a div for HTML preview are visible.
  • [ ] Typing into the Markdown editor immediately updates the content in the preview pane.
  • [ ] Markdown syntax # Heading 1 and ## Heading 2 correctly render as <h1> and <h2> in the preview.
  • [ ] Markdown syntax **bold text** renders as <strong>bold text</strong> in the preview.
  • [ ] Markdown syntax *italic text* renders as <em>italic text</em> in the preview.
  • [ ] Markdown lines - List item or * List item correctly render as <li> elements within a <ul> block in the preview.

Constraints

Constraints & assumptions

  • You must use React for building the UI.
  • Implement the Markdown parsing logic yourself or use extremely minimal helper functions. Avoid full-fledged Markdown parsing libraries (e.g., marked, markdown-it) to demonstrate your understanding of string manipulation and transformation. Simple regular expressions are encouraged.
  • The application should run in a standard web browser environment.
  • Focus on the core functionality. Performance optimizations beyond React.useMemo (if applicable) are not strictly required within the time limit.

Out of scope

  • Advanced Markdown features (e.g., links, images, tables, code blocks, blockquotes, ordered lists).
  • Rich text editor controls (e.g., bold/italic buttons).
  • Saving or loading content (persistence).
  • Complex responsive design beyond a basic two-pane layout.
  • Cross-site scripting (XSS) sanitization for dangerouslySetInnerHTML is not expected for this problem, as the parsing logic is controlled internally.

What interviewers evaluate

  • Functional Correctness: Ability to accurately parse and render the specified Markdown syntax into HTML.
  • React Proficiency: Effective use of React state management and component lifecycle for real-time updates.
  • Code Quality: Clean, readable, and modular code structure, adhering to React best practices.
  • Problem-Solving: Approach to string manipulation and transformation for parsing Markdown.

Loading editor...