Frontend School

Simple Markdown Editor: Bold Text

Machine Coding
easy

Simple Markdown Editor: Bold Text

Easy
Rich Text Editing
UI
React
State Management
String Manipulation

Overview

At Ola, clear and effective communication is paramount, especially within our internal tools. We're building a lightweight text editor for our team's project management platform. This problem challenges you to implement a core feature of rich text editing: applying bold formatting to selected text, mirroring a common markdown-like syntax. This exercise will assess your ability to manage UI state, handle user interactions, and perform basic text manipulation.

What you need to do / Task

Your goal is to build a simple React component that allows users to type text, select a portion of it, and apply bold formatting using a button.

  1. Render Editor Components: Display a textarea for text input and a "Bold" button.
  2. Implement Bold Formatting: When the "Bold" button is clicked:
    • Identify the currently selected text within the textarea.
    • Wrap the selected text with ** on both sides (e.g., hello becomes **hello**).
    • Update the textarea's value with the newly formatted text. Ensure the cursor position and selection are maintained or reset appropriately after formatting.
  3. Live Preview: Below the editor, display a live preview of the text. Any text wrapped with ** in the textarea should be rendered as visually bolded HTML (e.g., <strong>).

UI/UX expectations

  • The textarea should be clearly visible and allow multi-line input.
  • The "Bold" button should be easily clickable, perhaps positioned near the textarea.
  • A dedicated area below the textarea should display the formatted preview.
  • Basic styling to differentiate the editor from the preview is encouraged but not strictly required for functionality. Accessibility considerations for button labels (e.g., aria-label) are a good practice.

Acceptance criteria

  • A textarea and a "Bold" button are rendered on the screen.
  • Typing in the textarea updates its content.
  • The live preview area updates in real-time as text is typed or formatted.
  • When a user selects a portion of text in the textarea and clicks "Bold", the selected text is wrapped with ** markers in the textarea's value.
  • The live preview correctly renders text marked with ** as bold using <strong> HTML tags.
  • If no text is selected when "Bold" is clicked, the action should ideally do nothing or insert **** and place the cursor in between (handling either is acceptable for this problem).

Constraints

Constraints & assumptions

  • You must use React for this implementation.
  • You are not allowed to use any external rich text editor libraries (e.g., Draft.js, Slate.js, TinyMCE). All logic for formatting and rendering should be custom.
  • The focus is on the core functionality; extensive error handling or edge-case validation is not required unless it directly impacts the core task.
  • Assume standard browser environments where selectionStart and selectionEnd properties are available on textarea elements.

Out of scope

  • Implementing multiple formatting options (e.g., italic, underline, lists).
  • Undo/redo functionality.
  • Advanced markdown parsing for complex structures (e.g., headers, links, code blocks).
  • Real-time collaborative editing.

What interviewers evaluate

  • Component Structure & State Management: How well the React component is structured and how effectively state is managed for the editor content and interactions.
  • Event Handling & DOM Interaction: Proficiency in handling user events (button clicks, text input) and interacting with native DOM elements like textarea to retrieve selection information.
  • String Manipulation Logic: Correctness and efficiency of the logic to modify the text string based on user selection.
  • Rendering & HTML Transformation: Ability to transform the markdown-like text into appropriate HTML for display in the preview.

Loading editor...