Frontend School

Interactive Markdown Previewer

Machine Coding
medium

Interactive Markdown Previewer

Medium
React
Frontend
UI
State Management
String Manipulation
Markdown

Overview

Salesforce applications frequently require users to input and display rich text content, from knowledge articles to Chatter posts. Building a robust text editor with real-time feedback is a common challenge. This problem focuses on developing a simplified interactive markdown previewer, demonstrating your ability to manage UI state, handle user input, and implement basic text transformation logic in a React environment.

What you need to do / Task

Your primary task is to build a React component that allows users to type markdown text into an input area and see a live HTML preview of that markdown in an adjacent display area.

  1. Input Area: Create a textarea element where users can type markdown.
  2. Preview Area: Create a display area (e.g., a div) that renders the parsed HTML version of the markdown entered in the input area.
  3. Real-time Updates: The preview area must update immediately as the user types in the textarea.
  4. Markdown Parsing: Implement logic to parse and convert the following basic markdown syntax into corresponding HTML:
    • Headers:
      • # Heading 1 -> <h1>Heading 1</h1>
      • ## Heading 2 -> <h2>Heading 2</h2>
      • ### Heading 3 -> <h3>Heading 3</h3>
    • Emphasis:
      • **bold text** -> <strong>bold text</strong>
      • *italic text* -> <em>italic text</em>
    • Unordered Lists:
      • - List item 1 -> <ul><li>List item 1</li></ul>
      • - List item 2 -> <ul><li>List item 2</li></ul>
      • (Each list item should be on a new line and start with a hyphen. Consecutive list items should be grouped into a single <ul> block.)

UI/UX expectations

  • Layout: The input textarea and the preview area should be displayed side-by-side, occupying roughly equal horizontal space. Use a clean, responsive layout (e.g., flexbox or grid).
  • Input: The textarea should be clearly distinguishable and have an appropriate aria-label for accessibility.
  • Preview: The preview area should clearly display the rendered HTML. It should not be editable.
  • Visual Separation: A clear visual separator (e.g., a border or background difference) between the input and preview sections.

Acceptance criteria

  • The textarea for markdown input is fully editable.
  • The preview area updates instantly whenever the content in the textarea changes.
  • Single hash (#) followed by text renders correctly as an <h1>.
  • Double hash (##) followed by text renders correctly as an <h2>.
  • Triple hash (###) followed by text renders correctly as an <h3>.
  • Text enclosed in double asterisks (**text**) renders correctly as <strong>.
  • Text enclosed in single asterisks (*text*) renders correctly as <em>.
  • Lines starting with a hyphen (- ) render correctly as <li> elements within a <ul>. Multiple consecutive list items are grouped into a single <ul>.
  • The overall layout is responsive and provides a good user experience.

Constraints

Constraints & assumptions

  • You must use React.js for this problem.
  • No external markdown parsing libraries (e.g., marked, markdown-it, react-markdown) are allowed. You are expected to implement the parsing logic yourself using basic string manipulation (e.g., split, replace, regex).
  • Focus only on the specified markdown syntax features. Do not implement additional markdown features.
  • The application runs in a modern web browser environment.
  • Assume input content will be relatively small (e.g., a few paragraphs, not a large document).
  • No network requests or backend integration are required.
  • Basic React state management (useState) is sufficient. No need for global state management libraries.

Out of scope

  • Advanced markdown features (e.g., links, images, code blocks, blockquotes, tables).
  • Syntax highlighting within the input editor.
  • Undo/redo functionality.
  • Saving or loading markdown content.
  • Full cross-browser compatibility testing beyond modern evergreen browsers.

What interviewers evaluate

  • React Fundamentals: Correct use of React components, state management (useState), and event handling.
  • Algorithm Design: Effective and efficient implementation of the markdown parsing logic using string manipulation.
  • Code Quality: Readability, maintainability, and adherence to common best practices (e.g., clear function names, appropriate component separation).
  • UI/UX Implementation: Adherence to specified layout, responsiveness, and accessibility guidelines.
  • Problem Solving: Ability to break down the problem and implement a functional solution within the time constraints.

Loading editor...