isodoc 1.7.1 → 1.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +2 -1
  3. data/lib/isodoc/convert.rb +1 -0
  4. data/lib/isodoc/css.rb +3 -3
  5. data/lib/isodoc/function/blocks.rb +180 -168
  6. data/lib/isodoc/function/blocks_example_note.rb +85 -79
  7. data/lib/isodoc/function/cleanup.rb +181 -175
  8. data/lib/isodoc/function/inline.rb +110 -108
  9. data/lib/isodoc/function/inline_simple.rb +55 -55
  10. data/lib/isodoc/function/lists.rb +75 -71
  11. data/lib/isodoc/function/references.rb +165 -160
  12. data/lib/isodoc/function/reqt.rb +91 -85
  13. data/lib/isodoc/function/section.rb +140 -190
  14. data/lib/isodoc/function/section_titles.rb +82 -0
  15. data/lib/isodoc/function/table.rb +90 -87
  16. data/lib/isodoc/function/terms.rb +58 -56
  17. data/lib/isodoc/function/to_word_html.rb +208 -204
  18. data/lib/isodoc/html_convert.rb +0 -4
  19. data/lib/isodoc/html_function/mathvariant_to_plain.rb +5 -3
  20. data/lib/isodoc/presentation_function/inline.rb +1 -1
  21. data/lib/isodoc/presentation_function/math.rb +9 -0
  22. data/lib/isodoc/presentation_function/section.rb +12 -1
  23. data/lib/isodoc/presentation_xml_convert.rb +2 -0
  24. data/lib/isodoc/version.rb +1 -1
  25. data/lib/isodoc/word_function/body.rb +5 -5
  26. data/lib/isodoc/xslfo_convert.rb +2 -2
  27. data/lib/isodoc.rb +2 -1
  28. data/lib/metanorma/output/base.rb +13 -0
  29. data/lib/metanorma/output/utils.rb +17 -0
  30. data/lib/metanorma/output/xslfo.rb +21 -0
  31. data/lib/metanorma/output.rb +7 -0
  32. data/spec/assets/outputtest/a.xml +66 -0
  33. data/spec/assets/outputtest/iso.international-standard.xsl +3011 -0
  34. data/spec/isodoc/blocks_spec.rb +441 -243
  35. data/spec/isodoc/inline_spec.rb +197 -114
  36. data/spec/isodoc/postproc_spec.rb +2 -2
  37. data/spec/isodoc/presentation_xml_spec.rb +84 -0
  38. data/spec/isodoc/section_spec.rb +639 -0
  39. metadata +23 -18
  40. data/lib/isodoc/html_function/sectionsplit.rb +0 -244
  41. data/spec/isodoc/sectionsplit_spec.rb +0 -190
@@ -419,30 +419,12 @@ RSpec.describe IsoDoc do
419
419
  <p>
420
420
  <ul>
421
421
  <li>
422
- <concept ital="true"><refterm>term</refterm>
423
- <renderterm>term</renderterm>
424
- <xref target='clause1'/>
425
- </concept></li>
426
- <li><concept ref="true"><refterm>term</refterm>
427
- <renderterm>term</renderterm>
428
- <xref target='clause1'/>
429
- </concept></li>
430
- <li><concept ital="true" ref="true"><refterm>term</refterm>
431
- <renderterm>term</renderterm>
432
- <xref target='clause1'/>
433
- </concept></li>
434
- <li><concept ital="false"><refterm>term</refterm>
435
- <renderterm>term</renderterm>
436
- <xref target='clause1'/>
437
- </concept></li>
438
- <li><concept ref="false"><refterm>term</refterm>
439
- <renderterm>term</renderterm>
440
- <xref target='clause1'/>
441
- </concept></li>
442
- <li><concept ital="false" ref="false"><refterm>term</refterm>
443
- <renderterm>term</renderterm>
444
- <xref target='clause1'/>
445
- </concept></li>
422
+ <concept ital="true"><refterm>term</refterm><renderterm>term</renderterm><xref target='clause1'/></concept>,</li>
423
+ <li><concept ref="true"><refterm>term</refterm><renderterm>term</renderterm><xref target='clause1'/></concept>,</li>
424
+ <li><concept ital="true" ref="true"><refterm>term</refterm><renderterm>term</renderterm><xref target='clause1'/></concept>,</li>
425
+ <li><concept ital="false"><refterm>term</refterm><renderterm>term</renderterm><xref target='clause1'/></concept>,</li>
426
+ <li><concept ref="false"><refterm>term</refterm><renderterm>term</renderterm><xref target='clause1'/></concept>,</li>
427
+ <li><concept ital="false" ref="false"><refterm>term</refterm><renderterm>term</renderterm><xref target='clause1'/></concept>,</li>
446
428
  </ul></p>
