// GhostEditor - Markdown to Word Converter JavaScript document.addEventListener('DOMContentLoaded', function() { // DOM Elements const markdownInput = document.getElementById('markdownInput'); const previewOutput = document.getElementById('previewOutput'); const previewToggle = document.getElementById('previewToggle'); const exportBtn = document.getElementById('exportBtn'); const blockType = document.getElementById('blockType'); const applyStyle = document.getElementById('applyStyle'); const applyStyleBtn = document.getElementById('applyStyleBtn'); const customCaption = document.getElementById('customCaption'); const applyCaptionBtn = document.getElementById('applyCaptionBtn'); const autoCaptionImages = document.getElementById('autoCaptionImages'); const autoCaptionTables = document.getElementById('autoCaptionTables'); const autoCaptionFigures = document.getElementById('autoCaptionFigures'); const tablePagination = document.getElementById('tablePagination'); const boldBtn = document.getElementById('boldBtn'); const italicBtn = document.getElementById('italicBtn'); const headingBtn = document.getElementById('headingBtn'); const listBtn = document.getElementById('listBtn'); const imageBtn = document.getElementById('imageBtn'); // Configuration let config = { autoCaptionImages: true, autoCaptionTables: true, autoCaptionFigures: true, tablePagination: true, defaultStyle: 'Normal' }; // Initialize with sample markdown markdownInput.value = `# GhostEditor Sample Document This is a sample document to demonstrate the real-time conversion capabilities of GhostEditor. ## Features Demonstrated ### Auto-captioning  *Figure 1: Sample placeholder image* ### Table with Pagination Support | ID | Name | Role | |----|------|------| | 1 | John | Developer | | 2 | Jane | Designer | | 3 | Bob | Manager | | 4 | Alice | Analyst | ### Code Block \`\`\`python def hello_world(): print("Hello, GhostEditor!") \`\`\` ### Blockquote > This is a sample quote demonstrating the styling capabilities of GhostEditor. ### List - First item - Second item - Third item`; // Update configuration when settings change autoCaptionImages.addEventListener('change', updateConfig); autoCaptionTables.addEventListener('change', updateConfig); autoCaptionFigures.addEventListener('change', updateConfig); tablePagination.addEventListener('change', updateConfig); // Toolbar buttons boldBtn.addEventListener('click', () => wrapText('**', '**')); italicBtn.addEventListener('click', () => wrapText('*', '*')); headingBtn.addEventListener('click', () => wrapLine('# ')); listBtn.addEventListener('click', () => wrapLine('- ')); imageBtn.addEventListener('click', () => insertImage()); // Apply style button applyStyleBtn.addEventListener('click', applyStyleToSelection); // Apply caption button applyCaptionBtn.addEventListener('click', applyCaptionToSelection); // Export button exportBtn.addEventListener('click', exportToWord); // Initial preview update updatePreview(); // Update preview when input changes markdownInput.addEventListener('input', updatePreview); // Update preview when toggle changes previewToggle.addEventListener('change', function() { if (this.checked) { updatePreview(); } else { previewOutput.innerHTML = '
Preview is disabled. Enable to see real-time conversion.
'; } }); // Update configuration function updateConfig() { config = { autoCaptionImages: autoCaptionImages.checked, autoCaptionTables: autoCaptionTables.checked, autoCaptionFigures: autoCaptionFigures.checked, tablePagination: tablePagination.checked, defaultStyle: document.getElementById('defaultStyle').value }; // Update preview after config change updatePreview(); } // Update preview function function updatePreview() { if (!previewToggle.checked) return; const markdown = markdownInput.value; // Convert markdown to HTML using Marked.js const html = marked.parse(markdown); // Process the HTML to add captions and table pagination const processedHtml = processHtmlForPreview(html); previewOutput.innerHTML = processedHtml; // Add captions to images if enabled if (config.autoCaptionImages) { addImageCaptions(); } } // Process HTML for preview with special features function processHtmlForPreview(html) { let processed = html; // Add table pagination header if enabled if (config.tablePagination) { processed = processed.replace(/