Role: You are an expert full-stack web developer. Your task is to build a complete,…
- User
Role: You are an expert full-stack web developer. Your task is to build a complete, self-contained web application based on the user story and technical specifications below.
Project Title: "Live Markdown Previewer"
User Story: As a content creator, I want a simple, clean web page where I can type Markdown text in one panel and see the rendered HTML output in real-time in a second panel. The tool should be easy to use, visually appealing with a dark theme, and work well on both my desktop and mobile devices. Detailed Requirements:
-
Core Functionality (The "What"):
The page must have two main vertical panels.
Left Panel (Input): A element where the user can write or paste Markdown text. It should have a placeholder like "Type your Markdown here...".
Right Panel (Output): A element that will display the HTML generated from the Markdown in the left panel.
Real-time Conversion: The HTML in the right panel must update automatically as the user types in the . This should be an instant, "live" preview.
Markdown Parsing: Use the marked.js library to handle the Markdown-to-HTML conversion. You must load this library from a CDN.
-
Layout and Styling (The "How it Looks"):
Overall Layout: Use CSS Flexbox to create the side-by-side two-panel layout. The panels should each take up 50% of the available width and 100% of the viewport height (minus some padding).
Responsive Design: On screen widths less than 768px (i.e., mobile devices), the layout must switch from side-by-side to a stacked, vertical layout. The Markdown input panel should be on top, and the HTML output panel below it.
Theme: Implement a modern dark theme.
Background: A very dark grey (e.g., #1a1a1a). Text: A light grey or off-white (e.g., #f0f0f0). Input Panel: Use a clean, monospaced font (like Fira Code, Source Code Pro, or a standard monospace). Output Panel: Style the rendered HTML for readability. For example: <h1>, <h2> tags should be a distinct color or have a bottom border. <code> blocks should have a slightly different background color (e.g., #2b2b2b) and padding. Blockquotes (<blockquote>) should be indented and have a left border.Headers: Each panel should have a simple title: "Markdown" for the left and "Preview" for the right.
-
Technical Specifications (The "How to Build It"):
Single File: All HTML, CSS, and JavaScript must be contained within a single index.html file. Use internal and tags.
No Build Tools: The final code must run directly in a web browser without needing any build steps, package managers (like npm), or local servers.
External Library: Load marked.js from its official CDN link within the of the HTML document.
Code Quality: Your code should be well-commented, especially the JavaScript section, to explain the logic for capturing input and updating the preview.
-
- Assistant
Live Markdown Previewer
Here's a complete, self-contained web application that meets all your requirements. The solution is implemented in a single HTML file with embedded CSS and JavaScript, using marked.js from a CDN for Markdown parsing.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Live Markdown Previewer</title> <!-- Load marked.js from CDN --> <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> <style> /* Base styles and dark theme */ :root { --bg-color: #1a1a1a; --text-color: #f0f0f0; --panel-bg: #252525; --code-bg: #2b2b2b; --border-color: #3a3a3a; --accent-color: #4dabf7; } * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(--bg-color); color: var(--text-color); line-height: 1.6; padding: 20px; min-height: 100vh; } /* Main container layout */ .container { display: flex; flex-direction: row; gap: 20px; height: calc(100vh - 40px); } /* Panel styles */ .panel { flex: 1; display: flex; flex-direction: column; background-color: var(--panel-bg); border-radius: 8px; border: 1px solid var(--border-color); overflow: hidden; } .panel-header { padding: 12px 15px; background-color: var(--bg-color); border-bottom: 1px solid var(--border-color); font-size: 1.2rem; } /* Input panel specific styles */ .input-panel { font-family: 'Fira Code', 'Source Code Pro', monospace; } .input-panel textarea { flex: 1; background-color: transparent; color: var(--text-color); border: none; padding: 15px; resize: none; font-family: inherit; font-size: 1rem; outline: none; } .input-panel textarea::placeholder { color: #6c757d; } /* Output panel specific styles */ .output-panel { padding: 15px; overflow-y: auto; } /* Markdown rendering styles */ .output-panel h1 { color: var(--accent-color); border-bottom: 1px solid var(--border-color); padding-bottom: 10px; margin-bottom: 15px; } .output-panel h2 { color: var(--accent-color); border-bottom: 1px solid var(--border-color); padding-bottom: 8px; margin-bottom: 12px; } .output-panel h3 { color: var(--accent-color); margin-bottom: 10px; } .output-panel code { background-color: var(--code-bg); padding: 2px 4px; border-radius: 3px; font-family: monospace; } .output-panel pre { background-color: var(--code-bg); padding: 15px; border-radius: 5px; overflow-x: auto; } .output-panel blockquote { border-left: 3px solid var(--accent-color); padding-left: 15px; margin-left: 0; color: #a0a0a0; font-style: italic; } .output-panel ul, .output-panel ol { margin-bottom: 15px; } .output-panel li { margin-bottom: 5px; } .output-panel a { color: var(--accent-color); text-decoration: none; } .output-panel a:hover { text-decoration: underline; } /* Responsive layout for mobile */ @media (max-width: 768px) { .container { flex-direction: column; height: auto; min-height: calc(100vh - 40px); } .panel { height: 50vh; } } </style> </head> <body> <div class="container"> <!-- Input Panel --> <div class="panel input-panel"> <div class="panel-header">Markdown</div> <textarea id="markdown-input" placeholder="Type your Markdown here..."></textarea> </div> <!-- Output Panel --> <div class="panel output-panel"> <div class="panel-header">Preview</div> <div id="preview-output"></div> </div> </div> <script> // Wait for the DOM to be fully loaded before executing JavaScript document.addEventListener('DOMContentLoaded', function() { // Get references to the DOM elements we'll be working with const markdownInput = document.getElementById('markdown-input'); const previewOutput = document.getElementById('preview-output'); // Set up the initial preview with some example Markdown const initialMarkdown = `# Welcome to the Live Markdown Previewer! This tool lets you write Markdown and see the rendered HTML in real-time. ## Features - **Live preview** as you type - Supports all standard Markdown syntax - Dark theme for comfortable viewing - Responsive design for all devices ## Example Code Block \`\`\`javascript function helloWorld() { console.log("Hello, world!"); } \`\`\` ## Blockquote Example > "The only way to do great work is to love what you do." > — Steve Jobs ## List Example 1. First item 2. Second item 3. Third item - Unordered item - Another unordered item [Visit Markdown Guide](https://www.markdownguide.org/) for more syntax examples.`; // Set the initial content in the textarea markdownInput.value = initialMarkdown; // Function to update the preview function updatePreview() { // Get the current Markdown content const markdownText = markdownInput.value; // Convert Markdown to HTML using marked.js // We use marked.parse() (or marked() in older versions) to convert the text // The second parameter allows us to configure options const htmlOutput = marked.parse(markdownText, { // Enable GitHub Flavored Markdown gfm: true, // Allow HTML tags in the source breaks: true }); // Update the preview panel with the generated HTML previewOutput.innerHTML = htmlOutput; } // Set up the event listener for input changes // We use 'input' event instead of 'keyup' to catch all changes including paste operations markdownInput.addEventListener('input', function() { // Call our update function whenever the input changes updatePreview(); }); // Initialize the preview with the default content updatePreview(); }); </script> </body> </html>Key Features Implemented:
-
Core Functionality:
- Two vertical panels (input and output)
- Real-time Markdown to HTML conversion using marked.js from CDN
- Automatic updates as the user types
-
Layout and Styling:
- Dark theme with carefully chosen colors
- Responsive design that switches to vertical layout on mobile
- Clean, modern styling for both input and output panels
- Special styling for Markdown elements (headers, code blocks, blockquotes, etc.)
-
Technical Implementation:
- Single self-contained HTML file with embedded CSS and JavaScript
- No build tools required - works directly in any modern browser
- Well-commented JavaScript explaining the logic
- Initial example content to demonstrate capabilities
The application is ready to use - simply copy this code into an HTML file and open it in any modern web browser. The preview updates in real-time as you type Markdown in the left panel.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.