(짜깁기 디버깅) <!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta…
- User
(짜깁기 디버깅)
// 코드 복사 버튼 처리 if (button.classList.contains('code-copy-btn')) { const codeElement = button.closest('pre')?.querySelector('code'); if (codeElement) { textToCopy = codeElement.innerText; } } // 글 복사 버튼 처리 if (button.classList.contains('copy-btn')) { // .prose 요소 탐색 const proseElement = button.closest('article')?.querySelector('.prose'); if (proseElement) { textToCopy = proseElement.innerText; } else { // .whitespace-pre-wrap 요소 탐색 const preWrapElement = button.closest('article')?.querySelector('.whitespace-pre-wrap'); if (preWrapElement) { textToCopy = preWrapElement.innerText; } } } // 공통 복사 로직 if (textToCopy) { const textArea = document.createElement('textarea'); textArea.value = textToCopy; document.body.appendChild(textArea); textArea.select(); try { document.execCommand('copy'); const originalHTML = button.innerHTML; // 버튼의 원래 HTML 저장 button.innerHTML = '복사됨!'; // 버튼의 내용을 변경 setTimeout(() => { button.innerHTML = originalHTML; // 버튼의 원래 HTML 복원 }, 2000); } catch (err) { alert('복사 실패: ' + err); } document.body.removeChild(textArea); } else { alert('복사할 내용을 찾을 수 없습니다.'); } }); });</script>
document.getElementById('fileInput').addEventListener('change', (event) => { const file = event.target.files[0]; uploadedFileName = file.name; if (file) { const reader = new FileReader(); reader.onload = (e) => { const content = e.target.result; // <article> 태그 추가const tempDiv = document.createElement('div'); tempDiv.innerHTML = content;
// 모든 헤딩 요소 탐색 및 태그로 래핑 tempDiv.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach((heading) => { const parent = heading.parentElement; if (parent && !parent.matches("article")) { const article = document.createElement("article"); parent.replaceWith(article); article.appendChild(parent.cloneNode(true)); } });
// 업데이트된 HTML 반영 const updatedHTML = tempDiv.innerHTML; document.getElementById('textPreview').value = updatedHTML; document.getElementById('htmlPreview').srcdoc = updatedHTML;
const selectedConverter = converters.chatgpt; // 웹사이트 선택은 ChatGPT로 const htmlStartIndex = content.indexOf(selectedConverter.htmlStartTag); // 변수명 수정 if (htmlStartIndex !== -1) { let htmlContent = content.slice(htmlStartIndex) .replace(/<script[\s\S]*?<\/script>/gi, '') // <script> 제거 .replace(/<link[\s\S]*?>/gi, '') // <link> 제거 .replace(/py-1/gi, 'code-copy-btn py-1') // 코드_복사_버튼 클래스 추가 .replace(/rounded-lg/gi, 'copy-btn rounded-lg'); // 복사_버튼 클래스 추가 if (!htmlContent || htmlContent.trim() === "") { document.getElementById('textPreview').value = 'HTML 콘텐츠가 비어 있습니다.'; return; } const articleStartIndex = htmlContent.indexOf(selectedConverter.articleStartTag); const articleEndIndex = htmlContent.lastIndexOf(selectedConverter.articleEndTag) + selectedConverter.articleEndTag.length; if (articleStartIndex !== -1 && articleEndIndex !== -1) { // <article>이 있는 경우 let articleContent = htmlContent.slice(articleStartIndex, articleEndIndex); // 지정된 태그 제거 (script만 제거) selectedConverter.removeTags.forEach((regex) => { articleContent = articleContent.replace(regex, ''); }); // 텍스트 미리보기 설정 document.getElementById('textPreview').value = articleContent + " "; // 빈문자 추가: 첫화면부터 미리보기 창 편집된 창으로 업데이트 // 실시간 미리보기 업데이트 - Assistant