Advertisement
mbruns

Import and Bind Stackedit to website text area

Jun 11th, 2022
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Import the lib.
  2. import Stackedit from 'stackedit-js';
  3.  
  4. // Get the textarea.
  5. const el = document.querySelector('textarea');
  6.  
  7. // Create the Stackedit object.
  8. const stackedit = new Stackedit();
  9.  
  10. // Open the iframe
  11. stackedit.openFile({
  12.   name: 'Filename', // with a filename
  13.   content: {
  14.     text: el.value // and the Markdown content.
  15.   }
  16. });
  17.  
  18. // Listen to StackEdit events and apply the changes to the textarea.
  19. stackedit.on('fileChange', (file) => {
  20.   el.value = file.content.text;
  21. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement