html2doc 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,11 +64,11 @@ WORD_HDR_END = <<~HDR.freeze
64
64
  </head>
65
65
  HDR
66
66
 
67
- def word_body(x, fn)
67
+ def word_body(xml, footnote)
68
68
  <<~BODY
69
69
  <body>
70
- #{x}
71
- #{fn}</body></html>
70
+ #{xml}
71
+ #{footnote}</body></html>
72
72
  BODY
73
73
  end
74
74
 
@@ -317,26 +317,36 @@ RSpec.describe Html2Doc do
317
317
  end
318
318
 
319
319
  it "processes a stylesheet in an HTML document with an empty head" do
320
- Html2Doc.process(html_input_empty_head(""), filename: "test", stylesheet: "lib/html2doc/wordstyle.css")
320
+ Html2Doc.process(html_input_empty_head(""),
321
+ filename: "test", stylesheet: "lib/html2doc/wordstyle.css")
322
+ word_hdr_end = WORD_HDR_END
323
+ .sub(%(<meta name="Originator" content="Me"/>\n), "")
324
+ .sub("</style>\n</head>", "</style></head>")
321
325
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
322
326
  .to match_fuzzy(<<~OUTPUT)
323
327
  #{WORD_HDR.sub('<title>blank</title>', '')}
324
328
  #{DEFAULT_STYLESHEET}
325
- #{WORD_HDR_END.sub('<meta name="Originator" content="Me"/>' + "\n", '').sub("</style>\n</head>", '</style></head>')}
329
+ #{word_hdr_end}
326
330
  #{word_body('', '<div style="mso-element:footnote-list"/>')} #{WORD_FTR1}
327
331
  OUTPUT
328
332
  end
329
333
 
330
334
  it "processes a header" do
331
- Html2Doc.process(html_input(""), filename: "test", header_file: "spec/header.html")
335
+ Html2Doc.process(html_input(""),
336
+ filename: "test", header_file: "spec/header.html")
332
337
  html = guid_clean(File.read("test.doc", encoding: "utf-8"))
333
- hdr = Base64.decode64(html.sub(%r{^.*Content-Location: file:///C:/Doc/test_files/header.html}, "")
334
- .sub(%r{^.*Content-Type: text/html charset="utf-8"}m, "")
335
- .sub(%r{------=_NextPart_--.*$}m, "")).force_encoding("UTF-8")
338
+ hdr = Base64.decode64(
339
+ html
340
+ .sub(%r{^.*Content-Location: file:///C:/Doc/test_files/header.html}, "")
341
+ .sub(%r{^.*Content-Type: text/html charset="utf-8"}m, "")
342
+ .sub(%r{------=_NextPart_--.*$}m, ""),
343
+ ).force_encoding("UTF-8")
336
344
  # expect(hdr.gsub(/\xa0/, " ")).to match_fuzzy(HEADERHTML)
337
345
  expect(HTMLEntities.new.encode(hdr, :hexadecimal)
338
- .gsub(/&#x3c;/, "<").gsub(/&#x3e;/, ">").gsub(/&#x27;/, "'").gsub(/&#x22;/, '"')
339
- .gsub(/&#xd;/, "&#xa;").gsub(/&#xa;/, "\n")).to match_fuzzy(HEADERHTML)
346
+ .gsub(/&#x3c;/, "<").gsub(/&#x3e;/, ">")
347
+ .gsub(/&#x27;/, "'").gsub(/&#x22;/, '"')
348
+ .gsub(/&#xd;/, "&#xa;").gsub(/&#xa;/, "\n"))
349
+ .to match_fuzzy(HEADERHTML)
340
350
  expect(html.sub(%r{Content-ID: <header.html>.*$}m, ""))
341
351
  .to match_fuzzy(<<~OUTPUT)
342
352
  #{WORD_HDR} #{DEFAULT_STYLESHEET.gsub(/url\("[^"]+"\)/, 'url(cid:header.html)')}
@@ -345,7 +355,8 @@ RSpec.describe Html2Doc do
345
355
  end
346
356
 
347
357
  it "processes a header with an image" do
348
- Html2Doc.process(html_input(""), filename: "test", header_file: "spec/header_img.html")
358
+ Html2Doc.process(html_input(""),
359
+ filename: "test", header_file: "spec/header_img.html")
349
360
  doc = guid_clean(File.read("test.doc", encoding: "utf-8"))
350
361
  expect(doc).to match(%r{Content-Type: image/png})
351
362
  expect(doc).to match(%r{iVBORw0KGgoAAAANSUhEUgAAA5cAAAN7CAYAAADRE24cAAAgAElEQVR4XuydB5gUxdaGC65gTogB})
@@ -354,9 +365,13 @@ RSpec.describe Html2Doc do
354
365
  it "processes a header with an image with absolute path" do
355
366
  doc = File.read("spec/header_img.html", encoding: "utf-8")
356
367
  File.open("spec/header_img1.html", "w:UTF-8") do |f|
357
- f.write doc.sub(%r{spec/19160-6.png}, File.expand_path(File.join(File.dirname(__FILE__), "19160-6.png")))
368
+ f.write(
369
+ doc.sub(%r{spec/19160-6.png},
370
+ File.expand_path(File.join(File.dirname(__FILE__), "19160-6.png"))),
371
+ )
358
372
  end
359
- Html2Doc.process(html_input(""), filename: "test", header_file: "spec/header_img1.html")
373
+ Html2Doc.process(html_input(""),
374
+ filename: "test", header_file: "spec/header_img1.html")
360
375
  doc = guid_clean(File.read("test.doc", encoding: "utf-8"))
361
376
  expect(doc).to match(%r{Content-Type: image/png})
362
377
  expect(doc).to match(%r{iVBORw0KGgoAAAANSUhEUgAAA5cAAAN7CAYAAADRE24cAAAgAElEQVR4XuydB5gUxdaGC65gTogB})
@@ -375,43 +390,46 @@ RSpec.describe Html2Doc do
375
390
  end
376
391
 
377
392
  it "processes AsciiMath" do
378
- Html2Doc.process(html_input(%[<div>{{sum_(i=1)^n i^3=((n(n+1))/2)^2 text("integer"))}}</div>]), filename: "test", asciimathdelims: ["{{", "}}"])
393
+ Html2Doc.process(html_input(%[<div>{{sum_(i=1)^n i^3=((n(n+1))/2)^2 text("integer"))}}</div>]),
394
+ filename: "test", asciimathdelims: ["{{", "}}"])
379
395
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
380
396
  .to match_fuzzy(<<~OUTPUT)
381
397
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
382
398
  #{word_body(%{
383
- <div><m:oMath>
384
- <m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>"integer"</m:t></m:r><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>)</m:t></m:r></span>
385
- </m:oMath>
386
- </div>}, '<div style="mso-element:footnote-list"/>')}
399
+ <div><m:oMath>
400
+ <m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>"integer"</m:t></m:r><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>)</m:t></m:r></span>
401
+ </m:oMath>
402
+ </div>}, '<div style="mso-element:footnote-list"/>')}
387
403
  #{WORD_FTR1}
388
404
  OUTPUT
389
405
  end
390
406
 
391
407
  it "processes mstyle" do
392
- Html2Doc.process(html_input(%[<div>{{bb (-log_2 (p_u)) bb "BB" bbb "BBB" cc "CC" bcc "BCC" tt "TT" fr "FR" bfr "BFR" sf "SF" bsf "BSFα" sfi "SFI" sfbi "SFBIα" bii "BII" ii "II"}}</div>]), filename: "test", asciimathdelims: ["{{", "}}"])
408
+ Html2Doc.process(html_input(%[<div>{{bb (-log_2 (p_u)) bb "BB" bbb "BBB" cc "CC" bcc "BCC" tt "TT" fr "FR" bfr "BFR" sf "SF" bsf "BSFα" sfi "SFI" sfbi "SFBIα" bii "BII" ii "II"}}</div>]),
409
+ filename: "test", asciimathdelims: ["{{", "}}"])
393
410
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
394
411
  .to match_fuzzy(<<~OUTPUT)
395
412
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
396
413
  #{word_body(%{
397
- <div><m:oMath>
398
- <span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>&#x2212;</m:t></m:r></span><m:sSub><m:e><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>log</m:t></m:r></span></m:e><m:sub><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>2</m:t></m:r></span></m:sub></m:sSub><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:sSub><m:e><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>p</m:t></m:r></span></m:e><m:sub><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>u</m:t></m:r></span></m:sub></m:sSub></m:e></m:d><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:nor></m:nor><m:sty m:val="b"></m:sty></m:rPr><m:t>BB</m:t></m:r></span><m:r><m:rPr><m:nor></m:nor><m:scr m:val="double-struck"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D539;&#x1D539;&#x1D539;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="script"></m:scr></m:rPr><m:t>&#x1D49E;&#x1D49E;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="script"></m:scr><m:sty m:val="b"></m:sty></m:rPr><m:t>&#x1D4D1;&#x1D4D2;&#x1D4D2;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="monospace"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D683;&#x1D683;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="fraktur"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D509;&#x211C;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="fraktur"></m:scr><m:sty m:val="b"></m:sty></m:rPr><m:t>&#x1D56D;&#x1D571;&#x1D57D;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D5B2;&#x1D5A5;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="b"></m:sty></m:rPr><m:t>&#x1D5D5;&#x1D5E6;&#x1D5D9;&#x1D770;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr></m:rPr><m:t>&#x1D5B2;&#x1D5A5;&#x1D5A8;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="bi"></m:sty></m:rPr><m:t>&#x1D64E;&#x1D641;&#x1D63D;&#x1D644;&#x1D7AA;</m:t></m:r><span class="nostem" style="font-weight:bold;"><em></em><m:r><m:rPr><m:nor></m:nor><m:sty m:val="bi"></m:sty></m:rPr><m:t>BII</m:t></m:r></span><span class="nostem"><em></em><m:r><m:rPr><m:nor></m:nor><m:sty m:val="i"></m:sty></m:rPr><m:t>II</m:t></m:r></span>
399
- </m:oMath>
400
- </div>}, '<div style="mso-element:footnote-list"/>')}
414
+ <div><m:oMath>
415
+ <span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>&#x2212;</m:t></m:r></span><m:sSub><m:e><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>log</m:t></m:r></span></m:e><m:sub><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>2</m:t></m:r></span></m:sub></m:sSub><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:sSub><m:e><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>p</m:t></m:r></span></m:e><m:sub><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>u</m:t></m:r></span></m:sub></m:sSub></m:e></m:d><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:nor></m:nor><m:sty m:val="b"></m:sty></m:rPr><m:t>BB</m:t></m:r></span><m:r><m:rPr><m:nor></m:nor><m:scr m:val="double-struck"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D539;&#x1D539;&#x1D539;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="script"></m:scr></m:rPr><m:t>&#x1D49E;&#x1D49E;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="script"></m:scr><m:sty m:val="b"></m:sty></m:rPr><m:t>&#x1D4D1;&#x1D4D2;&#x1D4D2;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="monospace"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D683;&#x1D683;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="fraktur"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D509;&#x211C;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="fraktur"></m:scr><m:sty m:val="b"></m:sty></m:rPr><m:t>&#x1D56D;&#x1D571;&#x1D57D;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>&#x1D5B2;&#x1D5A5;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="b"></m:sty></m:rPr><m:t>&#x1D5D5;&#x1D5E6;&#x1D5D9;&#x1D770;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr></m:rPr><m:t>&#x1D5B2;&#x1D5A5;&#x1D5A8;</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="bi"></m:sty></m:rPr><m:t>&#x1D64E;&#x1D641;&#x1D63D;&#x1D644;&#x1D7AA;</m:t></m:r><span class="nostem" style="font-weight:bold;"><em></em><m:r><m:rPr><m:nor></m:nor><m:sty m:val="bi"></m:sty></m:rPr><m:t>BII</m:t></m:r></span><span class="nostem"><em></em><m:r><m:rPr><m:nor></m:nor><m:sty m:val="i"></m:sty></m:rPr><m:t>II</m:t></m:r></span>
416
+ </m:oMath>
417
+ </div>}, '<div style="mso-element:footnote-list"/>')}
401
418
  #{WORD_FTR1}
