-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (39 loc) · 1.16 KB
/
Copy pathindex.js
File metadata and controls
45 lines (39 loc) · 1.16 KB
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
var stream = require('stream');
var extend = require('extend');
var Transform = require('stream').Transform;
// var jsdom = require('jsdom');
// var docx = require('./lib/docx.js');
var toDocx = function constructToDocx(options) {
console.log('constructToDocx', options);
var transform = new Transform({decodeStrings: false});
transform.options = options;
transform.htmlBuffer = null;
transform._transform = function _transform(chunk, encoding, done) {
console.log('toDoc._transform');
if (!this.htmlBuffer) {
this.htmlBuffer = new Buffer(chunk.length);
chunk.copy(this.htmlBuffer);
} else {
this.htmlBuffer = Buffer.concat([this.htmlBuffer, chunk]);
}
done(null, null);
};
transform.html2docx = function html2docx(html) {
console.log('toDoc.html2docx');
// var dom = jsdom.jsdom({
// url: options.url,
// html: html,
// });
// return docx.convertContent(dom);
return html;
};
transform._flush = function _flush(done) {
console.log('toDoc._flush');
this.push(this.html2docx(this.htmlBuffer.toString()));
done(null);
};
return transform;
};
module.exports = {
toDocx: toDocx
};