Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
96 changes: 96 additions & 0 deletions src/pages/markdown-preview.js
Original file line number Diff line number Diff line change
@@ -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 (
<Layout
title="Markdown to HTML Previewer"
description="Live markdown to HTML preview tool"
>
<div className={styles.container}>
<div className={styles.header}>
<h1>Markdown Preview</h1>
<p>Write markdown on the left, see HTML preview on the right</p>
</div>

<div className={styles.controls}>
<button onClick={handleClear} className={styles.button}>
Clear
</button>
<button onClick={handleReset} className={styles.button}>
Reset
</button>
<button onClick={handleDownload} className={styles.button}>
Download
</button>
</div>

<div className={styles.preview}>
<div className={styles.editor}>
<h2>Your Markdown Input</h2>
<textarea
value={markdown}
onChange={(e) => setMarkdown(e.target.value)}
placeholder="Enter your markdown here..."
className={styles.textarea}
/>
</div>

<div className={styles.output}>
<h2>HTML Preview</h2>
<div className={styles.htmlPreview}>
<ReactMarkdown>{markdown}</ReactMarkdown>
</div>
</div>
</div>
</div>
</Layout>
);
}
200 changes: 200 additions & 0 deletions src/pages/markdown-preview.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
.container {
padding: 2rem 1rem;
max-width: 1400px;
margin: 0 auto;
}

.header {
text-align: center;
margin-bottom: 2rem;
}

.header h1 {
font-size: 2.5rem;
margin-bottom: 0.5rem;
}

.header p {
font-size: 1.1rem;
color: #666;
}

.controls {
display: flex;
gap: 0.5rem;
margin-bottom: 2rem;
justify-content: center;
flex-wrap: wrap;
}

.button {
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
background-color: #0066cc;
color: white;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background-color 0.2s;
}

.button:hover {
background-color: #0052a3;
}

.button:active {
background-color: #003d7a;
}

.preview {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 2rem;
min-height: 600px;
}

.editor,
.output {
display: flex;
flex-direction: column;
}

.editor h2,
.output h2 {
margin-top: 0;
margin-bottom: 1rem;
font-size: 1.3rem;
border-bottom: 2px solid #0066cc;
padding-bottom: 0.5rem;
}

.textarea {
flex: 1;
padding: 1rem;
border: 2px solid #ddd;
border-radius: 4px;
font-family: 'Courier New', monospace;
font-size: 0.95rem;
line-height: 1.5;
resize: none;
transition: border-color 0.2s;
}

.textarea:focus {
outline: none;
border-color: #0066cc;
box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.htmlPreview {
flex: 1;
overflow-y: auto;
padding: 1rem;
border: 2px solid #ddd;
border-radius: 4px;
background-color: var(--ifm-background-color);
color: var(--ifm-font-color-base);
line-height: 1.6;
}

[data-theme='dark'] .htmlPreview {
border-color: #444;
}

.htmlPreview h1,
.htmlPreview h2,
.htmlPreview h3,
.htmlPreview h4,
.htmlPreview h5,
.htmlPreview h6 {
margin-top: 1.5rem;
margin-bottom: 0.5rem;
}

.htmlPreview h1:first-child,
.htmlPreview h2:first-child,
.htmlPreview h3:first-child {
margin-top: 0;
}

.htmlPreview code {
background-color: var(--ifm-code-background);
padding: 0.2rem 0.4rem;
border-radius: 3px;
font-family: 'Courier New', monospace;
font-size: 0.9em;
}

.htmlPreview pre {
background-color: #2d2d2d;
color: #f8f8f2;
padding: 1rem;
border-radius: 4px;
overflow-x: auto;
margin: 1rem 0;
}

.htmlPreview pre code {
background-color: transparent;
padding: 0;
color: inherit;
}

.htmlPreview blockquote {
border-left: 4px solid var(--ifm-link-color);
padding-left: 1rem;
margin-left: 0;
color: var(--ifm-color-emphasis-700);
}

.htmlPreview ul,
.htmlPreview ol {
margin: 1rem 0;
padding-left: 2rem;
}

.htmlPreview table {
width: 100%;
border-collapse: collapse;
margin: 1rem 0;
}

.htmlPreview table th,
.htmlPreview table td {
border: 1px solid var(--ifm-color-emphasis-300);
padding: 0.75rem;
text-align: left;
}

.htmlPreview table th {
background-color: var(--ifm-code-background);
font-weight: bold;
}

.htmlPreview a {
color: #0066cc;
text-decoration: none;
}

.htmlPreview a:hover {
text-decoration: underline;
}

/* Responsive: stack on mobile */
@media (max-width: 768px) {
.preview {
grid-template-columns: 1fr;
gap: 1.5rem;
min-height: auto;
}

.editor,
.output {
min-height: 400px;
}

.header h1 {
font-size: 1.8rem;
}
}
22 changes: 22 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5219,6 +5219,11 @@ html-tags@^3.3.1:
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.3.1.tgz#a04026a18c882e4bba8a01a3d39cfe465d40b5ce"
integrity sha512-ztqyC3kLto0e9WbNp0aeP+M3kTt+nbaIveGmUxAtZa+8iFgKLUOD4YKM5j+f3QD89bra7UeumolZHKuOXnTmeQ==

html-url-attributes@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/html-url-attributes/-/html-url-attributes-3.0.1.tgz#83b052cd5e437071b756cd74ae70f708870c2d87"
integrity sha512-ol6UPyBWqsrO6EJySPz2O7ZSr856WDrEzM5zMqp+FJJLGMW35cLYmmZnl0vztAZxRUoNZJFTCohfjuIJ8I4QBQ==

html-void-elements@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/html-void-elements/-/html-void-elements-3.0.0.tgz#fc9dbd84af9e747249034d4d62602def6517f1d7"
Expand Down Expand Up @@ -7848,6 +7853,23 @@ react-loadable-ssr-addon-v5-slorber@^1.0.3:
dependencies:
"@types/react" "*"

react-markdown@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/react-markdown/-/react-markdown-10.1.0.tgz#e22bc20faddbc07605c15284255653c0f3bad5ca"
integrity sha512-qKxVopLT/TyA6BX3Ue5NwabOsAzm0Q7kAPwq6L+wWDwisYs7R8vZ0nRXqq6rkueboxpkjvLGU9fWifiX/ZZFxQ==
dependencies:
"@types/hast" "^3.0.0"
"@types/mdast" "^4.0.0"
devlop "^1.0.0"
hast-util-to-jsx-runtime "^2.0.0"
html-url-attributes "^3.0.0"
mdast-util-to-hast "^13.0.0"
remark-parse "^11.0.0"
remark-rehype "^11.0.0"
unified "^11.0.0"
unist-util-visit "^5.0.0"
vfile "^6.0.0"

react-router-config@^5.1.1:
version "5.1.1"
resolved "https://registry.npmjs.org/react-router-config/-/react-router-config-5.1.1.tgz#0f4263d1a80c6b2dc7b9c1902c9526478194a988"
Expand Down
Loading