402
419
  OUTPUT
403
420
  end
404
421
 
405
422
  it "processes spaces in AsciiMath" do
406
- Html2Doc.process(html_input(%[<div>{{text " integer ")}}</div>]), filename: "test", asciimathdelims: ["{{", "}}"])
423
+ Html2Doc.process(html_input(%[<div>{{text " integer ")}}</div>]),
424
+ filename: "test", asciimathdelims: ["{{", "}}"])
407
425
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
408
426
  .to match_fuzzy(<<~OUTPUT)
409
427
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
410
428
  #{word_body('
411
- <div><m:oMath>
412
- <m:r><m:t>text</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>&#xA0;integer&#xA0;</m:t></m:r><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>)</m:t></m:r></span>
413
- </m:oMath>
414
- </div>', '<div style="mso-element:footnote-list"/>')}
429
+ <div><m:oMath>
430
+ <m:r><m:t>text</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>&#xA0;integer&#xA0;</m:t></m:r><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>)</m:t></m:r></span>
431
+ </m:oMath>
432
+ </div>', '<div style="mso-element:footnote-list"/>')}
415
433
  #{WORD_FTR1}
416
434
  OUTPUT
417
435
  end
@@ -419,14 +437,15 @@ RSpec.describe Html2Doc do
419
437
  it "processes spaces in MathML mtext" do
