logo

demo

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/demo.git

vanilla-editor.js (1023B)


  1. let source = document.getElementById("content_source");
  2. let view = document.getElementById("content_view");
  3. source.addEventListener("input", (event) => {
  4. view.innerHTML = source.value;
  5. });
  6. view.addEventListener("input", (event) => {
  7. source.value = view.innerHTML;
  8. });
  9. // Abusing JS Templates for multiline
  10. let hello = `<p>This is an example of VanillaJS rich-text edition. Your browser probably provides you with Word Processor shortcuts (ctrl-i for Italic, ctrl-b for Bold) in the rich-text editing mode.<br/>
  11. Meh parts are when it comes to things beyond just basic text-formatting like links, lists, tables, … which can still be pasted in formatted-mode in the rich-text area.</p>
  12. <ol>
  13. <li>First item</li>
  14. <li>Second item</li></ol>
  15. <p>Tables are where it’s usually not great at and where you’d definitely need some helper code for the user to add rows/columns:</p>
  16. <table>
  17. <tr><th>A</th><th>B</th><th>C</th></tr>
  18. <tr><td>1</td><td>2</td><td>3</td></tr>
  19. </table>`;
  20. view.innerHTML = hello;
  21. source.value = hello;