blob: 2eb226acafdd15abe61d1a31a6c8062a713ea158 (
plain)
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
|
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);
}
|