odf
![godocs.io](https://godocs.io/sbinet.org/x/odf?status.svg)
odf
is a set of Go-based tools to deal with the OpenDocument file format.
Installation
$> go install sbinet.org/x/odf
Examples
func main() {
doc, err := odf.Open("testdata/simple.odt")
if err != nil {
panic(err)
}
defer doc.Close()
var depth int
indent := func() string {
return strings.Repeat(" ", depth)
}
err = odf.Walk(doc.Node(), func(n odf.Node, entering bool) (odf.WalkStatus, error) {
switch {
case entering:
ii := indent()
fmt.Printf("%s<%s> {\n", ii, n.Name())
depth++
default:
switch n := n.(type) {
case *odf.Text:
if n.Value != "" {
fmt.Printf("%stext: %q\n", indent(), n.Value)
}
}
depth--
ii := indent()
fmt.Printf("%s}\n", ii)
}
return odf.WalkContinue, nil
})
if err != nil {
panic(err)
}
}
odt2md
odt2md
tries its best at converting an ODT document to a CommonMark one:
$> go install sbinet.org/x/odf/cmd/odt2md@latest
$> odt2md -h
odt2md converts an ODT document into a CommonMark one.
Usage: odt2md [OPTIONS] [INPUT.odt]
Example:
$> odt2md input.odt
$> odt2md input.odt > out.md
$> odt2md -o out.md input.odt
$> odt2md < input.odt > out.md
$> odt2md -o out.md < input.odt
Options:
-o string
path to output CommonMark file
$> odt2md ./testdata/simple.odt
# Title
Hello World!