index.html
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 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>SunEditor Example</title> <!-- SunEditor CSS --> <link href="https://cdn.jsdelivr.net/npm/suneditor@latest/dist/css/suneditor.min.css" rel="stylesheet"> <style> #editor-container { width: 100%; margin: auto; margin-top: 20px; } #sample-editor{ width:100% } .editor-preview { border: 1px solid #ccc; margin-top: 20px; padding: 10px; } #show-content { margin-top: 10px; } </style> </head> <body> <h1 style="text-align: center;">SunEditor Example</h1> <div id="editor-container"> <!-- Textarea for SunEditor --> <textarea id="sample-editor">Welcome to SunEditor!</textarea> <button id="show-content">Show HTML Content</button> <div class="editor-preview" id="editor-preview"> <!-- Content preview will appear here --> </div> </div> <!-- SunEditor JS --> <script src="https://cdn.jsdelivr.net/npm/suneditor@latest/dist/suneditor.min.js"></script> <!-- Language Support (optional, default is English) --> <script src="https://cdn.jsdelivr.net/npm/suneditor@latest/src/lang/en.js"></script> <script> // Initialize SunEditor const editor = SUNEDITOR.create('sample-editor', { height: 300, buttonList: [ ['undo', 'redo', 'formatBlock', 'bold', 'italic', 'underline', 'strike'], ['fontSize', 'fontColor', 'hiliteColor', 'align', 'list', 'link', 'image', 'video'], ['removeFormat', 'preview', 'codeView'] ], lang: SUNEDITOR_LANG['en'], // Set language to English placeholder: 'Start typing here...', charCounter: true, }); // Show content button click handler document.getElementById("show-content").addEventListener("click", () => { const content = editor.getContents(); document.getElementById("editor-preview").innerHTML = content; }); </script> </body> </html> |