447
429
  </foreword></preface>
448
430
  <sections>
@@ -451,88 +433,88 @@ RSpec.describe IsoDoc do
451
433
  </iso-standard>
452
434
  INPUT
453
435
  presxml = <<~OUTPUT
454
- <iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
455
- <preface><foreword displayorder="1">
456
- <p>
457
- <ul>
458
- <li>
436
+ <iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
437
+ <preface><foreword displayorder="1">
438
+ <p>
439
+ <ul>
440
+ <li>
459
441
 
460
- <em>term</em>
461
- [term defined in <xref target="clause1">Clause 1</xref>]
462
- </li>
463
- <li>
464
- <em>term</em>
465
- [term defined in <xref target="clause1">Clause 1</xref>]
466
- </li>
442
+ <em>term</em>
443
+ [term defined in <xref target="clause1">Clause 1</xref>],
444
+ </li>
445
+ <li>
446
+ <em>term</em>
447
+ [term defined in <xref target="clause1">Clause 1</xref>],
448
+ </li>
449
+ <li>
450
+ <em>term</em>
451
+ [term defined in <xref target="clause1">Clause 1</xref>],
452
+ </li>
467
453
  <li>
468
- <em>term</em>
469
- [term defined in <xref target="clause1">Clause 1</xref>]
470
- </li>
454
+ term
455
+ [term defined in <xref target="clause1">Clause 1</xref>],
456
+ </li>
471
457
  <li>
472
- term
473
- [term defined in <xref target="clause1">Clause 1</xref>]
474
- </li>
475
- <li>
476
- <em>term</em>
458
+ <em>term</em>,
477
459
 
478
- </li>
479
- <li>
480
- term
460
+ </li>
461
+ <li>
462
+ term,
481
463
 
482
- </li>
483
- </ul></p>
484
- </foreword></preface>
485
- <sections>
486
- <clause id="clause1" displayorder="2"><title depth="1">1.<tab/>Clause 1</title></clause>
487
- </sections>
488
- </iso-standard>
464
+ </li>
465
+ </ul></p>
466
+ </foreword></preface>
467
+ <sections>
468
+ <clause id="clause1" displayorder="2"><title depth="1">1.<tab/>Clause 1</title></clause>
469
+ </sections>
470
+ </iso-standard>
489
471
  OUTPUT
490
472
  output = <<~OUTPUT
491
- #{HTML_HDR}
492
- <br/>
493
- <div>
494
- <h1 class='ForewordTitle'>Foreword</h1>
495
- <p>
496
- <ul>
497
- <li>
498
- <i>term</i>
499
- [term defined in
500
- <a href='#clause1'>Clause 1</a>
501
- ]
502
- </li>
503
- <li>
504
- <i>term</i>
505
- [term defined in
506
- <a href='#clause1'>Clause 1</a>
507
- ]
508
- </li>
509
- <li>
510
- <i>term</i>
511
- [term defined in
512
- <a href='#clause1'>Clause 1</a>
513
- ]
514
- </li>
515
- <li>
516
- term [term defined in
517
- <a href='#clause1'>Clause 1</a>
518
- ]
519
- </li>
520
- <li>
521
- <i>term</i>
522
- </li>
523
- <li> term </li>
524
- </ul>
525
- </p>
526
- </div>
527
- <p class='zzSTDTitle1'/>
528
- <div id='clause1'>
529
- <h1>1.&#160; Clause 1</h1>
530
- </div>
531
- </div>
532
- </body>
533
- </html>
473
+ #{HTML_HDR}
474
+ <br/>
475
+ <div>
476
+ <h1 class='ForewordTitle'>Foreword</h1>
477
+ <p>
478
+ <ul>
479
+ <li>
480
+ <i>term</i>
481
+ [term defined in
482
+ <a href='#clause1'>Clause 1</a>
483
+ ],
484
+ </li>
485
+ <li>
486
+ <i>term</i>
487
+ [term defined in
488
+ <a href='#clause1'>Clause 1</a>
489
+ ],
490
+ </li>
491
+ <li>
492
+ <i>term</i>
493
+ [term defined in
494
+ <a href='#clause1'>Clause 1</a>
495
+ ],
496
+ </li>
497
+ <li>
498
+ term [term defined in
499
+ <a href='#clause1'>Clause 1</a>
500
+ ],
501
+ </li>
502
+ <li>
503
+ <i>term</i>,
504
+ </li>
505
+ <li>term,</li>
506
+ </ul>
507
+ </p>
508
+ </div>
509
+ <p class='zzSTDTitle1'/>
510
+ <div id='clause1'>
511
+ <h1>1.&#160; Clause 1</h1>
512
+ </div>
513
+ </div>
514
+ </body>
515
+ </html>
534
516
  OUTPUT
535
- expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
517
+ expect((IsoDoc::PresentationXMLConvert.new({})
536
518
  .convert("test", input, true))).to be_equivalent_to xmlpp(presxml)
537
519
  expect(xmlpp(IsoDoc::HtmlConvert.new({})
538
520
  .convert("test", presxml, true))).to be_equivalent_to xmlpp(output)
@@ -855,6 +837,102 @@ RSpec.describe IsoDoc do
855
837
  .convert("test", input, true))).to be_equivalent_to xmlpp(output)
856
838
  end
857
839
 
840
+ it "duplicates MathML with AsciiMath" do
841
+ input = <<~INPUT
842
+ <iso-standard xmlns="http://riboseinc.com/isoxml" xmlns:m='http://www.w3.org/1998/Math/MathML'>
843
+ <preface><foreword>
844
+ <p>
845
+ <stem type="MathML"><m:math>
846
+ <m:msup> <m:mrow> <m:mo>(</m:mo> <m:mrow> <m:mi>x</m:mi> <m:mo>+</m:mo> <m:mi>y</m:mi> </m:mrow> <m:mo>)</m:mo> </m:mrow> <m:mn>2</m:mn> </m:msup>
847
+ </m:math></stem>
848
+ </p>
849
+ </foreword></preface>
850
+ <sections>
851
+ </iso-standard>
852
+ INPUT
853
+ output = <<~OUTPUT
854
+ <iso-standard xmlns='http://riboseinc.com/isoxml' xmlns:m='http://www.w3.org/1998/Math/MathML' type='presentation'>
855
+ <preface>
856
+ <foreword displayorder='1'>
857
+ <p>
858
+ <stem type='MathML'>
859
+ <m:math>
860
+ <m:msup>
861
+ <m:mrow>
862
+ <m:mo>(</m:mo>
863
+ <m:mrow>
864
+ <m:mi>x</m:mi>
865
+ <m:mo>+</m:mo>
866
+ <m:mi>y</m:mi>
867
+ </m:mrow>
868
+ <m:mo>)</m:mo>
869
+ </m:mrow>
870
+ <m:mn>2</m:mn>
871
+ </m:msup>
872
+ </m:math>
873
+ <comment> ( x + y )^2 </comment>
874
+ </stem>
875
+ </p>
876
+ </foreword>
877
+ </preface>
878
+ <sections> </sections>
879
+ </iso-standard>
880
+ OUTPUT
881
+ expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
882
+ .convert("test", input, true)
883
+ .gsub("<!--", "<comment>")
884
+ .gsub("-->", "</comment>")))
885
+ .to be_equivalent_to xmlpp(output)
886
+ end
887
+
888
+ it "overrides duplication of MathML with AsciiMath" do
889
+ input = <<~INPUT
890
+ <iso-standard xmlns="http://riboseinc.com/isoxml" xmlns:m='http://www.w3.org/1998/Math/MathML'>
891
+ <preface><foreword>
892
+ <p>
893
+ <stem type="MathML"><m:math>
894
+ <m:msup> <m:mrow> <m:mo>(</m:mo> <m:mrow> <m:mi>x</m:mi> <m:mo>+</m:mo> <m:mi>y</m:mi> </m:mrow> <m:mo>)</m:mo> </m:mrow> <m:mn>2</m:mn> </m:msup>
895
+ </m:math></stem>
896
+ </p>
897
+ </foreword></preface>
898
+ <sections>
899
+ </iso-standard>
900
+ INPUT
901
+ output = <<~OUTPUT
902
+ <iso-standard xmlns='http://riboseinc.com/isoxml' xmlns:m='http://www.w3.org/1998/Math/MathML' type='presentation'>
903
+ <preface>
904
+ <foreword displayorder='1'>
905
+ <p>
906
+ <stem type='MathML'>
907
+ <m:math>
908
+ <m:msup>
909
+ <m:mrow>
910
+ <m:mo>(</m:mo>
911
+ <m:mrow>
912
+ <m:mi>x</m:mi>
913
+ <m:mo>+</m:mo>
914
+ <m:mi>y</m:mi>
915
+ </m:mrow>
916
+ <m:mo>)</m:mo>
917
+ </m:mrow>
918
+ <m:mn>2</m:mn>
919
+ </m:msup>
920
+ </m:math>
921
+ </stem>
922
+ </p>
923
+ </foreword>
924
+ </preface>
925
+ <sections> </sections>
926
+ </iso-standard>
927
+ OUTPUT
928
+ expect(xmlpp(IsoDoc::PresentationXMLConvert
929
+ .new({ suppressasciimathdup: "true" })
930
+ .convert("test", input, true)
931
+ .gsub("<!--", "<comment>")
932
+ .gsub("-->", "</comment>")))
933
+ .to be_equivalent_to xmlpp(output)
934
+ end
935
+
858
936
  it "processes eref types" do
