简体   繁体   中英

Get the html from ToastUI (that shows the markdown text) editor to save in database

I have an editor from ToastUI (source code:

<html>
<head>
  <title>TOAST UI</title>
  <script src="https://uicdn.toast.com/tui-editor/latest/tui-editor-Editor-full.js"></script>
  <script src="https://code.jquery.com/jquery-1.12.3.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.min.css" />
  <link rel="stylesheet" href="https://uicdn.toast.com/editor/latest/toastui-editor.min.css" />
  </script>
</head>

<body>
  
  <div id="editorSection">
  </div>
    <button id = "but">Hello</button>
 
<script>
  var editor = new tui.Editor({
    el: document.querySelector('#editorSection'),
    previewStyle: 'vertical',
    height: '300px',
    initialEditType: 'markdown'
  });
  document.querySelector("#but").addEventListener("click", function() {
    //I want such html to make the markdown text, but this doesn't work.
     console.log(document.querySelector('#editorSection').textContent)
     
  })
</script>
</body>

</html>

and it works, but I want to save the markdown text to a database on a click of a button. How to do this?

document.querySelector("#but").addEventListener("click", function() {
    //I want such html to make the markdown text, but this doesn't work.
     console.log(document.querySelector('#editorSection').textContent)
     
  })
editor = new tui.Editor({
    el: document.querySelector('#editorSection'),
    previewStyle: 'vertical',
    height: '300px',
    initialEditType: 'markdown'
  }); 

editor.getHtml();
editor.getMarkdown();

Both options are possible.

Hope can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM