Core Functionality Breakdown
Marked.js Integration: We use
marked.parse(input.value)to transform plain text into HTML. This handles lists, tables, bolding, and links automatically.Live Toolbar: The
insertText()function manipulates the cursor position (selectionStart) to wrap selected text in Markdown syntax (e.g., adding**for Bold).Sync Scroll: It calculates the scroll percentage of the input area and applies that same ratio to the preview area, ensuring your "view" stays roughly aligned.
Responsive Panes: * Desktop: Side-by-side view using
flex: 1.Mobile: Stacked view (Top/Bottom) via
flex-direction: columnat the 768px breakpoint.
AdSense Placement: * Top Banner: High visibility for revenue.
Bottom Banner: Non-intrusive placement for long editing sessions.
CSS Note: Fixed
min-heightfor ad units prevents "layout shift" when ads load.
How to use this:
Replace
ca-pub-YOUR_CLIENT_IDwith your actual AdSense ID.You can extend the
previewCSS to include specific themes (like GitHub's dark mode or a classic paper style).