From 222dc9e92336faff1be9ac8895ddd0d519bbefa3 Mon Sep 17 00:00:00 2001 From: Deepak Giri Date: Sat, 5 Sep 2026 01:18:14 -0300 Subject: [PATCH] add markdown preview tool --- docusaurus.config.js | 4 + package.json | 5 +- src/pages/markdown-preview.js | 96 +++++++++++++ src/pages/markdown-preview.module.css | 200 ++++++++++++++++++++++++++ yarn.lock | 22 +++ 5 files changed, 325 insertions(+), 2 deletions(-) create mode 100644 src/pages/markdown-preview.js create mode 100644 src/pages/markdown-preview.module.css diff --git a/docusaurus.config.js b/docusaurus.config.js index 83292a0..ec4a3bf 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -79,6 +79,10 @@ module.exports = { label: 'QR Code Gen', to: 'qrcode', }, + { + label: 'Markdown to HTML Preview', + to: 'markdown-preview', + }, // { // label: 'Plain QR Code', // to: 'qrcode-plain', diff --git a/package.json b/package.json index 8579a34..41d22eb 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,11 @@ "@docusaurus/core": "3.10.2", "@docusaurus/preset-classic": "3.10.2", "classnames": "^2.2.6", - "qrcode": "^1.5.4", "qr-code-styling": "^1.9.2", + "qrcode": "^1.5.4", "react": "^18.3.1", - "react-dom": "^18.3.1" + "react-dom": "^18.3.1", + "react-markdown": "^10.1.0" }, "// TODO": "Remove these temporary overrides once Docusaurus updates its transitive dependencies to patched versions.", "resolutions": { diff --git a/src/pages/markdown-preview.js b/src/pages/markdown-preview.js new file mode 100644 index 0000000..e7553ed --- /dev/null +++ b/src/pages/markdown-preview.js @@ -0,0 +1,96 @@ +import React, { useState } from 'react'; +import ReactMarkdown from 'react-markdown'; +import Layout from '@theme/Layout'; +import styles from './markdown-preview.module.css'; + +const defaultMarkdown = `# Welcome to Markdown Previewer + +## Live Preview +Type or paste your markdown on the left, and see the HTML preview on the right. + +### Features +- **Real-time preview** as you type +- **Syntax highlighting** for code blocks +- **Tables**, lists, links, and more + +### Code Example +\`\`\`javascript +function hello(name) { + console.log(\`Hello, \${name}!\`); +} +\`\`\` + +> This is a blockquote. You can use it to highlight important information. + +--- + +### Try it! +Edit the markdown on the left to see the preview update instantly. +`; + +export default function MarkdownPreview() { + const [markdown, setMarkdown] = useState(defaultMarkdown); + + const handleClear = () => { + setMarkdown(''); + }; + + const handleReset = () => { + setMarkdown(defaultMarkdown); + }; + + const handleDownload = () => { + const element = document.createElement('a'); + const file = new Blob([markdown], { type: 'text/markdown' }); + element.href = URL.createObjectURL(file); + element.download = 'markdown.md'; + document.body.appendChild(element); + element.click(); + document.body.removeChild(element); + }; + + return ( + +
+
+

Markdown Preview

+

Write markdown on the left, see HTML preview on the right

+
+ +
+ + + +
+ +
+
+

Your Markdown Input

+