-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobconv.html
More file actions
726 lines (626 loc) · 22.4 KB
/
Copy pathobconv.html
File metadata and controls
726 lines (626 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OBSIDIAN WEB</title>
<style id="main-obsidian-styles">
/* ===========================
Obsidian Theme Variables
=========================== */
:root {
--background-primary: #1e1e1e;
--background-secondary: #2a2a2a;
--text-normal: #dcdcdc;
--text-accent: #a882ff;
--text-muted: #888;
--interactive-accent: #a882ff;
--code-background: #242424;
--code-normal: #b3b3b3;
--code-comment: #666666;
--code-function: #e0de71;
--code-important: #e9973f;
--code-keyword: #fa99cd;
--code-operator: #fb464c;
--code-property: #53dfdd;
--code-punctuation: #b3b3b3;
--code-string: #44cf6e;
--code-tag: #fb464c;
--code-value: #a882ff;
--text-highlight-bg: #655300;
}
/* Light Mode Variables */
.light-mode {
--background-primary: #f6f6f6;
--background-secondary: #ffffff;
--text-normal: #1e1e1e;
--text-accent: #6c3aff;
--text-muted: #555;
--interactive-accent: #6c3aff;
--code-background: #f0f0f0;
--code-comment: #999;
--code-string: #118c4f;
--code-keyword: #7d4dd3;
--code-function: #c37e00;
}
/* ===========================
기본 레이아웃 (Layout Fixed)
=========================== */
body {
background-color: var(--background-primary);
color: var(--text-normal);
font-family: "Inter", "Segoe UI", sans-serif;
display: flex;
flex-direction: row;
height: 100vh;
margin: 0;
overflow: hidden;
}
#editor {
width: 40%;
padding: 1em;
background-color: var(--background-secondary);
border-right: 2px solid var(--interactive-accent);
resize: none;
outline: none;
color: var(--text-normal);
font-family: "Fira Code", monospace;
font-size: 14px;
height: 100%; /* (FIXED) 툴바 공간 확보 */
box-sizing: border-box;
padding-bottom: 50px;
}
/* (NEW) 오른쪽 패널 (미리보기 + HTML 뷰) */
#right-panel {
width: 60%;
display: flex;
flex-direction: column;
height: 100vh;
padding-bottom: 50px; /* (FIXED) 툴바 공간 확보 */
box-sizing: border-box;
}
#preview {
height: 60%; /* 상단 60% */
padding: 2em;
overflow-y: auto;
}
/* (NEW) HTML 코드 실시간 뷰 */
/* (NEW) HTML 코드 실시간 뷰 */
#html-code-view {
height: 100%; /* (MODIFIED) 부모 div를 100% 채우도록 변경 */
box-sizing: border-box; /* (NEW) 패딩이 높이에 포함되도록 추가 */
background: var(--code-background);
color: var(--text-normal);
border-top: 2px solid var(--interactive-accent);
padding: 1em;
margin: 0;
overflow: auto;
font-family: "Fira Code", monospace;
font-size: 13px;
white-space: pre-wrap; /* 자동 줄바꿈 */
word-break: break-all;
}
/* ===========================
Markdown 스타일
=========================== */
h1, h2, h3, h4, h5, h6 {
color: var(--text-normal);
}
a {
color: var(--interactive-accent);
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
code {
background-color: var(--code-background);
color: var(--code-string);
padding: 2px 4px;
border-radius: 4px;
}
pre {
margin: 0;
}
pre code {
display: block;
background-color: var(--code-background);
padding: 1em;
border-radius: 8px;
overflow-x: auto;
white-space: pre-wrap;
word-break: break-word;
}
blockquote {
border-left: 2px solid var(--interactive-accent);
padding-left: 1.5em;
margin: 0;
color: var(--text-normal);
}
blockquote p {
margin: 0;
}
blockquote p:empty {
margin: 0.5em 0;
}
#preview > blockquote {
margin: 1em 0;
}
/* ===========================
Toolbar GUI
=========================== */
#toolbar {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: var(--background-secondary);
border-top: 1px solid var(--interactive-accent);
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 12px;
box-sizing: border-box;
gap: 10px;
}
#cssSnippet {
width: 45%;
background: #111;
color: var(--text-accent);
font-family: "Fira Code", monospace;
font-size: 12px;
border: 1px solid var(--interactive-accent);
border-radius: 4px;
padding: 4px;
resize: vertical;
}
button {
background: var(--interactive-accent);
border: none;
color: white;
padding: 6px 10px;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #8a6eff;
}
/* ===========================
코드 하이라이팅
=========================== */
.hljs-comment { color: var(--code-comment); }
.hljs-keyword { color: var(--code-keyword); }
.hljs-string { color: var(--code-string); }
.hljs-number { color: var(--code-value); }
/* ===========================
추가된 Markdown 스타일
=========================== */
/* 수정된 mark 스타일 */
mark {
background-color: var(--text-highlight-bg); /* 변수 사용 */
color: var(--text-normal); /* 글자색 변경 */
padding: 2px 4px;
border-radius: 0; /* 둥글기 제거 */
}
ul.task-list {
list-style-type: none;
padding-left: 0.5em;
}
li.task-list-item {
display: flex;
align-items: center;
margin: 0.2em 0;
}
li.task-list-item::before {
content: ' ';
display: inline-block;
width: 16px;
height: 16px;
border: 2px solid var(--text-muted);
border-radius: 3px;
margin-right: 0.5em;
background-color: var(--background-secondary);
flex-shrink: 0;
}
li.task-list-item.checked::before {
background-color: var(--interactive-accent);
border-color: var(--interactive-accent);
background-image: url("data:image/svg+xml,%3Csvg xmlns='[http://www.w3.org/2000/svg](http://www.w3.org/2000/svg)' viewBox='0 0 16 16' fill='white'%3E%3Cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3E%3C/svg%3E");
background-position: center;
background-repeat: no-repeat;
}
a.internal-link {
color: var(--text-accent);
background-color: #333333;
padding: 1px 3px;
border-radius: 4px;
text-decoration: none;
}
#preview p {
margin: 0.5em 0;
}
#preview p:first-child {
margin-top: 0;
}
/* ===========================
코드 복사 버튼 스타일
=========================== */
.code-block-wrapper {
position: relative;
margin: 1em 0;
}
.copy-code-btn {
position: absolute;
top: 8px;
right: 8px;
background-color: #3a3a3a;
color: var(--text-muted);
border: 1px solid var(--text-muted);
border-radius: 4px;
padding: 4px;
cursor: pointer;
opacity: 0;
transition: opacity 0.2s;
}
.code-block-wrapper:hover .copy-code-btn {
opacity: 1;
}
#html-code-view {
/* ... (other rules) ... */
white-space: pre-wrap;
word-break: break-all;
user-select: text; /* This line was added */
}
hr {
border: none; /* 기존 스타일 초기화 */
border-top: 2px solid #555555; /* 1px 두께와 특정 회색 적용 */
height: 0;
}
</style>
</head>
<body>
<textarea id="editor" placeholder="type your Markdown here">
# OBSIDIAN web
---
Obsidian for web browser (unofficial)
<br>
## SUGGESTIONS?
---
If you have any suggestions, please send it to **i.aecopse12@gmail.com**
<br>
>Thank you for your suggestions :)
<br>
## FEATURES
---
1. Obsidian editor in the **WEB**
2. Light/Dark theme switch
3. Auto markdown completer
4. Custom CSS snippet!
5. **export as html!**
Most Of All... It's
**BEAUTIFUL**
<br>
## DONATE
---
you can DONATE
<a href="https://ko-fi.com/acops">HERE</a>
https://ko-fi.com/acops
<br>
and, I'm from south korea. so my translation can be missing or wrong sometime... 😅
</textarea>
<div id="right-panel">
<div id="preview"></div>
<div class="code-block-wrapper" style="height: 40%;">
<button class="copy-code-btn" id="copy-html-btn" title="Copy HTML">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor">
<path d="M5.75 1a.75.75 0 0 0-.75.75v1.5h-.75A1.75 1.75 0 0 0 2.5 5v8.25c0 .966.784 1.75 1.75 1.75h5.5A1.75 1.75 0 0 0 11.5 13.25V5A1.75 1.75 0 0 0 9.75 3.25h-.75v-1.5A.75.75 0 0 0 8.25 1h-2.5ZM3.5 5A.25.25 0 0 1 3.75 4.75h5.5a.25.25 0 0 1 .25.25v8.25a.25.25 0 0 1-.25.25h-5.5A.25.25 0 0 1 3.5 13.25V5ZM6 2.5v.75h3V2.5h-3Z"></path>
</svg>
</button>
<pre id="html-code-view"></pre>
</div>
</div>
<div id="toolbar">
<span style="color: var(--text-muted)">🎨Custom CSS Snippet:</span>
<textarea id="cssSnippet" rows="2" placeholder="예: body { font-size: 18px;
}">body { --background-primary: black; --interactive-accent: #895FE6;
--text-highlight-bg: #655300}</textarea>
<button id="applyCSS">APPLY</button>
<button id="toggleTheme">SWITCH THEME</button>
</div>
<script>
function simpleMarkdown(md) {
md = md.replace(/\r\n/g, '\n');
// ==========================================================
// (NEW) 인라인 파서 헬퍼 함수
// 헤더, 리스트, 단락에서 이 함수를 호출해 인라인 마크다운을 처리합니다.
// ==========================================================
function parseInline(text) {
// 1. 인라인 코드(``)를 가장 먼저 처리해야
// 그 안의 특수기호(==, **)가 마크다운으로 변환되는 것을 막을 수 있습니다.
text = text.replace(/` + '`(.*?)`' + `/gim, (match, code) => {
// 인라인 코드 내부의 HTML 특수문자 이스케이프
const escapedCode = code.replace(/[<>&]/g, c => ({'<':'<','>':'>','&':'&'}[c]));
return '<code>' + escapedCode + '</code>';
});
// 2. 나머지 인라인 마크다운을 처리합니다.
// (이제 <code> 태그 안의 내용은 건드리지 않습니다.)
return text.replace(/\[(.*?)\]\((.*?)\)/gim, '<a href="$2" target="_blank">$1</a>')
.replace(/\[\[(.*?)\]\]/g, '<a href="#" class="internal-link">$1</a>')
.replace(/~~(.*?)~~/gim, "<s>$1</s>")
.replace(/==(.*?)==/gim, "<mark>$1</mark>")
.replace(/\*\*(.*?)\*\*/gim, "<b>$1</b>")
.replace(/\*(.*?)\*/gim, "<i>$1</i>");
}
const codeBlocks = [];
// 1. (FIXED) 코드 블록을 먼저 추출하고 토큰으로 대체
let html = md.replace(/\n?```([a-z]*)\n([\s\S]*?)```\n?/g, (match, lang, code) => {
const escapedCode = code.replace(/[<>&]/g, c => ({'<':'<','>':'>','&':'&'}[c]));
const copyButton = `
<button class="copy-code-btn" title="Copy code">
<svg xmlns="[http://www.w3.org/2000/svg](http://www.w3.org/2000/svg)" viewBox="0 0 16 16" fill="currentColor">
<path d="M5.75 1a.75.75 0 0 0-.75.75v1.5h-.75A1.75 1.75 0 0 0 2.5 5v8.25c0 .966.784 1.75 1.75 1.75h5.5A1.75 1.75 0 0 0 11.5 13.25V5A1.75 1.75 0 0 0 9.75 3.25h-.75v-1.5A.75.75 0 0 0 8.25 1h-2.5ZM3.5 5A.25.25 0 0 1 3.75 4.75h5.5a.25.25 0 0 1 .25.25v8.25a.25.25 0 0 1-.25.25h-5.5A.25.25 0 0 1 3.5 13.25V5ZM6 2.5v.75h3V2.5h-3Z"></path>
</svg>
</button>`;
const blockHtml = `\n<div class="code-block-wrapper">${copyButton}<pre><code class="language-${lang}">${escapedCode}</code></pre></div>\n`;
codeBlocks.push(blockHtml);
return `\n__CODE_BLOCK_${codeBlocks.length - 1}__\n`;
});
// 2. 나머지 블록 요소 처리
html = '\n' + html + '\n';
// Horizontal Rules
html = html.replace(/\n(---|\*\*\*)\n/g, "\n<hr>\n");
// Headers (h1-h6) - (USER FIX)
// 콜백 함수를 사용해 캡처한 content를 즉시 parseInline으로 처리합니다.
html = html.replace(/\n(######) (.*)/g, (match, h, content) => `\n<h6>${parseInline(content)}</h6>`)
.replace(/\n(#####) (.*)/g, (match, h, content) => `\n<h5>${parseInline(content)}</h5>`)
.replace(/\n(####) (.*)/g, (match, h, content) => `\n<h4>${parseInline(content)}</h4>`)
.replace(/\n(###) (.*)/g, (match, h, content) => `\n<h3>${parseInline(content)}</h3>`)
.replace(/\n(##) (.*)/g, (match, h, content) => `\n<h2>${parseInline(content)}</h2>`)
.replace(/\n(#) (.*)/g, (match, h, content) => `\n<h1>${parseInline(content)}</h1>`);
// (FIXED) Blockquotes - (USER FIX)
// 인용문은 내부에 다른 블록(헤더, 목록 등)이 또 올 수 있으므로 '재귀 호출' 방식을 유지합니다.
html = html.replace(/\n((?:> ?.*(?:\n|$))+)/g, (match, block) => {
const content = block.replace(/^> ?/gm, '');
const innerHtml = simpleMarkdown(content); // 재귀 호출
return '\n<blockquote>' + innerHtml + '</blockquote>\n';
});
// Images
html = html.replace(/!\[(.*?)\]\((.*?)\)/gim, '<img src="$2" alt="$1" style="max-width: 100%;">');
// Lists (Task, Unordered, Ordered) - (USER FIX)
// 콜백 함수를 사용해 캡처한 content를 즉시 parseInline으로 처리합니다.
html = html.replace(/\n- \[(x|X)\] (.*)/g, (match, x, content) => `\n<li class="task-list-item checked">${parseInline(content)}</li>`)
.replace(/\n- \[ \] (.*)/g, (match, content) => `\n<li class="task-list-item">${parseInline(content)}</li>`)
.replace(/\n\d+\. (.*)/g, (match, content) => `\n<li class="ol-item">${parseInline(content)}</li>`)
.replace(/\n- (.*)/g, (match, content) => `\n<li class="ul-item">${parseInline(content)}</li>`);
// List Grouping
html = html.replace(/((?:\n<li class="ul-item">.*<\/li>)+)/g, "\n<ul>$1\n</ul>")
.replace(/((?:\n<li class="ol-item">.*<\/li>)+)/g, "\n<ol>$1\n</ol>")
.replace(/((?:\n<li class="task-list-item.*<\/li>)+)/g, "\n<ul class=\"task-list\">$1\n</ul>");
// 3. (FIXED) 단락(<p>) 및 인라인 요소 처리
html = html.split('\n').map(line => {
const trimmed = line.trim();
if (trimmed === "") return "";
// (FIXED) 이 검사는 이제 안전합니다.
// 왜냐하면 h1, li 등은 이미 위에서 인라인 파싱이 완료된 상태이기 때문입니다.
if (/^__CODE_BLOCK_/.test(trimmed) || /^<(h[1-6]|ul|ol|li|pre|code|blockquote|hr|img|div)/.test(trimmed) || /^<\/(ul|ol|blockquote)>$/.test(trimmed)) {
return line;
}
// 위에서 걸러지지 않은 나머지 줄(일반 <p> 문단)에 대해 인라인 파서를 실행합니다.
line = parseInline(line);
return `<p>${line}</p>`;
}).join('\n');
// 4. (FIXED) 코드 블록 토큰을 다시 HTML로 복원
html = html.replace(/<p>__CODE_BLOCK_(\d+)__<\/p>|__CODE_BLOCK_(\d+)__/g, (match, p1, p2) => {
const index = p1 || p2;
return codeBlocks[index];
});
// 5. Cleanup
html = html.replace(/<p> <\/p>/g, '')
.replace(/<p><\/p>/g, '')
.replace(/\n/g, '');
return html.trim();
}
</script>
<script>
function highlightCode() {
document.querySelectorAll('pre code').forEach(block => {
if (block.querySelector('span.hljs-keyword')) {
return;
}
block.innerHTML = block.innerHTML
.replace(/("[^"]*"|'[^']*')/g, '<span class="hljs-string">$1</span>')
.replace(/(def|class|return|import|from|if|else|for|while|print)/g, '<span class="hljs-keyword">$1</span>')
.replace(/(#.*$)/gm, '<span class="hljs-comment">$1</span>')
.replace(/(\d+)/g, '<span class="hljs-number">$1</span>');
});
}
</script>
<script>
const editor = document.getElementById('editor');
const preview = document.getElementById('preview');
const htmlView = document.getElementById('html-code-view'); // (NEW)
const cssSnippet = document.getElementById('cssSnippet');
const applyBtn = document.getElementById('applyCSS');
const toggleBtn = document.getElementById('toggleTheme');
// (REMOVED) exportBtn, copyBtn
// ===================================
// 스마트 에디터 기능
// ===================================
editor.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
this.value = this.value.replace(/\r\n/g, '\n');
}
const start = this.selectionStart;
const end = this.selectionEnd;
const text = this.value;
// 1. 괄호, 따옴표, 백틱 자동 완성
const pairs = { '(': ')', '[': ']', '{': '}', '"': '"', "'": "'", '`': '`' };
if (pairs[e.key]) {
e.preventDefault();
const before = text.substring(0, start);
const after = text.substring(end);
if (start !== end) {
const selected = text.substring(start, end);
this.value = before + e.key + selected + pairs[e.key] + after;
this.setSelectionRange(start + 1, end + 1);
} else {
this.value = before + e.key + pairs[e.key] + after;
this.setSelectionRange(start + 1, start + 1);
}
renderMarkdown();
return;
}
// 2. Enter 키로 목록/인용문 자동 완성 및 해제
if (e.key === 'Enter') {
const before = text.substring(0, start);
const lastNewline = before.lastIndexOf('\n');
const currentLine = before.substring(lastNewline + 1);
const listMatch = currentLine.match(/^(\s*)((?:>|[-*]|\d+\.) )/);
if (listMatch) {
e.preventDefault();
const prefix = listMatch[1];
const bullet = listMatch[2];
if (currentLine.trim() === bullet.trim()) {
this.value = text.substring(0, lastNewline + 1) + text.substring(start);
this.setSelectionRange(lastNewline + 1, lastNewline + 1);
} else {
let newBullet = bullet;
if (/\d+\./.test(bullet)) {
const num = parseInt(bullet, 10);
newBullet = (num + 1) + '. ';
}
const newLine = '\n' + prefix + newBullet;
this.value = before + newLine + text.substring(start);
this.setSelectionRange(start + newLine.length, start + newLine.length);
}
} else {
e.preventDefault();
this.value = before + '\n' + text.substring(start);
this.setSelectionRange(start + 1, start + 1);
}
renderMarkdown();
return;
}
});
// ===================================
// 코드 복사 버튼 기능 (미리보기 패널)
// ===================================
preview.addEventListener('click', function(e) {
// (FIXED) #copy-html-btn이 아닌 버튼만 선택
const btn = e.target.closest('.copy-code-btn:not(#copy-html-btn)');
if (btn) {
e.preventDefault();
const code = btn.nextElementSibling.querySelector('code').innerText;
navigator.clipboard.writeText(code).then(() => {
btn.title = "Copied!";
btn.style.color = "var(--code-string)";
setTimeout(() => {
btn.title = "Copy code";
btn.style.color = "var(--text-muted)";
}, 2000);
}).catch(err => {
console.error('Failed to copy code:', err);
btn.title = "Failed to copy";
});
}
});
// ===================================
// HTML 코드 복사 버튼 기능 (FIXED - 분리됨)
// ===================================
document.getElementById('copy-html-btn').addEventListener('click', function(e) {
const btn = e.currentTarget; // 클릭된 버튼 (this)
const htmlContent = document.getElementById('html-code-view').textContent;
navigator.clipboard.writeText(htmlContent).then(() => {
btn.title = "Copied!";
btn.style.color = "var(--code-string)"; // 피드백 스타일 재사용
setTimeout(() => {
btn.title = "Copy HTML";
btn.style.color = "var(--text-muted)";
}, 2000);
}).catch(err => {
console.error('Failed to copy HTML:', err);
btn.title = "Failed to copy";
});
});
// Markdown 렌더링 (FIXED)
function renderMarkdown() {
// 1. 마크다운을 HTML 조각으로 변환
const bodyHtml = simpleMarkdown(editor.value);
// 2. 상단 미리보기(preview) 패널은 그대로 HTML 조각으로 채움
preview.innerHTML = bodyHtml;
// 3. (NEW) 하단 HTML 코드 뷰를 위한 작업
// 3-1. 메인 스타일 시트 내용을 '안전하게' 가져옴
const mainStylesEl = document.getElementById('main-obsidian-styles');
const mainStyles = mainStylesEl ? mainStylesEl.textContent : '/* 🎨 메인 스타일을 찾지 못했습니다 */';
// 3-2. 사용자가 입력한 커스텀 CSS 스니펫을 가져옴
const customStyles = cssSnippet.value;
// 3-3. 현재 테마(라이트 모드) 상태를 확인
const isLightMode = document.body.classList.contains('light-mode');
const bodyClass = isLightMode ? ' class="light-mode"' : '';
// 3-4. (FIXED) 완전한 HTML 문서 템플릿을 생성 (레이아웃 오버라이드 포함)
const fullHtmlOutput = `<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown Export</title>
<style id="main-obsidian-styles">
${mainStyles}
</style>
<style id="custom-snippet-styles">
${customStyles}
</style>
<style>
/* 에디터의 flex 레이아웃 스타일('display: flex')이
결과물 파일에 영향을 주지 않도록 초기화(override)합니다.
*/
body {
display: block; /* 'flex'에서 'block'으로 변경 */
flex-direction: unset;
height: auto;
overflow: auto;
}
</style>
</head>
<body${bodyClass}>
<div id="preview-wrapper" style="max-width: 800px; margin: 2em auto; padding: 2em;">
${bodyHtml}
</div>
</body>
</html>`;
// 4. 하단 HTML 뷰(htmlView)에 '텍스트'로 삽입
htmlView.textContent = fullHtmlOutput;
// 5. 기타 기능 수행
highlightCode(); // 상단 미리보기 하이라이팅
localStorage.setItem('obsidian-md', editor.value);
}
// 로컬 저장 불러오기
window.addEventListener('load', () => {
const saved = localStorage.getItem('obsidian-md');
if (saved) editor.value = saved;
// [수정] 기본 CSS 스니펫을 로드 시 즉시 적용합니다.
applyBtn.click();
renderMarkdown();
});
// 입력 시 즉시 렌더링 + 저장
editor.addEventListener('input', renderMarkdown);
// CSS 스니펫 적용
applyBtn.addEventListener('click', () => {
let styleTag = document.getElementById('customCSS');
if (!styleTag) {
styleTag = document.createElement('style');
styleTag.id = 'customCSS';
document.head.appendChild(styleTag);
}
styleTag.textContent = cssSnippet.value;
});
// 테마 전환
toggleBtn.addEventListener('click', () => {
document.body.classList.toggle('light-mode');
renderMarkdown();
});
// (REMOVED) 내보내기 및 복사 버튼 리스너 제거
// made by ACOPS1206 aecopse12@gmail.com
</script>
</body>
</html>