diff options
Diffstat (limited to 'public/js/marked.js')
| -rw-r--r-- | public/js/marked.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/public/js/marked.js b/public/js/marked.js new file mode 100644 index 0000000..2eb226a --- /dev/null +++ b/public/js/marked.js @@ -0,0 +1,44 @@ +let mainContent; +let inputText; +let htmlResult; //the resulting html to display the inputted markup text +let buttonSave; + +$(function() { + inputText = $('#input_text')[0]; + mainContent = $('main')[0]; + buttonSave = $('#button_save')[0]; + + if (typeof marked == 'undefined'){ + console.error("marked lib not loaded"); + return; + } else { + console.log("marked loaded"); + console.log(marked); + } + + inputText.oninput = ()=>{ + htmlResult = marked.parse(inputText.value); + mainContent.innerHTML = htmlResult; + }; + + buttonSave.onclick = async ()=>{ + //save to local file + console.log(htmlResult); + + downloadFile(htmlResult, 'markdown-doc.html', 'text/plain'); + + }; +}); + +function downloadFile(content, fileName, mimeType) { + const blob = new Blob([content], {type: mimeType}); + + const url = window.URL.createObjectURL(blob); + + const a = document.createElement('a'); + a.href = url; + a.download = fileName; + a.click(); + + window.URL.revokeObjectURL(url); +}
\ No newline at end of file |