420
438
  Html2Doc.process(html_input("<div><math xmlns='http://www.w3.org/1998/Math/MathML'>
421
439
  <mrow><mi>H</mi><mtext> original </mtext><mi>J</mi></mrow>
422
- </math></div>"), filename: "test", asciimathdelims: ["{{", "}}"])
440
+ </math></div>"),
441
+ filename: "test", asciimathdelims: ["{{", "}}"])
423
442
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
424
443
  .to match_fuzzy(<<~OUTPUT)
425
444
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
426
445
  #{word_body('<div><m:oMath>
427
- <m:r><m:t>H</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>&#xA0;original&#xA0;</m:t></m:r><m:r><m:t>J</m:t></m:r>
428
- </m:oMath>
429
- </div>', '<div style="mso-element:footnote-list"/>')}
446
+ <m:r><m:t>H</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>&#xA0;original&#xA0;</m:t></m:r><m:r><m:t>J</m:t></m:r>
447
+ </m:oMath>
448
+ </div>', '<div style="mso-element:footnote-list"/>')}
430
449
  #{WORD_FTR1}
431
450
  OUTPUT
432
451
  end
@@ -439,58 +458,67 @@ RSpec.describe Html2Doc do
439
458
  .to match_fuzzy(<<~OUTPUT)
440
459
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
441
460
  #{word_body('<div><m:oMath>
442
- <m:acc><m:accPr><m:chr m:val="^"></m:chr></m:accPr><m:e><m:r><m:t>p</m:t></m:r></m:e></m:acc>
443
- </m:oMath>
444
- </div>', '<div style="mso-element:footnote-list"/>')}
461
+ <m:acc><m:accPr><m:chr m:val="^"></m:chr></m:accPr><m:e><m:r><m:t>p</m:t></m:r></m:e></m:acc>
462
+ </m:oMath>
463
+ </div>', '<div style="mso-element:footnote-list"/>')}
445
464
  #{WORD_FTR1}
446
465
  OUTPUT
447
466
  end
448
467
 
449
468
  it "left-aligns AsciiMath" do
450
- Html2Doc.process(html_input("<div style='text-align:left;'>{{sum_(i=1)^n i^3=((n(n+1))/2)^2}}</div>"), filename: "test", asciimathdelims: ["{{", "}}"])
469
+ Html2Doc.process(html_input("<div style='text-align:left;'>{{sum_(i=1)^n i^3=((n(n+1))/2)^2}}</div>"),
470
+ filename: "test", asciimathdelims: ["{{", "}}"])
451
471
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
452
472
  .to match_fuzzy(<<~OUTPUT)
453
473
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
454
474
  #{word_body(%{
455
- <div style="text-align:left;"><m:oMathPara><m:oMathParaPr><m:jc m:val="left"/></m:oMathParaPr><m:oMath>
456
- <m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
457
- </m:oMath>
458
- </m:oMathPara></div>}, '<div style="mso-element:footnote-list"/>')}
475
+ <div style="text-align:left;"><m:oMathPara><m:oMathParaPr><m:jc m:val="left"/></m:oMathParaPr><m:oMath>
476
+ <m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
477
+ </m:oMath>
478
+ </m:oMathPara></div>}, '<div style="mso-element:footnote-list"/>')}
459
479
  #{WORD_FTR1}
460
480
  OUTPUT
461
481
  end
462
482
 
463
483
  it "right-aligns AsciiMath" do
464
- Html2Doc.process(html_input("<div style='text-align:right;'>{{sum_(i=1)^n i^3=((n(n+1))/2)^2}}</div>"), filename: "test", asciimathdelims: ["{{", "}}"])
484
+ Html2Doc.process(html_input("<div style='text-align:right;'>{{sum_(i=1)^n i^3=((n(n+1))/2)^2}}</div>"),
485
+ filename: "test", asciimathdelims: ["{{", "}}"])
465
486
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
466
487
  .to match_fuzzy(<<~OUTPUT)
467
488
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
468
489
  #{word_body(%{
469
- <div style="text-align:right;"><m:oMathPara><m:oMathParaPr><m:jc m:val="right"/></m:oMathParaPr><m:oMath>
470
- <m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
471
- </m:oMath>
472
- </m:oMathPara></div>}, '<div style="mso-element:footnote-list"/>')}
490
+ <div style="text-align:right;"><m:oMathPara><m:oMathParaPr><m:jc m:val="right"/></m:oMathParaPr><m:oMath>
491
+ <m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
492
+ </m:oMath>
493
+ </m:oMathPara></div>}, '<div style="mso-element:footnote-list"/>')}
473
494
  #{WORD_FTR1}
474
495
  OUTPUT
475
496
  end
476
497
 
477
498
  it "raises error in processing of broken AsciiMath" do
478
499
  begin
