Skip to content

Bashscript to convert Libreoffice Documents to Git Friendly Format

License

Notifications You must be signed in to change notification settings

timwiel/libreoffice2git

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

libreoffice2git

A bashscript to convert Libreoffice Writer Documents (.odt) to a Git Friendly Format with text based diff available

Preamble

Libreoffice file formats are ZIP archives with XML files in them containing the content and styles. As ZIP archives are binary files unfortunately Git (and therefore GitHub, GitLab,etc.) won't display a nice diff for them.

This script provides a work-around in the meantime by creating a folder for each .ODT file and placing within it content that can easily have diff performed on it with good results.

Features

  • Creates a subfolder called <FILENAME.odt.git> in the folder the .odt file resides in
  • Creates Markdown and Plaintext using pandoc
  • Optionally:
    • Exports embeded pictures from the .odt file
    • Exports the whole "flat odt xml" file but tidies the XML using xmllint for easier comparisions

Usage

USAGE: ./libreoffice2git.sh [-hpz] -i <file>

  where:
    -i  --input         Input file (.odt format)
    -p  --pictures      Extract the pictures
    -z  --unzip         Save the full unzipped ODT (includes -p)
    -h  --help          show this help text

Please note that this script requires unzip, pandoc and xmllint to be installed. These are easily installed on Mac (from Homebrew)(e.g. brew install pandoc) or Ubuntu (e.g. apt-get install pandoc)

Examples

Extract just markdown and plaintext from resume.odt

./libreoffice2git.sh --input resume.odt

Extract just markdown and plaintext with pictures from resume.odt

./libreoffice2git.sh --pictures --input resume.odt

Flatten the .odt into xml, pictures with markdown and plaintext from resume.odt

./libreoffice2git.sh --pictures --unzip --input resume.odt

Git Pre-Commit Hook

To automate the git management of the office files you can install a git pre-commit hook that builds the files on already tracked office files.

Just copy the githook-pre-commit to .git/hooks/pre-commit

The libreoffice2git.sh will need to be run on each new .odt file before the hook will track the changes automatically

Based on

This script is based on the powershell script for Microsoft Word .docx files by Tomáš Hübelbauer found at https://github.com/TomasHubelbauer/modern-office-git-diff

About

Bashscript to convert Libreoffice Documents to Git Friendly Format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages