-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
374 lines (336 loc) · 22.2 KB
/
index.html
File metadata and controls
374 lines (336 loc) · 22.2 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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>LaTeX Editor Pro - v24 (v18 Color Restore)</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/mode/stex/stex.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.13/addon/search/searchcursor.min.js"></script>
<style>
:root { --bg-color: #1e1e1e; --panel-bg: #252526; --border-color: #3c3c3c; --vscode-blue: #007acc; }
body { font-family: 'Consolas', monospace; background: var(--bg-color); color: #d4d4d4; margin: 0; display: flex; height: 100vh; overflow: hidden; }
/* [v18 복구] 에디터 및 텍스트 선택 색상 */
.CodeMirror { flex: 1; font-size: 14px; background: #1e1e1e !important; color: #d4d4d4 !important; height: 100%; }
.CodeMirror-cursor { border-left: 2px solid #ffffff !important; }
.CodeMirror-selected { background: rgba(0, 122, 204, 0.6) !important; }
.CodeMirror-focused .CodeMirror-selectedtext, .CodeMirror-selectedtext { color: white !important; }
/* [v18 복구] 구문 강조 (Syntax Highlight) */
.cm-s-default .cm-keyword { color: #4ec9b0 !important; font-weight: bold; }
.cm-s-default .cm-variable-2 { color: #9cdcfe !important; }
.CodeMirror .CodeMirror-scroll .CodeMirror-code .cm-keyword-custom { color: #dcdcaa !important; font-weight: bold !important; }
.CodeMirror .CodeMirror-scroll .CodeMirror-code .cm-hangblock-custom,
.CodeMirror .CodeMirror-scroll .CodeMirror-code .cm-hangblock-custom * { color: #ff8c42 !important; font-weight: bold !important; }
.CodeMirror .CodeMirror-scroll .CodeMirror-code .cm-hblinebreak-custom,
.CodeMirror .CodeMirror-scroll .CodeMirror-code .cm-hblinebreak-custom * { color: #c586c0 !important; font-weight: bold !important; }
.cm-s-default .cm-tag, .cm-s-default .cm-atom { color: #9cdcfe !important; }
.cm-s-default .cm-bracket, .cm-s-default .cm-punctuation { color: #ffd700 !important; }
.cm-s-default .cm-number { color: #b5cea8 !important; }
.cm-s-default .cm-comment { color: #6a9955 !important; font-style: italic; }
/* 찾기 하이라이트 18종 */
.hl-0 { background: rgba(255, 235, 59, 0.35) !important; outline: 1px solid #ffeb3b; } /* 노랑 */
.hl-1 { background: rgba(186, 104, 200, 0.35) !important; outline: 1px solid #ba68c8; } /* 보라 */
.hl-2 { background: rgba(76, 175, 80, 0.35) !important; outline: 1px solid #4caf50; } /* 초록 */
.hl-3 { background: rgba(255, 87, 34, 0.35) !important; outline: 1px solid #ff5722; } /* 주황 */
.hl-4 { background: rgba(3, 169, 244, 0.35) !important; outline: 1px solid #03a9f4; } /* 파랑 */
.hl-5 { background: rgba(233, 30, 99, 0.35) !important; outline: 1px solid #e91e63; } /* 핑크 */
.hl-6 { background: rgba(0, 188, 212, 0.35) !important; outline: 1px solid #00bcd4; } /* 청록 */
.hl-7 { background: rgba(244, 67, 54, 0.35) !important; outline: 1px solid #f44336; } /* 빨강 */
.hl-8 { background: rgba(198, 255, 0, 0.35) !important; outline: 1px solid #c6ff00; } /* 라임 */
.hl-9 { background: rgba(29, 233, 182, 0.35) !important; outline: 1px solid #1de9b6; } /* 민트 */
.hl-10 { background: rgba(92, 107, 192, 0.35) !important; outline: 1px solid #5c6bc0; } /* 인디고 */
.hl-11 { background: rgba(255, 171, 64, 0.35) !important; outline: 1px solid #ffab40; } /* 앰버 */
.hl-12 { background: rgba(224, 64, 251, 0.35) !important; outline: 1px solid #e040fb; } /* 바이올렛 */
.hl-13 { background: rgba(255, 112, 67, 0.35) !important; outline: 1px solid #ff7043; } /* 코럴 */
.hl-14 { background: rgba(64, 196, 255, 0.35) !important; outline: 1px solid #40c4ff; } /* 하늘 */
.hl-15 { background: rgba(0, 230, 118, 0.35) !important; outline: 1px solid #00e676; } /* 연두 */
.hl-16 { background: rgba(255, 128, 171, 0.35) !important; outline: 1px solid #ff80ab; } /* 로즈 */
.hl-17 { background: rgba(255, 214, 0, 0.35) !important; outline: 1px solid #ffd600; } /* 골드 */
/* 레이아웃 및 탭 스타일 */
.main-layout { display: flex; flex: 1; height: 100%; }
.editor-section { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.resizer { width: 6px; cursor: col-resize; background: #2d2d2d; z-index: 10; }
.side-panel { width: 450px; background: var(--panel-bg); display: flex; flex-direction: column; border-left: 1px solid var(--border-color); overflow-y: auto; padding-bottom: 50px; }
.section { margin: 10px; padding: 10px; border: 1px solid var(--border-color); border-radius: 4px; background: #2d2d2d; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; border-bottom: 1px solid #444; padding-bottom: 5px; }
.section-header h3 { margin: 0; font-size: 13px; color: #569cd6; }
.tab-bar { display: flex; gap: 4px; overflow-x: auto; padding: 5px 0; margin-bottom: 5px; }
.tab { background: #3c3c3c; padding: 4px 10px; font-size: 11px; cursor: pointer; border-radius: 3px; display: flex; align-items: center; gap: 5px; white-space: nowrap; border: 1px solid transparent; color: #aaa; }
.tab.active { background: var(--vscode-blue); color: white; }
.tab-name { outline: none; border: none; background: none; color: inherit; font-size: inherit; cursor: text; padding: 2px 4px; }
.add-btn { background: #444; border: none; color: #ccc; cursor: pointer; border-radius: 3px; padding: 2px 8px; }
.header-btns { display: flex; gap: 5px; }
.copy-btn { font-size: 10px; background: #444; color: #aaa; border: 1px solid #555; cursor: pointer; padding: 2px 6px; border-radius: 2px; }
.input-pair-row { margin-bottom: 6px; padding-left: 6px; } /* 왼쪽 색상바를 위한 여백 */
input[type="text"] { background: #3c3c3c; border: 1px solid #555; color: white; padding: 6px; flex: 1; font-size: 12px; outline: none; }
.run-btn { background: var(--vscode-blue); color: white; border: none; padding: 10px; cursor: pointer; font-weight: bold; width: 100%; border-radius: 2px; margin-top: 10px; }
.remove-row-btn { color: #f44747; background: none; border: none; cursor: pointer; font-size: 16px; margin-left: 5px; }
</style>
</head>
<body>
<div class="main-layout">
<div class="editor-section">
<textarea id="editor"></textarea>
<div style="padding: 10px; background: #252526; border-top: 1px solid #3c3c3c; text-align: center;">
<button onclick="copyResult()" style="padding: 6px 25px; background: #3a3a3a; color: #ccc; border: 1px solid #555; cursor: pointer;">결과 복사</button>
</div>
</div>
<div class="resizer" id="resizer"></div>
<div class="side-panel">
<div class="section">
<div class="section-header">
<h3>단일 세트</h3>
<div class="header-btns"><button class="copy-btn" onclick="exportToExcel('single')">엑셀로 복사</button></div>
</div>
<div class="tab-bar" id="single-tabs"></div>
<div style="display:flex; gap:4px; margin-bottom:6px; align-items:center;">
<input type="text" id="s-find" placeholder="찾기" oninput="saveCurrentData(); refreshHighlights();" onpaste="handleExcelPaste(event, 'single')">
<input type="text" id="s-replace" placeholder="바꾸기" oninput="saveCurrentData(); refreshHighlights();">
<label style="font-size:11px; color:#888; cursor:pointer;"><input type="checkbox" id="s-regex" onchange="saveCurrentData(); refreshHighlights();"> R</label>
</div>
<button class="run-btn" onclick="runSingle()">단일 적용</button>
</div>
<div class="section">
<div class="section-header">
<h3>묶음 세트</h3>
<div class="header-btns"><button class="copy-btn" onclick="exportToExcel('batch')">엑셀로 복사</button></div>
</div>
<div class="tab-bar" id="batch-tabs"></div>
<div id="batch-list"></div>
<button onclick="addBatchRow()" style="background:none; border:1px dashed #666; color:#aaa; width:100%; padding:8px; margin-top:10px; font-size:12px;">+ 규칙 추가</button>
<button class="run-btn" onclick="runBatch()">전체 순차 적용</button>
</div>
</div>
</div>
<script>
const STORAGE_KEY = 'latex_editor_persistent_v1';
const LEGACY_KEYS = ['latex_editor_global_data', 'latex_editor_v22_final', 'latex_editor_v21_final', 'latex_editor_v20_data', 'latex_editor_global_tabs'];
const BATCH_COLORS = [
'#ffeb3b', '#ba68c8', '#4caf50', '#ff5722', '#03a9f4', '#e91e63',
'#00bcd4', '#f44336', '#c6ff00', '#1de9b6', '#5c6bc0', '#ffab40',
'#e040fb', '#ff7043', '#40c4ff', '#00e676', '#ff80ab', '#ffd600'
];
let data = {
single: { activeId: null, tabs: [] },
batch: { activeId: null, tabs: [] }
};
const editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
mode: "stex", lineNumbers: true, lineWrapping: true, inputStyle: "textarea"
});
const keywords = ["\\begin", "\\end", "\\left", "\\right", "\\TabPositions"];
function init() {
let saved = localStorage.getItem(STORAGE_KEY);
if (!saved) {
for (const key of LEGACY_KEYS) {
const legacyData = localStorage.getItem(key);
if (legacyData) {
saved = legacyData;
console.log(`Migrated from ${key}`);
break;
}
}
}
if (saved) {
try {
const parsed = JSON.parse(saved);
if (parsed.single && parsed.batch) { data = parsed; }
else if (parsed.batch) { // v18 형태 데이터 마이그레이션
data.single.tabs = [{id: Date.now(), name: 'S1', f: parsed.sF || '', r: parsed.sR || '', reg: parsed.sReg || false}];
data.single.activeId = data.single.tabs[0].id;
data.batch.tabs = [{id: Date.now()+1, name: 'B1', list: parsed.batch}];
data.batch.activeId = data.batch.tabs[0].id;
}
} catch (e) { console.error(e); }
}
if (!data.single.tabs.length) {
data.single.tabs = [{id: Date.now(), name: 'S1', f: '', r: '', reg: false}];
data.single.activeId = data.single.tabs[0].id;
}
if (!data.batch.tabs.length) {
data.batch.tabs = [{id: Date.now() + 1, name: 'B1', list: [{f: '', r: '', reg: false}]}];
data.batch.activeId = data.batch.tabs[0].id;
}
renderTabs('single'); renderTabs('batch');
loadActiveData('single'); loadActiveData('batch');
saveAll();
}
function renderTabs(type) {
const bar = document.getElementById(`${type}-tabs`);
bar.innerHTML = '';
data[type].tabs.forEach(tab => {
const btn = document.createElement('div');
btn.className = `tab ${tab.id === data[type].activeId ? 'active' : ''}`;
const nameSpan = document.createElement('span');
nameSpan.className = 'tab-name';
nameSpan.contentEditable = true;
nameSpan.innerText = tab.name;
nameSpan.onclick = (e) => { e.stopPropagation(); if(data[type].activeId !== tab.id) switchTab(type, tab.id); };
nameSpan.onblur = () => renameTab(type, tab.id, nameSpan.innerText);
nameSpan.onkeydown = (e) => { if(e.key === 'Enter') { e.preventDefault(); nameSpan.blur(); } };
btn.onclick = () => switchTab(type, tab.id);
const closeBtn = document.createElement('span');
closeBtn.style.cssText = "opacity:0.5; margin-left:5px;";
closeBtn.innerText = '×';
closeBtn.onclick = (e) => deleteTab(e, type, tab.id);
btn.appendChild(nameSpan); btn.appendChild(closeBtn);
bar.appendChild(btn);
});
const addBtn = document.createElement('button');
addBtn.className = 'add-btn'; addBtn.innerText = '+';
addBtn.onclick = () => addTab(type);
bar.appendChild(addBtn);
}
function addTab(type) {
saveCurrentData();
const newId = Date.now();
const newTab = type === 'single' ? {id: newId, name: '새 세트', f: '', r: '', reg: false} : {id: newId, name: '새 세트', list: [{f: '', r: '', reg: false}]};
data[type].tabs.push(newTab); switchTab(type, newId);
}
function switchTab(type, id) {
if(data[type].activeId === id) return;
saveCurrentData(); data[type].activeId = id;
renderTabs(type); loadActiveData(type); saveAll();
}
function saveCurrentData() {
const sActive = data.single.tabs.find(t => t.id === data.single.activeId);
if (sActive) {
sActive.f = document.getElementById('s-find').value;
sActive.r = document.getElementById('s-replace').value;
sActive.reg = document.getElementById('s-regex').checked;
}
const bActive = data.batch.tabs.find(t => t.id === data.batch.activeId);
if (bActive) {
bActive.list = [];
document.querySelectorAll('#batch-list .input-pair-row').forEach(row => {
bActive.list.push({ f: row.querySelector('.b-find').value, r: row.querySelector('.b-replace').value, reg: row.querySelector('.b-regex').checked });
});
}
saveAll();
}
function loadActiveData(type) {
if (type === 'single') {
const tab = data.single.tabs.find(t => t.id === data.single.activeId);
if (tab) {
document.getElementById('s-find').value = tab.f || '';
document.getElementById('s-replace').value = tab.r || '';
document.getElementById('s-regex').checked = tab.reg || false;
}
} else {
const tab = data.batch.tabs.find(t => t.id === data.batch.activeId);
const listContainer = document.getElementById('batch-list');
listContainer.innerHTML = '';
if (tab && tab.list) { tab.list.forEach(item => addBatchRow(item.f, item.r, item.reg)); }
else { addBatchRow(); }
}
refreshHighlights();
}
function addBatchRow(f='', r='', reg=false) {
const div = document.createElement('div');
div.className = 'input-pair-row';
div.style.display = "flex"; div.style.gap = "4px";
// [v18 복구] 행 추가 시 인덱스에 따른 왼쪽 색상 바 적용
const idx = document.querySelectorAll('#batch-list .input-pair-row').length;
div.style.borderLeft = `4px solid ${BATCH_COLORS[idx % 18]}`;
div.innerHTML = `
<input type="text" class="b-find" value="${f}" placeholder="찾기" oninput="saveCurrentData(); refreshHighlights();" onpaste="handleExcelPaste(event, 'batch', Array.from(this.parentElement.parentElement.children).indexOf(this.parentElement))">
<input type="text" class="b-replace" value="${r}" placeholder="바꾸기" oninput="saveCurrentData(); refreshHighlights();">
<label style="font-size:11px; color:#888; display:flex; align-items:center;"><input type="checkbox" class="b-regex" ${reg ? 'checked' : ''} onchange="saveCurrentData(); refreshHighlights();"> R</label>
<button class="remove-row-btn" onclick="this.parentElement.remove(); saveCurrentData(); refreshHighlights();">×</button>
`;
document.getElementById('batch-list').appendChild(div);
}
function saveAll() { localStorage.setItem(STORAGE_KEY, JSON.stringify(data)); }
function renameTab(type, id, name) { const t = data[type].tabs.find(x => x.id === id); if(t) t.name = name; saveAll(); }
function deleteTab(e, type, id) { e.stopPropagation(); if(data[type].tabs.length <= 1) return; if(!confirm('삭제하시겠습니까?')) return; data[type].tabs = data[type].tabs.filter(t => t.id !== id); if(data[type].activeId === id) data[type].activeId = data[type].tabs[0].id; renderTabs(type); loadActiveData(type); saveAll(); }
function refreshHighlights() {
editor.getAllMarks().forEach(m => m.clear());
keywords.forEach(kw => {
const cursor = editor.getSearchCursor(kw);
while (cursor.findNext()) editor.markText(cursor.from(), cursor.to(), {className: 'cm-keyword-custom'});
});
// hangblock 전용 강조: \begin{hangblock}[..]{..}{..} 와 \end{hangblock} 는 진한 주황,
// \hblinebreak 는 연한 주황으로 구분.
const hangblockPatterns = [
/\\begin\{hangblock\}(?:\[[^\]]*\])?(?:\{[^}]*\})?(?:\{[^}]*\})?/g,
/\\end\{hangblock\}/g
];
hangblockPatterns.forEach(re => {
const cursor = editor.getSearchCursor(re);
while (cursor.findNext()) editor.markText(cursor.from(), cursor.to(), {className: 'cm-hangblock-custom'});
});
const hblinebreakCursor = editor.getSearchCursor(/\\hblinebreak/g);
while (hblinebreakCursor.findNext()) editor.markText(hblinebreakCursor.from(), hblinebreakCursor.to(), {className: 'cm-hblinebreak-custom'});
// [v18 복구] 단일 세트는 hl-0 고정
const sf = document.getElementById('s-find').value;
if (sf) applyHighlight(sf, document.getElementById('s-regex').checked, 'hl-0');
// [v18 복구] 묶음 세트는 인덱스별 hl-0~5 순환 적용
document.querySelectorAll('#batch-list .input-pair-row').forEach((row, idx) => {
const bf = row.querySelector('.b-find').value;
if (bf) applyHighlight(bf, row.querySelector('.b-regex').checked, `hl-${idx % 18}`);
row.style.borderLeft = `4px solid ${BATCH_COLORS[idx % 18]}`;
});
}
function applyHighlight(query, isRegex, className) {
try { const cursor = editor.getSearchCursor(isRegex ? new RegExp(query, 'g') : query);
while (cursor.findNext()) editor.markText(cursor.from(), cursor.to(), {className: className});
} catch(e) {}
}
// --- 실행 로직 ---
function runSingle() {
let v = editor.getValue(); const f = document.getElementById('s-find').value, r = document.getElementById('s-replace').value;
if(!f) return;
if(document.getElementById('s-regex').checked) v = v.replace(new RegExp(f, 'g'), r.replace(/\\(\d)/g, '$$$1'));
else v = v.split(f).join(r);
editor.setValue(v);
}
function runBatch() {
let v = editor.getValue();
document.querySelectorAll('#batch-list .input-pair-row').forEach(row => {
const f = row.querySelector('.b-find').value, r = row.querySelector('.b-replace').value;
if(!f) return;
if(row.querySelector('.b-regex').checked) v = v.replace(new RegExp(f, 'g'), r.replace(/\\(\d)/g, '$$$1'));
else v = v.split(f).join(r);
});
editor.setValue(v);
}
function handleExcelPaste(event, type, startIdx = 0) {
const paste = (event.clipboardData || window.clipboardData).getData('text');
if (!paste.includes('\t') && !paste.includes('\n')) return;
event.preventDefault();
const rows = paste.split(/\r?\n/).filter(r => r.trim() !== '');
if (type === 'single') {
const cells = rows[0].split('\t');
document.getElementById('s-find').value = cells[0] || '';
document.getElementById('s-replace').value = cells[1] || '';
document.getElementById('s-regex').checked = (cells[2] === 'R' || cells[2] === '1' || cells[2] === 'true');
} else {
const currentRows = document.querySelectorAll('#batch-list .input-pair-row');
rows.forEach((rowStr, i) => {
const cells = rowStr.split('\t'); const targetIdx = startIdx + i;
if (targetIdx < currentRows.length) {
const row = currentRows[targetIdx];
row.querySelector('.b-find').value = cells[0] || '';
row.querySelector('.b-replace').value = cells[1] || '';
row.querySelector('.b-regex').checked = (cells[2] === 'R' || cells[2] === '1' || cells[2] === 'true');
} else { addBatchRow(cells[0] || '', cells[1] || '', (cells[2] === 'R' || cells[2] === '1')); }
});
}
saveCurrentData(); refreshHighlights();
}
function exportToExcel(type) {
let text = "";
if (type === 'single') { text = `${document.getElementById('s-find').value}\t${document.getElementById('s-replace').value}\t${document.getElementById('s-regex').checked ? 'R' : ''}`; }
else { document.querySelectorAll('#batch-list .input-pair-row').forEach(row => { text += `${row.querySelector('.b-find').value}\t${row.querySelector('.b-replace').value}\t${row.querySelector('.b-regex').checked ? 'R' : ''}\n`; }); }
navigator.clipboard.writeText(text).then(() => alert('엑셀 복사 완료!'));
}
function copyResult() { navigator.clipboard.writeText(editor.getValue()).then(() => alert("복사 완료")); }
const resizer = document.getElementById("resizer"), sideArea = document.querySelector(".side-panel");
let isResizing = false;
resizer.addEventListener("mousedown", () => isResizing = true);
document.addEventListener("mousemove", e => { if (!isResizing) return; sideArea.style.width = (window.innerWidth - e.clientX) + "px"; });
document.addEventListener("mouseup", () => isResizing = false);
editor.on("change", refreshHighlights);
window.onload = init;
</script>
</body>
</html>