summaryrefslogtreecommitdiff
path: root/static/app.js
blob: bfa426e5e3810b533cc3cf0e07f0a1c75d54d0c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
window.onkeyup = keyup;
var inputText;

function keyup(e) {
    // inputText = e.target.value;
    inputText = parseOrg();

    const preview = document.getElementById("preview");
    preview.innerHTML = inputText;
}

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);
}