859
937
  input = <<~INPUT
860
938
  <iso-standard xmlns="http://riboseinc.com/isoxml">
@@ -881,22 +959,27 @@ RSpec.describe IsoDoc do
881
959
  INPUT
882
960
  output = <<~OUTPUT
883
961
  #{HTML_HDR}
884
- <br/>
885
- <div>
886
- <h1 class="ForewordTitle">Foreword</h1>
887
- <p>
888
- <sup><a href="#ISO712">A</a></sup>
889
- <a href="#ISO712">A</a>
890
- </p>
891
- </div>
892
- <p class="zzSTDTitle1"/>
893
- <div>
894
- <h1>Normative References</h1>
895
- <p id="ISO712" class="NormRef">ISO 712, <i>Cereals and cereal products</i></p>
896
- </div>
897
- </div>
898
- </body>
899
- </html>
962
+ <br/>
963
+ <div>
964
+ <h1 class='ForewordTitle'>Foreword</h1>
965
+ <p>
966
+ <sup>
967
+ <a href='#ISO712'>A</a>
968
+ </sup>
969
+ <a href='#ISO712'>A</a>
970
+ </p>
971
+ </div>
972
+ <p class='zzSTDTitle1'/>
973
+ <div>
974
+ <h1>Normative References</h1>
975
+ <p id='ISO712' class='NormRef'>
976
+ ISO 712,
977
+ <i>Cereals and cereal products</i>
978
+ </p>
979
+ </div>
980
+ </div>
981
+ </body>
982
+ </html>
900
983
  OUTPUT
901
984
  expect(xmlpp(IsoDoc::HtmlConvert.new({})
902
985
  .convert("test", input, true))).to be_equivalent_to xmlpp(output)
@@ -245,7 +245,7 @@ RSpec.describe IsoDoc do
245
245
  html = File.read("test.html")
246
246
  expect(html).to match(/another empty stylesheet/)
247
247
  expect(html).to match(/p \{[^}]*?font-family: Arial/m)
248
- expect(html).to match(/code \{[^}]*?font-family: Courier/m)
248
+ expect(html).to match(/code \{[^}]*?font-family: Courier New/m)
249
249
  expect(html).to match(/h1 \{[^}]*?font-family: Arial/m)
