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 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Portable Offline Markdown Viewer</title>
|
| 7 |
+
<style>
|
| 8 |
+
body, html {
|
| 9 |
+
margin: 0;
|
| 10 |
+
padding: 0;
|
| 11 |
+
height: 100%;
|
| 12 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 13 |
+
overflow: hidden; /* Prevent body scrollbars when panes are full height */
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.container {
|
| 17 |
+
display: flex;
|
| 18 |
+
height: 100vh; /* Full viewport height */
|
| 19 |
+
width: 100vw; /* Full viewport width */
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.pane {
|
| 23 |
+
flex-grow: 1; /* Panes share space equally by default */
|
| 24 |
+
flex-basis: 0; /* Allow flex-grow to distribute space from a zero basis */
|
| 25 |
+
overflow: auto; /* Add scrollbars if content overflows */
|
| 26 |
+
padding: 15px;
|
| 27 |
+
box-sizing: border-box;
|
| 28 |
+
height: 100%; /* Make panes take full height of container */
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
#input-pane {
|
| 32 |
+
background-color: #fdfdfd;
|
| 33 |
+
border-right: 1px solid #e0e0e0; /* Subtle border */
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
#markdown-input {
|
| 37 |
+
width: 100%;
|
| 38 |
+
height: 100%;
|
| 39 |
+
border: 1px solid #d1d5da;
|
| 40 |
+
box-sizing: border-box;
|
| 41 |
+
padding: 10px;
|
| 42 |
+
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
| 43 |
+
font-size: 14px;
|
| 44 |
+
line-height: 1.5;
|
| 45 |
+
resize: none; /* Disable textarea's own resizer */
|
| 46 |
+
background-color: #fff;
|
| 47 |
+
color: #24292e;
|
| 48 |
+
}
|
| 49 |
+
#markdown-input:focus {
|
| 50 |
+
outline: none;
|
| 51 |
+
border-color: #0366d6;
|
| 52 |
+
box-shadow: 0 0 0 2px rgba(3, 102, 214, 0.3);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
#output-pane {
|
| 57 |
+
background-color: #ffffff;
|
| 58 |
+
padding-left: 20px; /* More space from resizer */
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
#html-output {
|
| 62 |
+
width: 100%;
|
| 63 |
+
height: 100%;
|
| 64 |
+
color: #24292e;
|
| 65 |
+
line-height: 1.6;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/* Basic Markdown Styling (inspired by GitHub) */
|
| 69 |
+
#html-output h1, #html-output h2, #html-output h3, #html-output h4, #html-output h5, #html-output h6 {
|
| 70 |
+
margin-top: 24px;
|
| 71 |
+
margin-bottom: 16px;
|
| 72 |
+
font-weight: 600;
|
| 73 |
+
line-height: 1.25;
|
| 74 |
+
border-bottom: 1px solid #eaecef;
|
| 75 |
+
padding-bottom: 0.3em;
|
| 76 |
+
}
|
| 77 |
+
#html-output h1 { font-size: 2em; }
|
| 78 |
+
#html-output h2 { font-size: 1.5em; }
|
| 79 |
+
#html-output h3 { font-size: 1.25em; }
|
| 80 |
+
#html-output p { margin-top: 0; margin-bottom: 16px; }
|
| 81 |
+
#html-output ul, #html-output ol { margin-top: 0; margin-bottom: 16px; padding-left: 2em; }
|
| 82 |
+
#html-output li > p { margin-bottom: 0.2em; } /* Less space for p inside li */
|
| 83 |
+
#html-output blockquote {
|
| 84 |
+
margin: 0 0 16px 0;
|
| 85 |
+
padding: 0 1em;
|
| 86 |
+
color: #6a737d;
|
| 87 |
+
border-left: 0.25em solid #dfe2e5;
|
| 88 |
+
}
|
| 89 |
+
#html-output code {
|
| 90 |
+
padding: 0.2em 0.4em;
|
| 91 |
+
margin: 0;
|
| 92 |
+
font-size: 85%;
|
| 93 |
+
background-color: rgba(27,31,35,0.05);
|
| 94 |
+
border-radius: 3px;
|
| 95 |
+
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
| 96 |
+
}
|
| 97 |
+
#html-output pre {
|
| 98 |
+
padding: 16px;
|
| 99 |
+
overflow: auto;
|
| 100 |
+
font-size: 85%;
|
| 101 |
+
line-height: 1.45;
|
| 102 |
+
background-color: #f6f8fa;
|
| 103 |
+
border-radius: 3px;
|
| 104 |
+
margin-bottom: 16px;
|
| 105 |
+
word-wrap: normal; /* Allow horizontal scroll for long lines */
|
| 106 |
+
}
|
| 107 |
+
#html-output pre code {
|
| 108 |
+
padding: 0;
|
| 109 |
+
margin: 0;
|
| 110 |
+
font-size: 100%;
|
| 111 |
+
background-color: transparent;
|
| 112 |
+
border-radius: 0;
|
| 113 |
+
display: inline;
|
| 114 |
+
max-width: auto;
|
| 115 |
+
overflow: visible;
|
| 116 |
+
line-height: inherit;
|
| 117 |
+
word-wrap: normal;
|
| 118 |
+
}
|
| 119 |
+
#html-output table {
|
| 120 |
+
border-collapse: collapse;
|
| 121 |
+
margin-top: 0;
|
| 122 |
+
margin-bottom: 16px;
|
| 123 |
+
display: block;
|
| 124 |
+
width: max-content;
|
| 125 |
+
max-width: 100%;
|
| 126 |
+
overflow: auto;
|
| 127 |
+
}
|
| 128 |
+
#html-output th, #html-output td {
|
| 129 |
+
padding: 6px 13px;
|
| 130 |
+
border: 1px solid #dfe2e5;
|
| 131 |
+
}
|
| 132 |
+
#html-output th { font-weight: 600; }
|
| 133 |
+
#html-output hr {
|
| 134 |
+
height: 0.25em;
|
| 135 |
+
padding: 0;
|
| 136 |
+
margin: 24px 0;
|
| 137 |
+
background-color: #e1e4e8;
|
| 138 |
+
border: 0;
|
| 139 |
+
}
|
| 140 |
+
#html-output img { max-width: 100%; box-sizing: content-box; background-color: #fff; }
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
.resizer {
|
| 144 |
+
width: 10px;
|
| 145 |
+
background-color: #e0e0e0; /* Slightly darker for better visibility */
|
| 146 |
+
cursor: col-resize;
|
| 147 |
+
flex-shrink: 0; /* Prevent resizer from shrinking */
|
| 148 |
+
display: flex;
|
| 149 |
+
align-items: center;
|
| 150 |
+
justify-content: center;
|
| 151 |
+
position: relative; /* For pseudo-element positioning */
|
| 152 |
+
z-index: 10;
|
| 153 |
+
}
|
| 154 |
+
.resizer:hover {
|
| 155 |
+
background-color: #c0c0c0;
|
| 156 |
+
}
|
| 157 |
+
.resizer::before { /* Visual grip dots */
|
| 158 |
+
content: '⋮';
|
| 159 |
+
color: #666;
|
| 160 |
+
font-size: 14px;
|
| 161 |
+
line-height: 0; /* Center vertically */
|
| 162 |
+
}
|
| 163 |
+
</style>
|
| 164 |
+
<!-- Make sure marked.min.js is in the same folder as this HTML file -->
|
| 165 |
+
<script src="marked.min.js"></script>
|
| 166 |
+
</head>
|
| 167 |
+
<body>
|
| 168 |
+
<div class="container">
|
| 169 |
+
<div class="pane" id="input-pane">
|
| 170 |
+
<textarea id="markdown-input" placeholder="Paste or type Markdown here..."></textarea>
|
| 171 |
+
</div>
|
| 172 |
+
<div class="resizer" id="dragMe"></div>
|
| 173 |
+
<div class="pane" id="output-pane">
|
| 174 |
+
<div id="html-output"></div>
|
| 175 |
+
</div>
|
| 176 |
+
</div>
|
| 177 |
+
|
| 178 |
+
<script>
|
| 179 |
+
const markdownInput = document.getElementById('markdown-input');
|
| 180 |
+
const htmlOutput = document.getElementById('html-output');
|
| 181 |
+
const resizer = document.getElementById('dragMe');
|
| 182 |
+
const leftPane = document.getElementById('input-pane');
|
| 183 |
+
const rightPane = document.getElementById('output-pane');
|
| 184 |
+
const container = document.querySelector('.container');
|
| 185 |
+
|
| 186 |
+
// Function to render Markdown
|
| 187 |
+
function renderMarkdown() {
|
| 188 |
+
const mdText = markdownInput.value;
|
| 189 |
+
try {
|
| 190 |
+
// Using marked.parse() for marked v4+
|
| 191 |
+
// gfm: true for GitHub Flavored Markdown
|
| 192 |
+
// breaks: true for rendering single newlines as <br> (common preference)
|
| 193 |
+
htmlOutput.innerHTML = marked.parse(mdText, { gfm: true, breaks: true, pedantic: false });
|
| 194 |
+
} catch (e) {
|
| 195 |
+
// Fallback for older marked versions or if marked.parse is not available
|
| 196 |
+
try {
|
| 197 |
+
htmlOutput.innerHTML = marked(mdText, { gfm: true, breaks: true, pedantic: false });
|
| 198 |
+
} catch (innerErr) {
|
| 199 |
+
htmlOutput.innerHTML = "<p style='color:red;'>Error rendering Markdown. Check browser console.</p>";
|
| 200 |
+
console.error("Markdown rendering error:", innerErr);
|
| 201 |
+
}
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
// Initial render and on input
|
| 206 |
+
markdownInput.addEventListener('input', renderMarkdown);
|
| 207 |
+
|
| 208 |
+
// Resizer logic
|
| 209 |
+
let isResizing = false;
|
| 210 |
+
|
| 211 |
+
resizer.addEventListener('mousedown', (e) => {
|
| 212 |
+
e.preventDefault(); // Prevent text selection during drag
|
| 213 |
+
isResizing = true;
|
| 214 |
+
document.body.style.userSelect = 'none'; // Prevent text selection globally
|
| 215 |
+
|
| 216 |
+
// Set flex-grow to 0 so flex-basis takes full control during resize
|
| 217 |
+
leftPane.style.flexGrow = '0';
|
| 218 |
+
rightPane.style.flexGrow = '0';
|
| 219 |
+
|
| 220 |
+
document.addEventListener('mousemove', handleMouseMove);
|
| 221 |
+
document.addEventListener('mouseup', stopResize);
|
| 222 |
+
});
|
| 223 |
+
|
| 224 |
+
function handleMouseMove(e) {
|
| 225 |
+
if (!isResizing) return;
|
| 226 |
+
|
| 227 |
+
const containerRect = container.getBoundingClientRect();
|
| 228 |
+
let leftWidth = e.clientX - containerRect.left;
|
| 229 |
+
|
| 230 |
+
// Minimum pane width (e.g., 30px to still see/drag resizer)
|
| 231 |
+
// Set to 0 if you want to allow complete collapse, but might be hard to reopen.
|
| 232 |
+
const minPaneWidth = 30;
|
| 233 |
+
const resizerWidth = resizer.offsetWidth;
|
| 234 |
+
|
| 235 |
+
// Constrain left pane
|
| 236 |
+
if (leftWidth < minPaneWidth) {
|
| 237 |
+
leftWidth = minPaneWidth;
|
| 238 |
+
}
|
| 239 |
+
if (leftWidth > containerRect.width - resizerWidth - minPaneWidth) {
|
| 240 |
+
leftWidth = containerRect.width - resizerWidth - minPaneWidth;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
const rightWidth = containerRect.width - leftWidth - resizerWidth;
|
| 244 |
+
|
| 245 |
+
leftPane.style.flexBasis = `${leftWidth}px`;
|
| 246 |
+
rightPane.style.flexBasis = `${rightWidth}px`;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
function stopResize() {
|
| 250 |
+
isResizing = false;
|
| 251 |
+
document.body.style.userSelect = ''; // Re-enable text selection
|
| 252 |
+
document.removeEventListener('mousemove', handleMouseMove);
|
| 253 |
+
document.removeEventListener('mouseup', stopResize);
|
| 254 |
+
// The flex-grow 0 and pixel-based flex-basis will persist.
|
| 255 |
+
// This means after a manual resize, the panes won't auto-adjust to window resizes
|
| 256 |
+
// unless we convert back to percentages or restore flex-grow:1.
|
| 257 |
+
// For this tool, fixed pixel widths after manual drag is often acceptable.
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
// Set some default Markdown content
|
| 261 |
+
markdownInput.value = `# Welcome to Your Offline Markdown Viewer!
|
| 262 |
+
|
| 263 |
+
## How to Use
|
| 264 |
+
1. **Paste or type** your Markdown text into this left pane.
|
| 265 |
+
2. The **rendered HTML** will appear live in the right pane.
|
| 266 |
+
3. **Drag the vertical bar** in the middle to resize the panes. You can shrink one pane almost completely to focus on the other.
|
| 267 |
+
|
| 268 |
+
## Features
|
| 269 |
+
* **Live Preview:** Updates as you type.
|
| 270 |
+
* **GitHub Flavored Markdown (GFM):** Includes support for tables, fenced code blocks, etc.
|
| 271 |
+
* **Line Breaks:** Single newlines are rendered as line breaks (\`<br>\`).
|
| 272 |
+
* **Portable & Offline:** Just this HTML file and \`marked.min.js\` in the same folder. No installation needed!
|
| 273 |
+
|
| 274 |
+
---
|
| 275 |
+
|
| 276 |
+
### Example Markdown:
|
| 277 |
+
|
| 278 |
+
\`\`\`javascript
|
| 279 |
+
// Code block example
|
| 280 |
+
function greet(name) {
|
| 281 |
+
return \`Hello, \${name}!\`;
|
| 282 |
+
}
|
| 283 |
+
console.log(greet("Markdown User"));
|
| 284 |
+
\`\`\`
|
| 285 |
+
|
| 286 |
+
- Item 1
|
| 287 |
+
- Item 2
|
| 288 |
+
- Sub-item A
|
| 289 |
+
- Sub-item B
|
| 290 |
+
|
| 291 |
+
> This is a blockquote. It's useful for highlighting text.
|
| 292 |
+
|
| 293 |
+
**Bold text**, *italic text*, and \`inline code\`.
|
| 294 |
+
|
| 295 |
+
A horizontal rule:
|
| 296 |
+
***
|
| 297 |
+
|
| 298 |
+
A table:
|
| 299 |
+
|
| 300 |
+
| Header 1 | Header 2 | Header 3 |
|
| 301 |
+
|----------|----------|----------|
|
| 302 |
+
| Cell 1A | Cell 2A | Cell 3A |
|
| 303 |
+
| Cell 1B | Cell 2B | Cell 3B |
|
| 304 |
+
`;
|
| 305 |
+
renderMarkdown(); // Render the default text on load
|
| 306 |
+
|
| 307 |
+
</script>
|
| 308 |
+
</body>
|
| 309 |
+
</html>
|