require "base64"
def html_input(xml)
<<~HTML
blank
#{xml}
HTML
end
def html_input_no_title(xml)
<<~HTML
#{xml}
HTML
end
def html_input_empty_head(xml)
<<~HTML
#{xml}
HTML
end
WORD_HDR = <<~HDR.freeze
MIME-Version: 1.0
Content-Type: multipart/related; boundary="----=_NextPart_"
------=_NextPart_
Content-ID:
Content-Disposition: inline; filename="test.htm"
Content-Type: text/html; charset="utf-8"
blank
HDR
def word_body(xml, footnote)
<<~BODY
#{xml}
#{footnote}
BODY
end
WORD_FTR1 = <<~FTR.freeze
------=_NextPart_
Content-ID:
Content-Disposition: inline; filename="filelist.xml"
Content-Transfer-Encoding: base64
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9ImZp
bGVsaXN0LnhtbCIvPgo8L3htbD4K
------=_NextPart_--
FTR
WORD_FTR2 = <<~FTR.freeze
------=_NextPart_
Content-ID:
Content-Disposition: inline; filename="filelist.xml"
Content-Transfer-Encoding: base64
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9ImZp
bGVsaXN0LnhtbCIvPgogIDxvOkZpbGUgSFJlZj0iaGVhZGVyLmh0bWwiLz4KPC94bWw+Cg==
------=_NextPart_
FTR
WORD_FTR3 = <<~FTR.freeze
------=_NextPart_
Content-ID:
Content-Disposition: inline; filename="filelist.xml"
Content-Transfer-Encoding: base64
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9IjFh
YzIwNjVmLTAzZjAtNGM3YS1iOWE2LTkyZTgyMDU5MWJmMC5wbmciLz4KICA8bzpGaWxlIEhSZWY9
ImZpbGVsaXN0LnhtbCIvPgo8L3htbD4K
------=_NextPart_
Content-ID:
Content-Disposition: inline; filename="cb7b0d19-891e-4634-815a-570d019d454c.png"
Content-Transfer-Encoding: base64
Content-Type: image/png
------=_NextPart_--
FTR
HEADERHTML = <<~FTR.freeze
FTR
ASCII_MATH = 'i=1ni3=nn+122'.freeze
DEFAULT_STYLESHEET = File.read("lib/html2doc/wordstyle.css",
encoding: "utf-8").freeze
def guid_clean(xml)
xml.gsub(/NextPart_[0-9a-f.]+/, "NextPart_")
end
def image_clean(xml)
xml.gsub(%r{[0-9a-f-]+\.png}, "image.png")
.gsub(%r{[0-9a-f-]+\.gif}, "image.gif")
.gsub(%r{[0-9a-f-]+\.(jpeg|jpg)}, "image.jpg")
.gsub(%r{------=_NextPart_\s+Content-Location: file:///C:/Doc/test_files/image\.(png|gif).*?\s-----=_NextPart_}m, "------=_NextPart_")
.gsub(%r{Content-Type: image/(png|gif|jpeg)[^-]*------=_NextPart_-?-?}m, "")
.gsub(%r{ICAgICAg[^-]*-----}m, "-----")
.gsub(%r{\s*\s*}m, "")
.gsub(%r{