blob: fdf451f52d764c31c8c81e21f1e7c9d41353a4ee (
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
|
exports.DocumentXmlReader = DocumentXmlReader;
var documents = require("../documents");
var Result = require("../results").Result;
function DocumentXmlReader(options) {
var bodyReader = options.bodyReader;
var rawNotes = (options.footnotes || []).concat(options.endnotes || []);
function convertXmlToDocument(documentXml) {
var body = documentXml.root.first("w:body");
var result = bodyReader.readXmlElements(body.children)
.flatMap(function(children) {
return readNotes().map(function(notes) {
return new documents.Document(children, {notes: notes});
});
});
return new Result(result.value, result.messages);
}
function readNotes() {
return Result.combine(rawNotes.map(function(rawNote) {
return bodyReader.readXmlElements(rawNote.body).map(function(body) {
return new documents.Note({
noteType: rawNote.noteType,
noteId: rawNote.id,
body: body
});
});
})).map(function(notes) {
return new documents.Notes(notes);
});
}
return {
convertXmlToDocument: convertXmlToDocument
};
}
|