-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
49 lines (46 loc) · 1.63 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<script src="docxtemplater.min.js"></script>
<script src="pizzip.js"></script>
<script src="mammoth.browser.min.js"></script>
</head>
<body>
<title>Annotation App</title>
<input type="file" id="file-input" accept=".docx" onchange='openHTML(event)'/>
<textarea id="text-input" rows="4" cols="50"></textarea>
<div id="output"></div>
</body>
<script>
// load text from file input and display it in text area when file is selected
var openFile = function(event) {
var input = event.target;
var reader = new FileReader();
reader.onload = function() {
var zip = new PizZip(reader.result);
// use options to enable all formatting from original docx
var doc = new window.docxtemplater(zip, {
});
var text = doc.getFullText();
console.log(text);
var node = document.getElementById("text-input");
node.value = text;
};
reader.readAsBinaryString(input.files[0]);
};
// load text from file input and convert it to html displayed in output div
var openHTML = function(event) {
var input = event.target;
mammoth.convertToHtml({path: URL.createObjectURL(input.files[0])})
.then(function(result){
var html = result.value; // The generated HTML
var messages = result.messages; // Any messages, such as warnings during conversion
})
.catch(function(error) {
console.error(error);
});
var output = document.getElementById("output");
output.innerHTML = html;
};
</script>
</html>