Write a code for a Markdown editor, the website should be split in half, the left side should be the editor, the right side should be the preview (in-real time), give it Dracula dark theme. Don't use any external library, do it on your own with your coding knowledge...
Assistant
Sure! Below is a complete, self-contained implementation of a Markdown editor with a real-time preview, styled with the Dracula dark theme. The layout is split into two halves: the left side contains the editor, and the right side displays the preview. This implementation uses plain HTML, CSS, and JavaScript without any external libraries.
Features:
Real-time Preview: As you type markdown in the editor on the left, the formatted HTML preview appears instantly on the right.
Dracula Dark Theme: The entire interface is styled with the Dracula color scheme for a modern and visually appealing look.
Basic Markdown Support: The parser supports headings, bold, italics, links, inline code, code blocks, blockquotes, unordered and ordered lists.
The <main> section is divided into two <div> elements:
.editor: Contains a <textarea> where users can type their Markdown.
.preview: Displays the rendered HTML in real-time.
CSS Styling:
The Dracula theme is implemented using CSS variables for easy color management.
The layout uses Flexbox to split the screen into two equal halves.
The .editor and .preview sections have distinct background colors and styling to differentiate them.
Basic Markdown elements like headings, lists, blockquotes, code blocks, etc., are styled to match the Dracula theme.
JavaScript Markdown Parser:
A simple Markdown parser is implemented using regular expressions. It handles:
Escaping HTML tags to prevent injection.
Code blocks enclosed in triple backticks (```).
Inline code using single backticks.
Headings ranging from <h1> to <h3>.
Bold, italic, and combined bold-italic text.
Blockquotes using the > symbol.
Links formatted as [text](url).
Unordered (*, +, -) and ordered lists.
The parseMarkdown function converts the Markdown text to HTML.
An event listener on the <textarea> updates the preview in real-time as the user types.
Notes:
This Markdown parser covers common Markdown syntax but doesn't handle all edge cases or more advanced features. For a production environment, consider using a comprehensive Markdown library like marked.js or showdown.js.
The styling can be further enhanced to handle more Markdown elements and improve responsiveness.
Feel free to copy the above code into an .html file and open it in your browser to see the Markdown editor in action!