250
250
  expect(html).to match(/p \{[^}]*?font-size: 1em;/m)
251
251
  expect(html).to match(/code \{[^}]*?font-size: 0.8em/m)
@@ -329,7 +329,7 @@ RSpec.describe IsoDoc do
329
329
  word = File.read("test.doc")
330
330
  expect(word).to match(/another empty stylesheet/)
331
331
  expect(word).to match(/p \{[^}]*?font-family: Arial/m)
332
- expect(word).to match(/code \{[^}]*?font-family: Courier/m)
332
+ expect(word).to match(/code \{[^}]*?font-family: Courier New/m)
333
333
  expect(word).to match(/h1 \{[^}]*?font-family: Arial/m)
334
334
  expect(word).to match(/p \{[^}]*?font-size: 12pt/m)
335
335
  expect(word).to match(/code \{[^}]*?font-size: 11pt/m)
@@ -678,6 +678,90 @@ RSpec.describe IsoDoc do
678
678
  .to be_equivalent_to xmlpp(output)
679
679
  end
680
680
 
681
+ it "strips variant-title" do
682
+ input = <<~INPUT
683
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
684
+ <bibdata/>
685
+ <sections>
686
+ <clause id='_' inline-header='false' obligation='normative'>
687
+ <title>Clause</title>
688
+ <p id='_'>Text</p>
689
+ <clause id='_' inline-header='false' obligation='normative'>
690
+ <title>Subclause</title>
691
+ <variant-title variant_title='true' type='sub' id='_'>&#8220;A&#8221; &#8216;B&#8217;</variant-title>
692
+ <variant-title variant_title='true' type='toc' id='_'>
693
+ Clause
694
+ <em>A</em>
695
+ <stem type='MathML'>
696
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
697
+ <mi>x</mi>
698
+ </math>
699
+ </stem>
700
+ </variant-title>
701
+ <p id='_'>Text</p>
702
+ </clause>
703
+ </clause>
704
+ </sections>
705
+ <annex id='_' inline-header='false' obligation='normative'>
706
+ <title>Clause</title>
707
+ <variant-title variant_title='true' type='toc' id='_'>
708
+ Clause
709
+ <em>A</em>
710
+ <stem type='MathML'>
711
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
712
+ <mi>x</mi>
713
+ </math>
714
+ </stem>
715
+ </variant-title>
716
+ <p id='_'>Text</p>
717
+ </annex>
718
+ </iso-standard>
719
+ INPUT
720
+ output = <<~OUTPUT
721
+ <iso-standard xmlns='http://riboseinc.com/isoxml' type='presentation'>
722
+ <bibdata/>
723
+ <sections>
724
+ <clause id='_' inline-header='false' obligation='normative' displayorder='1'>
725
+ <title depth='1'>
726
+ <strong>Annex A</strong>
727
+ <br/>
728
+ (normative).
729
+ <tab/>
730
+ Clause
731
+ </title>
732
+ <p id='_'>Text</p>
733
+ <clause id='_' inline-header='false' obligation='normative'>
734
+ <title depth='1'>
735
+ <strong>Annex A</strong>
736
+ <br/>
737
+ (normative).
738
+ <tab/>
739
+ Subclause
740
+ </title>
741
+ <variant-title variant_title='true' type='sub' id='_'>&#x201C;A&#x201D; &#x2018;B&#x2019;</variant-title>
742
+ <p id='_'>Text</p>
743
+ </clause>
744
+ </clause>
745
+ </sections>
746
+ <annex id='_' inline-header='false' obligation='normative' displayorder='2'>
747
+ <title>
748
+ <strong>Annex A</strong>
749
+ <br/>
750
+ (normative)
751
+ <br/>
752
+ <br/>
753
+ <strong>Clause</strong>
754
+ </title>
755
+ <p id='_'>Text</p>
756
+ </annex>
757
+ </iso-standard>
758
+ OUTPUT
759
+ expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
760
+ .convert("test", input, true))
761
+ .sub(%r{<localized-strings>.*</localized-strings>}m, ""))
762
+ .to be_equivalent_to xmlpp(output)
763
+ end
764
+
681
765
  private
682
766
 
683
767
  def mock_symbols