Coder Social home page Coder Social logo

docx2md's Introduction

docx2md

Yet ugly simple script but get the job done. Convert docx to markdown using pandoc.

I have a multi-level folder that contains many mixed doc/docx files along with other file types.

And, I don't wanna play with a word proccessor every time I need to see what it is in the doc/docx file.

Then, I know I have to convert these word files to a text-based format. Yes, markdown, of course, the most widely-used and simplest markup format of humanity :3. And yes, pandoc, a great tool to convert-a-file-format-to-another-file-format.

Requirements:

  • Shell that support text substitution.
  • GNU sed (-i for inline-replacement). Most Linux distro.
  • LibreOffice.
  • Perl (> v5.x.x) comes with Unicode module.
  • Pandoc, of course.

Here what the script actually does:

  • Walks through the folder with multi-level sub-folder
  • Watches all the files for doc or docx:
    • If the file name contans any white-space, replaces the white-space with hyphen (-). I hate the white-spaces in the path!
    • If the file name contains any latin-based char but not the ascii (I mean the Unicode), converts the char to an us-ascii char.
    • What about non-latin chars, suck as CJK? Eh, I don't get it now.
    • Lower-cases the file name. Yes, non-spaces and lower-cases paths. I love it.
    • If the file is doc, convert it to docx. This stage calls libreoffice (or soffice) directly. You also can use unoconv as an alternative. The doc2docx function. Then calls the docx2md function.
    • Removes the converted doc file.
    • Creates one media folder for every docx file to save every extracted media files (jpeg, png, ...) from the being-converted docx file. Named this folder ${the-docx-file-name}-media.
    • Calls the docx2md function. Converts all the docx files to md files. Converts the absolute to relative paths for extracted media files (if any).
    • Remove the converted docx file.
  • Exits the loop.

Unfortunately, you have to delete the empty media folder manually (if any).

That it.

I don't have much time to play with pandoc or Pandoc Template, although I think the out put should be more pleasure.

docx2md's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.