I'm attempting to produce an ODT document using Node.js, and I'm a little lost as to how I can, or whether templates are a suitable alternative.
The document I want to create is simple: table of contents, heading 1s, and paragraphs following each heading.
I have my book represented simply in program like:
const chapters = [
{
title: "It Begins", paragraphs: [
"On the first day...",
"Things were looking good...",
"Blah blah blah..."
]
},
{
title: "Second Chapter", paragraphs: [
"Blah blah blah..."
]
}
];
Ideally I'd just have something like
const doc = new ODTFile();
chapters.forEach(chapter => {
doc.insert('Heading 1', chapter.title);
chapter.paragraphs.forEach(para => doc.insert('paragraph', para));
});
doc.generateTableOfContents();
doc.writeFile('foo.odt');
Unfortunately there doesn't seem to be much in the way of LibreOffice/ODT libraries available for JS, and none that can request a table of contents be generated.
So my second idea was to maybe create an ODT template, and just pass in values to fill values the template requires. But finding documentation about how to do this has been tricky, especially with the LibreOffice website broken in terms of rendering and partly unreadable. I'm not really clear if templates can handle being passed arbitrary numbers of values or values that nest/pair this way.