#!/usr/bin/env ruby # frozen_string_literal: true require 'word-to-markdown' require 'reverse_asciidoctor' def scrub_whitespace(string) string = string.dup string.gsub!(' ', ' ') # HTML encoded spaces string.sub!(/\A[[:space:]]+/, '') # document leading whitespace string.sub!(/[[:space:]]+\z/, '') # document trailing whitespace string.gsub!(/([ ]+)$/, '') # line trailing whitespace string.gsub!(/\n\n\n\n/, "\n\n") # Quadruple line breaks string.delete!(' ') # Unicode non-breaking spaces, injected as tabs string end if ARGV.size != 1 || ARGV[0] == '--help' puts 'Usage: bundle exec w2m path/to/document.docx' exit 1 end if ARGV[0] == '--version' puts "WordToMarkdown v#{WordToMarkdown::VERSION}" puts "LibreOffice v#{WordToMarkdown.soffice.version}" unless Gem.win_platform? else doc = WordToMarkdown.new ARGV[0] # puts doc.to_s puts ReverseAsciidoctor.convert(scrub_whitespace(doc.document.html), WordToMarkdown::REVERSE_MARKDOWN_OPTIONS) end