diff options
Diffstat (limited to 'static/app.js')
| -rw-r--r-- | static/app.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/static/app.js b/static/app.js new file mode 100644 index 0000000..7da442b --- /dev/null +++ b/static/app.js @@ -0,0 +1,55 @@ +function parseOrg() { + var orgCode = document.getElementById("editor").value; + var orgParser = new Org.Parser(); + var orgDocument = orgParser.parse(orgCode); + var orgHTMLDocument = orgDocument.convert(Org.ConverterHTML, { + headerOffset: 1, + exportFromLineNumber: false, + suppressSubScriptHandling: false, + suppressAutoLink: false, + }); + + // console.dir(orgHTMLDocument); // => { title, contentHTML, tocHTML, toc } + // console.log(orgHTMLDocument.toString()) // => Rendered HTML + return orgHTMLDocument; +} + +function saveOrg() { + const filename = new Date().toISOString(); + var data = document.getElementById("editor").value; + var file = new Blob([data], { type: Text }); + var a = document.createElement("a"), + url = URL.createObjectURL(file); + a.href = url; + a.download = filename + ".org"; + document.body.appendChild(a); + a.click(); + setTimeout(function () { + document.body.removeChild(a); + window.URL.revokeObjectURL(url); + }, 0); +} + +function saveHTML() { + const filename = new Date().toISOString(); + var data = parseOrg(); + var file = new Blob([data], { type: Text }); + var a = document.createElement("a"), + url = URL.createObjectURL(file); + a.href = url; + a.download = filename + ".html"; + document.body.appendChild(a); + a.click(); + setTimeout(function () { + document.body.removeChild(a); + window.URL.revokeObjectURL(url); + }, 0); +} + +function showHTML() { + var data = parseOrg(); + data += "<form method='dialog'><button>Close dialog</button></form>"; + var element = document.getElementById("modal"); + element.innerHTML = data.toString(); + element.showModal(); +} |