479
- expect { Html2Doc.process(html_input(%[<div style='text-align:right;'>{{u_c = 6.6"unitsml(kHz)}}</div>]), filename: "test", asciimathdelims: ["{{", "}}"]) }.to output('parsing: u_c = 6.6"unitsml(kHz)').to_stderr
500
+ expect do
501
+ Html2Doc.process(html_input(%[<div style='text-align:right;'>{{u_c = 6.6"unitsml(kHz)}}</div>]),
502
+ filename: "test", asciimathdelims: ["{{", "}}"])
503
+ end.to output('parsing: u_c = 6.6"unitsml(kHz)').to_stderr
480
504
  rescue StandardError
481
505
  end
482
- expect { Html2Doc.process(html_input(%[<div style='text-align:right;'>{{u_c = 6.6"unitsml(kHz)}}</div>]), filename: "test", asciimathdelims: ["{{", "}}"]) }.to raise_error(StandardError)
506
+ expect do
507
+ Html2Doc.process(html_input(%[<div style='text-align:right;'>{{u_c = 6.6"unitsml(kHz)}}</div>]),
508
+ filename: "test", asciimathdelims: ["{{", "}}"])
509
+ end.to raise_error(StandardError)
483
510
  end
484
511
 
485
512
  it "wraps msup after munderover in MathML" do
486
513
  Html2Doc.process(html_input("<div><math xmlns='http://www.w3.org/1998/Math/MathML'>
487
- <munderover><mo>&#x2211;</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow><mi>n</mi></mrow></munderover><msup><mn>2</mn><mrow><mi>i</mi></mrow></msup></math></div>"), filename: "test", asciimathdelims: ["{{", "}}"])
514
+ <munderover><mo>&#x2211;</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow><mi>n</mi></mrow></munderover><msup><mn>2</mn><mrow><mi>i</mi></mrow></msup></math></div>"),
515
+ filename: "test", asciimathdelims: ["{{", "}}"])
488
516
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
489
517
  .to match_fuzzy(<<~OUTPUT)
490
518
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
491
519
  #{word_body('<div><m:oMath>
492
- <m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=0</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>2</m:t></m:r></m:e><m:sup><m:r><m:t>i</m:t></m:r></m:sup></m:sSup></m:e></m:nary></m:oMath>
493
- </div>', '<div style="mso-element:footnote-list"/>')}
520
+ <m:nary><m:naryPr><m:chr m:val="&#x2211;"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=0</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>2</m:t></m:r></m:e><m:sup><m:r><m:t>i</m:t></m:r></m:sup></m:sSup></m:e></m:nary></m:oMath>
521
+ </div>', '<div style="mso-element:footnote-list"/>')}
494
522
  #{WORD_FTR1}
495
523
  OUTPUT
496
524
  end
@@ -537,7 +565,7 @@ RSpec.describe Html2Doc do
537
565
 
538
566
  it "resizes images for height, in a file in a subdirectory" do
539
567
  simple_body = '<img src="19160-6.png">'
540
- Html2Doc.process(html_input(simple_body), filename: "spec/test")
568
+ Html2Doc.process(html_input(simple_body), filename: "spec/test", imagedir: "spec")
541
569
  testdoc = File.read("spec/test.doc", encoding: "utf-8")
542
570
  expect(testdoc).to match(%r{Content-Type: image/png})
543
571
  expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
@@ -549,7 +577,7 @@ RSpec.describe Html2Doc do
549
577
 
550
578
  it "resizes images for width" do
551
579
  simple_body = '<img src="spec/19160-7.gif">'
552
- Html2Doc.process(html_input(simple_body), filename: "test")
580
+ Html2Doc.process(html_input(simple_body), filename: "test", imagedir: ".")
553
581
  testdoc = File.read("test.doc", encoding: "utf-8")
554
582
  expect(testdoc).to match(%r{Content-Type: image/gif})
555
583
  expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
@@ -561,7 +589,7 @@ RSpec.describe Html2Doc do
561
589
 
562
590
  it "resizes images for height" do
563
591
  simple_body = '<img src="spec/19160-8.jpg">'
564
- Html2Doc.process(html_input(simple_body), filename: "test")
592
+ Html2Doc.process(html_input(simple_body), filename: "test", imagedir: ".")
565
593
  testdoc = File.read("test.doc", encoding: "utf-8")
566
594
  expect(testdoc).to match(%r{Content-Type: image/jpeg})
567
595
  expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
@@ -573,38 +601,48 @@ RSpec.describe Html2Doc do
573
601
 
574
602
  it "resizes images with missing or auto sizes" do
575
603
  image = { "src" => "spec/19160-8.jpg" }
576
- expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
604
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
605
+ .to eq [30, 100]
577
606
  image["width"] = "20"
578
- expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [20, 65]
607
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
608
+ .to eq [20, 65]
579
609
  image.delete("width")
580
610
  image["height"] = "50"
581
- expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [15, 50]
611
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
612
+ .to eq [15, 50]
582
613
  image.delete("height")
583
614
  image["width"] = "500"
584
- expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
615
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
616
+ .to eq [30, 100]
585
617
  image.delete("width")
586
618
  image["height"] = "500"
587
- expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
619
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
620
+ .to eq [30, 100]
588
621
  image["width"] = "20"
589
622
  image["height"] = "auto"
590
- expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [20, 65]
623
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
624
+ .to eq [20, 65]
591
625
  image["width"] = "auto"
592
626
  image["height"] = "50"
593
- expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [15, 50]
627
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
628
+ .to eq [15, 50]
594
629
  image["width"] = "500"
595
630
  image["height"] = "auto"
596
- expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
631
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
632
+ .to eq [30, 100]
597
633
  image["width"] = "auto"
598
634
  image["height"] = "500"
599
- expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
635
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
636
+ .to eq [30, 100]
600
637
  image["width"] = "auto"
601
638
  image["height"] = "auto"
602
- expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100)).to eq [30, 100]
639
+ expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
640
+ .to eq [30, 100]
603
641
  end
604
642
 
605
643
  it "does not move images if they are external URLs" do
606
644
  simple_body = '<img src="https://example.com/19160-6.png">'
607
- Html2Doc.process(html_input(simple_body), filename: "test")
645
+ Html2Doc.process(html_input(simple_body), filename: "test", imagedir: ".")
608
646
  testdoc = File.read("test.doc", encoding: "utf-8")
609
647
  expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
610
648
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
@@ -615,7 +653,7 @@ RSpec.describe Html2Doc do
615
653
 
616
654
  it "deals with absolute image locations" do
617
655
  simple_body = %{<img src="#{__dir__}/19160-6.png">}
618
- Html2Doc.process(html_input(simple_body), filename: "spec/test")
656
+ Html2Doc.process(html_input(simple_body), filename: "spec/test", imagedir: ".")
619
657
  testdoc = File.read("spec/test.doc", encoding: "utf-8")
620
658
  expect(testdoc).to match(%r{Content-Type: image/png})
621
659
  expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
@@ -627,7 +665,8 @@ RSpec.describe Html2Doc do
627
665
 
628
666
  # it "warns about SVG" do
629
667
  # simple_body = '<img src="https://example.com/19160-6.svg">'
630
- # expect{ Html2Doc.process(html_input(simple_body), filename: "test") }.to output("https://example.com/19160-6.svg: SVG not supported\n").to_stderr
668
+ # expect{ Html2Doc.process(html_input(simple_body), filename: "test") }
669
+ # .to output("https://example.com/19160-6.svg: SVG not supported\n").to_stderr
631
670
  # end
632
671
 
633
672
  it "processes epub:type footnotes" do
@@ -638,15 +677,15 @@ RSpec.describe Html2Doc do
638
677
  Html2Doc.process(html_input(simple_body), filename: "test")
639
678
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
640
679
  .to match_fuzzy(<<~OUTPUT)
641
- #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
642
- #{word_body('<div>This is a very simple
643
- document<a epub:type="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a> allegedly<a epub:type="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
644
- '<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
645
- <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
646
- <div style="mso-element:footnote" id="ftn2">
647
- <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
648
- </div>')}
649
- #{WORD_FTR1}
680
+ #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
681
+ #{word_body('<div>This is a very simple
682
+ document<a epub:type="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a> allegedly<a epub:type="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
683
+ '<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
684
+ <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
685
+ <div style="mso-element:footnote" id="ftn2">
686
+ <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
687
+ </div>')}
688
+ #{WORD_FTR1}
650
689
  OUTPUT
651
690
  end
652
691
 
@@ -658,15 +697,15 @@ RSpec.describe Html2Doc do
658
697
  Html2Doc.process(html_input(simple_body), filename: "test")
659
698
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
660
699
  .to match_fuzzy(<<~OUTPUT)
661
- #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
662
- #{word_body('<div>This is a very simple
663
- document<a class="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a> allegedly<a class="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
664
- '<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
665
- <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
666
- <div style="mso-element:footnote" id="ftn2">
667
- <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
668
- </div>')}
669
- #{WORD_FTR1}
700
+ #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
701
+ #{word_body('<div>This is a very simple
702
+ document<a class="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a> allegedly<a class="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
703
+ '<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
704
+ <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
705
+ <div style="mso-element:footnote" id="ftn2">
706
+ <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
707
+ </div>')}
708
+ #{WORD_FTR1}
670
709
  OUTPUT
671
710
  end
672
711
 
@@ -678,15 +717,15 @@ RSpec.describe Html2Doc do
678
717
  Html2Doc.process(html_input(simple_body), filename: "test")
679
718
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
680
719
  .to match_fuzzy(<<~OUTPUT)
681
- #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
682
- #{word_body('<div>This is a very simple
683
- document<a class="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference">(</span><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span><span class="MsoFootnoteReference">)</span></a> allegedly<a class="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
684
- '<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
685
- <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference">(</span><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span><span class="MsoFootnoteReference">)</span></a>Footnote</p></div>
686
- <div style="mso-element:footnote" id="ftn2">
687
- <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
688
- </div>')}
689
- #{WORD_FTR1}
720
+ #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
721
+ #{word_body('<div>This is a very simple
722
+ document<a class="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference">(</span><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span><span class="MsoFootnoteReference">)</span></a> allegedly<a class="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
723
+ '<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
724
+ <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference">(</span><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span><span class="MsoFootnoteReference">)</span></a>Footnote</p></div>
725
+ <div style="mso-element:footnote" id="ftn2">
726
+ <p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
727
+ </div>')}
728
+ #{WORD_FTR1}
690
729
  OUTPUT
691
730
  end
692
731
 
@@ -698,15 +737,15 @@ RSpec.describe Html2Doc do
698
737
  Html2Doc.process(html_input(simple_body), filename: "test")
699
738
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
700
739
  .to match_fuzzy(<<~OUTPUT)
701
- #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
702
- #{word_body('<div>This is a very simple
703
- document<a class="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a> allegedly<a class="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
704
- '<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
705
- <p class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
706
- <div style="mso-element:footnote" id="ftn2">
707
- <p class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
708
- </div>')}
709
- #{WORD_FTR1}
740
+ #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
741
+ #{word_body('<div>This is a very simple
742
+ document<a class="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a> allegedly<a class="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
743
+ '<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
744
+ <p class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
745
+ <div style="mso-element:footnote" id="ftn2">
746
+ <p class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
747
+ </div>')}
748
+ #{WORD_FTR1}
710
749
  OUTPUT
711
750
  end
712
751
 
@@ -715,13 +754,14 @@ RSpec.describe Html2Doc do
715
754
  <div><ul id="0">
716
755
  <li><div><p><ol id="1"><li><ul id="2"><li><p><ol id="3"><li><ol id="4"><li>A</li><li><p>B</p><p>B2</p></li><li>C</li></ol></li></ol></p></li></ul></li></ol></p></div></li><div><ul id="5"><li>C</li></ul></div>
717
756
  BODY
718
- Html2Doc.process(html_input(simple_body), filename: "test", liststyles: { ul: "l1", ol: "l2" })
757
+ Html2Doc.process(html_input(simple_body),
758
+ filename: "test", liststyles: { ul: "l1", ol: "l2" })
719
759
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
720
760
  .to match_fuzzy(<<~OUTPUT)
721
761
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
722
762
  #{word_body('<div>
723
- <p style="mso-list:l1 level1 lfo1;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p><div><p style="mso-list:l1 level1 lfo2;" class="MsoListParagraphCxSpFirst">C</p></div>
724
- </div>',
763
+ <p style="mso-list:l1 level1 lfo1;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p><div><p style="mso-list:l1 level1 lfo2;" class="MsoListParagraphCxSpFirst">C</p></div>
764
+ </div>',
725
765
  '<div style="mso-element:footnote-list"/>')}
726
766
  #{WORD_FTR1}
727
767
  OUTPUT
@@ -733,13 +773,14 @@ RSpec.describe Html2Doc do
733
773
  <ol id="1"><li><div><p><ol id="2"><li><ul id="3"><li><p><ol id="4"><li><ol id="5"><li>A</li></ol></li></ol></p></li></ul></li></ol></p></div></li></ol>
734
774
  <ol id="6"><li><div><p><ol id="7"><li><ul id="8"><li><p><ol id="9"><li><ol id="10"><li>A</li></ol></li></ol></p></li></ul></li></ol></p></div></li></ol></div>
735
775
  BODY
736
- Html2Doc.process(html_input(simple_body), filename: "test", liststyles: { ul: "l1", ol: "l2" })
776
+ Html2Doc.process(html_input(simple_body),
777
+ filename: "test", liststyles: { ul: "l1", ol: "l2" })
737
778
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
738
779
  .to match_fuzzy(<<~OUTPUT)
739
780
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
740
781
  #{word_body('<div>
741
- <p style="mso-list:l2 level1 lfo1;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpFirst">A</p></p></p></p></div></p>
742
- <p style="mso-list:l2 level1 lfo2;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo2;" class="MsoListParagraphCxSpFirst">A</p></p></p></p></div></p></div>',
782
+ <p style="mso-list:l2 level1 lfo1;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpFirst">A</p></p></p></p></div></p>
783
+ <p style="mso-list:l2 level1 lfo2;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo2;" class="MsoListParagraphCxSpFirst">A</p></p></p></p></div></p></div>',
743
784
  '<div style="mso-element:footnote-list"/>')}
744
785
  #{WORD_FTR1}
745
786
  OUTPUT
@@ -754,16 +795,18 @@ RSpec.describe Html2Doc do
754
795
  <div><ul class="other" id="10">
755
796
  <li><div><p><ol id="11"><li><ul id="12"><li><p><ol id="13"><li><ol id="14"><li>A</li><li><p>B</p><p>B2</p></li><li>C</li></ol></li></ol></p></li></ul></li></ol></p></div></li></ul></div>
756
797
  BODY
757
- Html2Doc.process(html_input(simple_body), filename: "test", liststyles: { ul: "l1", ol: "l2", steps: "l3" })
798
+ Html2Doc.process(html_input(simple_body),
799
+ filename: "test",
800
+ liststyles: { ul: "l1", ol: "l2", steps: "l3" })
758
801
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
759
802
  .to match_fuzzy(<<~OUTPUT)
760
803
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
761
804
  #{word_body('<div>
762
- <p style="mso-list:l3 level1 lfo2;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l3 level2 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l3 level4 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l3 level5 lfo2;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l3 level5 lfo2;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l3 level5 lfo2;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p></div>
763
- <div>
764
- <p style="mso-list:l1 level1 lfo1;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p></div>
765
- <div>
766
- <p style="mso-list:l1 level1 lfo3;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo3;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo3;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo3;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l2 level5 lfo3;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l2 level5 lfo3;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p></div>',
805
+ <p style="mso-list:l3 level1 lfo2;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l3 level2 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l3 level4 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l3 level5 lfo2;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l3 level5 lfo2;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l3 level5 lfo2;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p></div>
806
+ <div>
807
+ <p style="mso-list:l1 level1 lfo1;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p></div>
808
+ <div>
809
+ <p style="mso-list:l1 level1 lfo3;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo3;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo3;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo3;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l2 level5 lfo3;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l2 level5 lfo3;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p></div>',
767
810
  '<div style="mso-element:footnote-list"/>')}
768
811
  #{WORD_FTR1}
769
812
  OUTPUT
@@ -776,14 +819,15 @@ RSpec.describe Html2Doc do
776
819
  <p id="b"/>
777
820
  </div>
778
821
  BODY
779
- Html2Doc.process(html_input(simple_body), filename: "test", liststyles: { ul: "l1", ol: "l2" })
822
+ Html2Doc.process(html_input(simple_body),
823
+ filename: "test", liststyles: { ul: "l1", ol: "l2" })
780
824
  expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
781
825
  .to match_fuzzy(<<~OUTPUT)
782
826
  #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
783
827
  #{word_body('<div>
784
- <p class="MsoNormal"><a name="a" id="a"></a>Hello</p>
785
- <p class="MsoNormal"><a name="b" id="b"></a></p>
786
- </div>',
828
+ <p class="MsoNormal"><a name="a" id="a"></a>Hello</p>
829
+ <p class="MsoNormal"><a name="b" id="b"></a></p>
830
+ </div>',
787
831
  '<div style="mso-element:footnote-list"/>')}
788
832
  #{WORD_FTR1}
789
833
  OUTPUT
@@ -791,12 +835,14 @@ RSpec.describe Html2Doc do
791
835
 
792
836
  it "test image base64 image encoding" do
793
837
  simple_body = '<img src="19160-6.png">'
794
- Html2Doc.process(html_input(simple_body), filename: "spec/test", debug: true)
838
+ Html2Doc.process(html_input(simple_body),
839
+ filename: "spec/test", debug: true, imagedir: "spec")
795
840
  testdoc = File.read("spec/test.doc", encoding: "utf-8")
796
841
  base64_image = testdoc[/image\/png\n\n(.*?)\n\n----/m, 1].gsub!("\n", "")
797
842
  base64_image_basename = testdoc[%r{Content-ID: <([0-9a-z\-]+)\.png}m, 1]
798
843
  doc_bin_image = Base64.strict_decode64(base64_image)
799
- file_bin_image = IO.read("spec/test_files/#{base64_image_basename}.png", mode: "rb")
844
+ file_bin_image = IO
845
+ .read("spec/test_files/#{base64_image_basename}.png", mode: "rb")
800
846
  expect(doc_bin_image).to eq file_bin_image
801
847
  FileUtils.rm_rf %w[spec/test_files spec/test.doc spec/test.htm]
802
848
  end