ArunKr commited on
Commit
03479c0
·
verified ·
1 Parent(s): 3f3daa2

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +92 -74
index.html CHANGED
@@ -1,99 +1,117 @@
1
  <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
4
- <meta charset="UTF-8">
5
- <title>Markdown Editor & Publisher</title>
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <!-- Simple styling -->
 
 
 
 
 
8
  <style>
9
- body { margin: 0; font-family: sans-serif; display: flex; flex-direction: column; height: 100vh; }
10
- header { background: #333; color: #fff; padding: 0.5em 1em; display: flex; align-items: center; }
11
- header h1 { margin: 0; font-size: 1.2em; flex: 1; }
12
- header button { padding: 0.5em 1em; font-size: 1em; cursor: pointer; }
13
- main { flex: 1; display: flex; overflow: hidden; }
14
- textarea { width: 50%; border: none; padding: 1em; font-family: monospace; font-size: 1em; resize: none; outline: none; }
15
- #preview { width: 50%; padding: 1em; overflow-y: auto; border-left: 1px solid #ccc; }
16
- /* Basic Markdown styling */
17
- #preview h1 { border-bottom: 2px solid #eee; padding-bottom: 0.3em; }
18
- #preview pre { background: #f4f4f4; padding: 1em; overflow-x: auto; }
19
- #preview code { background: #f4f4f4; padding: 0.2em 0.4em; }
20
- #preview blockquote { border-left: 4px solid #ccc; padding-left: 1em; color: #666; }
21
  </style>
22
  </head>
23
- <body>
 
 
 
 
 
 
 
 
 
24
 
25
- <header>
26
- <h1>Markdown Editor & Publisher</h1>
27
- <button id="publishBtn">Publish → Download HTML</button>
28
- </header>
 
 
 
29
 
30
- <main>
31
- <textarea id="editor" placeholder="Type your Markdown here..."></textarea>
32
- <div id="preview"></div>
 
 
33
  </main>
34
 
35
- <!-- Marked.js from CDN for Markdown parsing -->
36
- <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
37
  <script>
 
 
 
 
 
 
 
 
 
38
  const editor = document.getElementById('editor');
39
  const preview = document.getElementById('preview');
40
- const publishBtn = document.getElementById('publishBtn');
41
 
42
- // Render Markdown to HTML
43
- function updatePreview() {
44
- const md = editor.value;
45
- preview.innerHTML = marked.parse(md, { breaks: true });
 
 
 
 
 
46
  }
47
 
48
- // Download rendered content as standalone HTML
49
- function publish() {
50
- const content = preview.innerHTML;
51
- const fullHtml = `
52
- <!DOCTYPE html>
53
- <html lang="en">
54
- <head>
55
- <meta charset="UTF-8">
56
- <title>Published Document</title>
57
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
58
- <style>
59
- body { font-family: sans-serif; padding: 2em; max-width: 800px; margin: auto; line-height: 1.6; }
60
- h1, h2, h3, h4 { margin-top: 1.4em; }
61
- pre { background: #f4f4f4; padding: 1em; overflow-x: auto; }
62
- code { background: #f4f4f4; padding: 0.2em 0.4em; }
63
- blockquote { border-left: 4px solid #ccc; padding-left: 1em; color: #666; margin: 1em 0; }
64
- </style>
65
- </head>
66
- <body>
67
- ${content}
68
- </body>
69
- </html>`;
70
 
71
- const blob = new Blob([fullHtml], { type: 'text/html' });
72
- const url = URL.createObjectURL(blob);
73
- const a = document.createElement('a');
74
- a.href = url;
75
- a.download = 'document.html';
76
- a.click();
77
- URL.revokeObjectURL(url);
78
  }
79
 
80
- // Event listeners
81
- editor.addEventListener('input', updatePreview);
82
- publishBtn.addEventListener('click', publish);
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
- // Initialize with a sample
85
- editor.value = `# Welcome
 
 
 
 
 
86
 
87
- Type *Markdown* on the left and see **HTML** on the right.
 
 
88
 
89
- - Live preview
90
- - Download as HTML
91
 
92
- \`\`\`js
93
- console.log('Hello, world!');
94
- \`\`\`
95
- `;
96
- updatePreview();
97
  </script>
98
  </body>
99
- </html>
 
1
  <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>DocSite Markdown Documentation</title>
7
+ <!-- Tailwind via CDN -->
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <!-- Icon library -->
10
+ <script src="https://unpkg.com/heroicons@2.0.18/dist/outline.js"></script>
11
+ <!-- Marked.js -->
12
+ <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
13
  <style>
14
+ /* custom scrollbar */
15
+ .scrollbar-thin::-webkit-scrollbar { width: 6px; }
16
+ .scrollbar-thin::-webkit-scrollbar-thumb { background-color: rgba(100,100,100,0.4); border-radius: 3px; }
 
 
 
 
 
 
 
 
 
17
  </style>
18
  </head>
19
+ <body class="h-screen flex overflow-hidden font-sans">
20
+ <!-- Sidebar: File Tree -->
21
+ <aside class="w-64 bg-gray-800 text-gray-200 p-4 flex flex-col">
22
+ <div class="flex items-center justify-between mb-4">
23
+ <h2 class="text-lg font-semibold">Pages</h2>
24
+ <button id="newPageBtn" class="p-1 hover:bg-gray-700 rounded"><svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path d="M12 4v16m8-8H4"/></svg></button>
25
+ </div>
26
+ <ul id="fileTree" class="flex-1 overflow-auto scrollbar-thin space-y-1"></ul>
27
+ <button id="deletePageBtn" class="mt-4 px-3 py-2 bg-red-600 hover:bg-red-700 rounded-md">Delete Page</button>
28
+ </aside>
29
 
30
+ <!-- Main Content: Editor & Preview -->
31
+ <main class="flex-1 flex flex-col">
32
+ <!-- Toolbar -->
33
+ <div class="flex items-center bg-gray-100 p-2 border-b">
34
+ <input id="pageTitle" class="flex-1 px-2 py-1 border rounded focus:outline-none" placeholder="Page Title..." />
35
+ <button id="saveBtn" class="ml-2 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded">Save</button>
36
+ </div>
37
 
38
+ <!-- Editor & Preview Panes -->
39
+ <div class="flex flex-1 overflow-hidden">
40
+ <textarea id="editor" class="w-1/2 p-4 text-sm font-mono outline-none border-r resize-none scrollbar-thin" placeholder="Write Markdown..."></textarea>
41
+ <div id="preview" class="w-1/2 p-4 overflow-auto scrollbar-thin prose max-w-none"></div>
42
+ </div>
43
  </main>
44
 
 
 
45
  <script>
46
+ // In-memory pages store using localStorage
47
+ let pages = JSON.parse(localStorage.getItem('docPages') || '{}');
48
+ let currentId = null;
49
+
50
+ const fileTree = document.getElementById('fileTree');
51
+ const newPageBtn = document.getElementById('newPageBtn');
52
+ const deletePageBtn = document.getElementById('deletePageBtn');
53
+ const saveBtn = document.getElementById('saveBtn');
54
+ const pageTitleInput = document.getElementById('pageTitle');
55
  const editor = document.getElementById('editor');
56
  const preview = document.getElementById('preview');
 
57
 
58
+ function renderTree() {
59
+ fileTree.innerHTML = '';
60
+ Object.keys(pages).forEach(id => {
61
+ const li = document.createElement('li');
62
+ li.textContent = pages[id].title;
63
+ li.className = 'px-2 py-1 hover:bg-gray-700 rounded cursor-pointer ' + (id === currentId ? 'bg-gray-700' : '');
64
+ li.onclick = () => loadPage(id);
65
+ fileTree.append(li);
66
+ });
67
  }
68
 
69
+ function loadPage(id) {
70
+ currentId = id;
71
+ const { title, content } = pages[id];
72
+ pageTitleInput.value = title;
73
+ editor.value = content;
74
+ updatePreview();
75
+ renderTree();
76
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
+ function updatePreview() {
79
+ preview.innerHTML = marked.parse(editor.value || '');
 
 
 
 
 
80
  }
81
 
82
+ newPageBtn.onclick = () => {
83
+ const id = Date.now().toString();
84
+ pages[id] = { title: 'Untitled', content: '' };
85
+ saveStore();
86
+ loadPage(id);
87
+ };
88
+
89
+ deletePageBtn.onclick = () => {
90
+ if (!currentId) return;
91
+ delete pages[currentId];
92
+ currentId = Object.keys(pages)[0] || null;
93
+ saveStore();
94
+ if (currentId) loadPage(currentId);
95
+ else { editor.value = ''; pageTitleInput.value = ''; preview.innerHTML = ''; renderTree(); }
96
+ };
97
 
98
+ saveBtn.onclick = () => {
99
+ if (!currentId) return alert('No page selected');
100
+ pages[currentId] = { title: pageTitleInput.value || 'Untitled', content: editor.value };
101
+ saveStore();
102
+ renderTree();
103
+ alert('Page saved!');
104
+ };
105
 
106
+ function saveStore() {
107
+ localStorage.setItem('docPages', JSON.stringify(pages));
108
+ }
109
 
110
+ editor.addEventListener('input', updatePreview);
 
111
 
112
+ // Initialize
113
+ renderTree();
114
+ if (!currentId && Object.keys(pages).length) loadPage(Object.keys(pages)[0]);
 
 
115
  </script>
116
  </body>
117
+ </html>