4

I'm trying to export a word document as HTML from LibreOffice on Linux. I'd like to take that output and be able to clean it up:

  • Strip out any tags that are not on a white list that I specify (I really want to preserve p , a, ul, and li tags, but not much else).
  • Remove unneeded attributes, especially style, class, and id.
  • Remove any comments
  • Pretty print the result
  • I'd like to be able to run it on the command line on Linux to pipe a file through it, although I'd be open to using a GUI program or finding a website that offered this as a service.
1

You should try grunt, it is a javascript task runner. And this kind of tasks are commonly supported in specific and well supported modules. For example this one (grunt-processhtml) is very customizable and I think it is perfect for what you are trying to do although it will need you to code a little. Its description is:

Process html files at build time to modify them depending on the release environment

To start with grunt you will need nodejs, but no worries, I assure you that it will be a time well invested and you can get to know all you need pretty fast.

  1. Download and install nodejs.
  2. Install the grunt client. In your console (not in nodejs console) type npm install -g grunt-cli (if using linux, you should do this with super user privileges).
  3. Install grunt in your current directory. In your console type npm install grunt.
  4. Install your grunt commponents also with npm. e.g. npm install grunt-processhtml npm install grunt-htmlclean.
  5. Configure your tasks, that is pretty easy and you can learn to do it with the the instructions given in this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.