Sha256: f4ba8d050fd188724edf5d5db7543df661633e687187cf91516175a9251fea29

Contents?: true

Size: 1017 Bytes

Versions: 2

Compression:

Stored size: 1017 Bytes

Contents

#!/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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reverse_asciidoctor-0.2.0 bin/w2a
reverse_asciidoctor-0.1.0 bin/w2m