Skip to content

Commit 39a369c

Browse files
authored
Merge pull request #5 from craigraphics/save-file-computer
Ability to save markdown file to computer
2 parents 8140a6b + 31603d5 commit 39a369c

File tree

5 files changed

+70
-21
lines changed

5 files changed

+70
-21
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<html lang="en" class="transition-colors duration-200">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
5+
<link rel="icon" type="image/svg+xml" href="/markdown.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Vite + React + TS</title>
7+
<title>MarkItDown</title>
88
</head>
99
<body>
1010
<div id="root"></div>

public/markdown.svg

Lines changed: 20 additions & 0 deletions
Loading

public/vite.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/App.tsx

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Markdown from 'react-markdown';
33
import { ThemeProvider } from './context/ThemeContext';
44
import ThemeToggle from './components/presentational/ThemeToggle';
55
import MarkdownEditor from './components/MarkdownEditor';
6+
import { saveAsFile } from './utils/fileHelpers';
7+
68
import './App.css';
79

810
function App() {
@@ -13,29 +15,47 @@ function App() {
1315
return () => clearTimeout(timeout);
1416
};
1517

18+
const handleSave = () => {
19+
saveAsFile(userMarkdown, 'markdown-content.md', 'text/markdown');
20+
};
21+
1622
return (
1723
<ThemeProvider>
18-
<main className="flex flex-col h-screen bg-white dark:bg-[#212424] text-gray-800 dark:text-gray-200 transition-colors duration-200">
19-
<div className="container mx-auto px-4 py-8">
20-
<div className="flex justify-between items-center mb-6">
21-
<h1 className="text-4xl font-bold text-gray-900 dark:text-white">Markdown Online Formatter</h1>
24+
<div className="flex flex-col h-screen bg-white dark:bg-[#212424] text-gray-800 dark:text-gray-200 transition-colors duration-200">
25+
<nav className="bg-gray-100 dark:bg-gray-800 shadow-md">
26+
<div className="container mx-auto px-4 py-3 flex justify-between items-center">
27+
<h1 className="text-2xl font-bold text-gray-900 dark:text-white">MarkItDown</h1>
2228
<ThemeToggle />
2329
</div>
24-
<p className="text-lg mb-6 text-gray-600 dark:text-gray-300 text-left">
25-
This tool allows you to format text in real-time as you type. Enter your text in the field provided, and the
26-
corresponding Markdown will be generated automatically. To apply formatting, simply select the text and
27-
click the desired style button.
28-
</p>
29-
</div>
30-
31-
<div className="flex-grow flex flex-col md:flex-row gap-4 px-4 pb-4">
32-
<MarkdownEditor onTextChange={handleTextChange} />
33-
34-
<div className="flex-1 p-4 bg-gray-100 dark:bg-gray-800 border border-gray-300 dark:border-gray-700 overflow-auto">
35-
<Markdown className="prose dark:prose-invert max-w-none markdown-custom">{userMarkdown}</Markdown>
30+
</nav>
31+
32+
<main className="flex-grow flex flex-col overflow-hidden">
33+
<div className="container mx-auto px-4 py-6">
34+
<h2 className="text-xl font-semibold mb-2">Markdown Online Formatter</h2>
35+
<p className="text-sm mb-4 text-gray-600 dark:text-gray-300">
36+
This tool allows you to format text in real-time as you type. Enter your text in the field provided, and
37+
the corresponding Markdown will be generated automatically. To apply formatting, simply select the text
38+
and click the desired style button.
39+
</p>
40+
41+
<button
42+
className="flex items-center justify-center flex-grow basis-0 min-w-[40px] h-8 bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-white font-medium rounded-md hover:bg-gray-300 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-opacity-50 transition-colors duration-200 p-2"
43+
onClick={handleSave}
44+
>
45+
Save as File
46+
</button>
47+
</div>
48+
49+
<div className="flex-grow flex flex-col md:flex-row gap-4 px-4 pb-4 overflow-auto">
50+
<MarkdownEditor onTextChange={handleTextChange} />
51+
52+
<div className="flex-1 p-4 bg-gray-100 dark:bg-gray-800 border border-gray-300 dark:border-gray-700 overflow-auto">
53+
<h3 className="dark:bg-gray-700 bg-gray-200 -m-4 mb-6 p-2 dark:text-gray-300 font-semibold">Preview</h3>
54+
<Markdown className="prose dark:prose-invert max-w-none markdown-custom">{userMarkdown}</Markdown>
55+
</div>
3656
</div>
37-
</div>
38-
</main>
57+
</main>
58+
</div>
3959
</ThemeProvider>
4060
);
4161
}

src/utils/fileHelpers.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const saveAsFile = (content: string, filename: string, contentType: string) => {
2+
const a = document.createElement('a');
3+
const file = new Blob([content], { type: contentType });
4+
5+
a.href = URL.createObjectURL(file);
6+
a.download = filename;
7+
a.click();
8+
9+
URL.revokeObjectURL(a.href);
10+
};

0 commit comments

Comments
 (0)