All Challenges

Markdown Live Previewer (XSS-Safe Parser)

JavaScriptMediumGitHubHashnodeNotion
45:00

Problem Brief

Convert headings (`#`, `##`), bold (`**text**`), inline code (`` `code` ``), and lists into HTML live while escaping raw HTML tags safely.

Requirements

  • Escape `<` and `>` before transforming Markdown rules so `<script>` never executes.
  • Transform `# Title` -> `<h1>`, `**text**` -> `<strong>`, and `` `code` `` -> `<code>`.
  • Render compiled output inside `[data-testid="md-preview"]` on every `input`.
Progressive Hints (1)
  • First replace `&`, `<`, `>`, then run line/inline regex transforms safely.
Reference Solution

Stuck? Load the verified reference code into your editor.

Automated Test Suite

2 Test Cases Ready
  • Transforms headings, bold, and inline codeRenders h1, strong, and code tags inside preview
  • Escapes injected <script> tags against XSSRaw <img onerror> or <script> stays harmless text
solution.html
Live Sandboxed Previewiframe sandbox
Starter template loaded — add your <script> logic in the editor (or open Reference Solution) to make the widget interactive.