Skip to content

Instantly share code, notes, and snippets.

@rgchris
Created December 31, 2021 03:55
Show Gist options
  • Save rgchris/e325347625b1688a1a1fe686610c68ba to your computer and use it in GitHub Desktop.
Save rgchris/e325347625b1688a1a1fe686610c68ba to your computer and use it in GitHub Desktop.
Build a minimal ODT (ODF Text) in R3C
#!/usr/local/bin/ren-r3c
Rebol [
Title: "Package a Minimal OpenText Document"
Date: 30-Dec-2021
Author: "Christopher Ross-Gill"
Rights: http://opensource.org/licenses/Apache-2.0
Home: https://gist.github.com/rgchris/e325347625b1688a1a1fe686610c68ba
]
target: %minimal.odt
minimal-odt: [
%mimetype "application/vnd.oasis.opendocument.text"
%META-INF/manifest.xml {
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd">
<manifest:manifest
xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
<manifest:file-entry
manifest:media-type="application/vnd.oasis.opendocument.text"
manifest:full-path="/"
/>
<manifest:file-entry
manifest:media-type="text/xml"
manifest:full-path="meta.xml"
/>
<manifest:file-entry
manifest:media-type="text/xml"
manifest:full-path="styles.xml"
/>
<manifest:file-entry
manifest:media-type="text/xml"
manifest:full-path="content.xml"
/>
</manifest:manifest>
}
%meta.xml {
<?xml version="1.0" encoding="UTF-8"?>
<office:document-meta
office:version="1.0"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0">
<office:meta>
<meta:generator>R3C/0.0.1</meta:generator>
</office:meta>
</office:document-meta>
}
%styles.xml {
<?xml version="1.0" encoding="UTF-8"?>
<office:document-styles
office:version="1.0"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0">
<office:font-face-decls>
<style:font-face
style:name="Helvetica"
svg:font-family="Helvetica"
/>
</office:font-face-decls>
<office:styles>
<style:default-style
style:family="paragraph">
<style:paragraph-properties
style:tab-stop-distance="36pt"
/>
<style:text-properties
style:font-name="Helvetica"
fo:font-size="12pt"
/>
</style:default-style>
<style:style
style:name="Standard"
style:family="paragraph"
style:class="text"
/>
</office:styles>
<office:automatic-styles>
<style:page-layout
style:name="Standard">
<style:page-layout-properties
fo:page-width="612pt"
fo:page-height="792pt"
style:print-orientation="portrait"
fo:margin-top="36pt"
fo:margin-bottom="36pt"
fo:margin-left="72pt"
fo:margin-right="72pt"
/>
</style:page-layout>
</office:automatic-styles>
<office:master-styles>
<style:master-page
style:name="Standard"
style:page-layout-name="Standard">
</style:master-page>
</office:master-styles>
</office:document-styles>
}
%content.xml {
<?xml version="1.0" encoding="UTF-8"?>
<office:document-content
office:version="1.0"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0">
<office:font-face-decls>
<style:font-face
style:name="Helvetica"
svg:font-family="Helvetica"
/>
</office:font-face-decls>
<office:automatic-styles>
<style:style
style:name="Body"
style:family="paragraph"
style:parent-style-name="Standard">
<style:text-properties
style:font-name="Helvetica"
fo:font-size="12pt"
/>
</style:style>
</office:automatic-styles>
<office:body>
<office:text>
<text:p text:style-name="Body">Hello World!</text:p>
</office:text>
</office:body>
</office:document-content>
}
]
zip target map-each part minimal-odt [
switch type of part [
file! [part]
text! [trim/head/tail trim/auto copy part]
]
]
print "----------------------------------"
call/wait/shell spaced ["zipinfo -l" target]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment