odfjs/scripts/odf/makeManifestFile.js
David Bruant 57dfb4f050
Templ odt (#8)
* add rough roadmap

* adding test of odt template filling

* progress

* avec les titres

* premier jet de remplacement

* progress i guess

* Bimz ! Remplissage de template et passage de tests !

* nettoyages

* zip entries async generator

* un fichier d'exemple pour la génération d'une liste de courses

* Test avec le each et amélioration de getOdtTextContent

* yep

* Le test du each passe mais pas encore la création du fichier .odt

* Meilleur packaging du zip

* Création d'un fichier à partir d'un template - le fichier de sortie s'ouvre avec LibreOffice !!

* Génération d'une liste dans un .odt

* 2 sibling each in a document

* add nested each test

* Génération d'un tableau avec un {#each}

* Refacto API for Node.js

* add fillOdtTemplate to browser exports

* Mention template filling in  readme
2025-04-07 11:00:18 +02:00

44 lines
1.3 KiB
JavaScript

/*
As specified by https://docs.oasis-open.org/office/OpenDocument/v1.3/os/part2-packages/OpenDocument-v1.3-os-part2-packages.html#__RefHeading__752825_826425813
*/
/** @typedef {'application/vnd.oasis.opendocument.text' | 'application/vnd.oasis.opendocument.spreadsheet'} ODFMediaType */
/** @typedef {'1.2' | '1.3' | '1.4'} ODFVersion */
/**
* @typedef ODFManifestFileEntry
* @prop {string} fullPath
* @prop {string} mediaType
* @prop {string} [version]
*/
/**
* @typedef ODFManifest
* @prop {ODFMediaType} mediaType
* @prop {ODFVersion} version
* @prop {ODFManifestFileEntry[]} fileEntries
*/
/**
*
* @param {ODFManifestFileEntry} fileEntry
* @returns {string}
*/
function makeFileEntry({fullPath, mediaType}){
return `<manifest:file-entry manifest:full-path="${fullPath}" manifest:media-type="${mediaType}"/>`
}
/**
*
* @param {ODFManifest} odfManifest
* @returns {string}
*/
export default function makeManifestFile({fileEntries, mediaType, version}){
return `<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="${version}">
<manifest:file-entry manifest:full-path="/" manifest:version="${version}" manifest:media-type="${mediaType}"/>
${fileEntries.map(makeFileEntry).join('\n')}
</manifest:manifest>`
}