require "base64"
def html_input(x)
<<~HTML
blank
#{x}
HTML
end
def html_input_no_title(x)
<<~HTML
#{x}
HTML
end
def html_input_empty_head(x)
<<~HTML
#{x}
HTML
end
WORD_HDR = <<~HDR
MIME-Version: 1.0
Content-Type: multipart/related; boundary="----=_NextPart_"
------=_NextPart_
Content-Location: file:///C:/Doc/test.htm
Content-Type: text/html; charset="utf-8"
blank
HDR
def word_body(x, fn)
<<~BODY
#{x}
#{fn}
BODY
end
WORD_FTR1 = <<~FTR
------=_NextPart_
Content-Location: file:///C:/Doc/test_files/filelist.xml
Content-Transfer-Encoding: base64
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9ImZp
bGVsaXN0LnhtbCIvPgo8L3htbD4K
------=_NextPart_--
FTR
WORD_FTR2 = <<~FTR
------=_NextPart_
Content-Location: file:///C:/Doc/test_files/filelist.xml
Content-Transfer-Encoding: base64
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9ImZp
bGVsaXN0LnhtbCIvPgogIDxvOkZpbGUgSFJlZj0iaGVhZGVyLmh0bWwiLz4KPC94bWw+Cg==
------=_NextPart_
FTR
WORD_FTR3 = <<~FTR
------=_NextPart_
Content-Location: file:///C:/Doc/test_files/filelist.xml
Content-Transfer-Encoding: base64
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9IjFh
YzIwNjVmLTAzZjAtNGM3YS1iOWE2LTkyZTgyMDU5MWJmMC5wbmciLz4KICA8bzpGaWxlIEhSZWY9
ImZpbGVsaXN0LnhtbCIvPgo8L3htbD4K
------=_NextPart_
Content-Location: file:///C:/Doc/test_files/cb7b0d19-891e-4634-815a-570d019d454c.png
Content-Transfer-Encoding: base64
Content-Type: image/png
------=_NextPart_--
FTR
HEADERHTML = <<~FTR
FTR
ASCII_MATH=<<~FTR
i=1
n
i
3
=
(
n
(n+1)
2
)
2
FTR
DEFAULT_STYLESHEET = File.read("lib/html2doc/wordstyle.css", encoding: "utf-8").freeze
def guid_clean(x)
x.gsub(/NextPart_[0-9a-f.]+/, "NextPart_")
end
def image_clean(x)
x.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{