isodoc 1.7.3.1 → 1.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require "twitter_cldr"
2
2
  require "bigdecimal"
3
+ require "mathml2asciimath"
3
4
 
4
5
  module IsoDoc
5
6
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -70,7 +71,15 @@ module IsoDoc
70
71
  locale
71
72
  end
72
73
 
74
+ def asciimath_dup(node)
75
+ return if @suppressasciimathdup
76
+
77
+ a = MathML2AsciiMath.m2a(node.to_xml)
78
+ node.next = "<!-- #{a} -->"
79
+ end
80
+
73
81
  def mathml1(node, locale)
82
+ asciimath_dup(node)
74
83
  localize_maths(node, locale)
75
84
  return unless node.elements.size == 1 && node.elements.first.name == "mn"
76
85
 
@@ -78,12 +78,23 @@ module IsoDoc
78
78
  i = display_order_at(docxml, "//clause[@type = 'scope']", i)
79
79
  i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i)
80
80
  i = display_order_at(docxml, "//sections/terms | "\
81
- "//sections/clause[descendant::terms]", i)
81
+ "//sections/clause[descendant::terms]", i)
82
82
  i = display_order_at(docxml, "//sections/definitions", i)
83
83
  i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
84
84
  i = display_order_xpath(docxml, "//annex", i)
85
85
  i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
86
86
  display_order_xpath(docxml, "//indexsect", i)
87
87
  end
88
+
89
+ def clausetitle(docxml)
90
+ docxml.xpath(ns("//variant-title[@type = 'toc']")).each(&:remove)
91
+ end
92
+
93
+ def toc(docxml)
94
+ docxml.xpath(ns("//toc//xref[text()]")).each do |x|
95
+ lbl = @xrefs.get[x["target"]][:label] or next
96
+ x.children.first.previous = "#{lbl}<tab/>"
97
+ end
98
+ end
88
99
  end
89
100
  end
@@ -34,6 +34,8 @@ module IsoDoc
34
34
  term docxml
35
35
  references docxml
36
36
  index docxml
37
+ clausetitle docxml
38
+ toc docxml
37
39
  display_order docxml
38
40
  end
39
41
 
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "1.7.3.1".freeze
2
+ VERSION = "1.7.4".freeze
3
3
  end
@@ -46,9 +46,9 @@ module IsoDoc::WordFunction
46
46
  end
47
47
  end
48
48
 
49
- def insert_tab(out, n)
50
- out.span **attr_code(style: "mso-tab-count:#{n}") do |span|
51
- [1..n].each { span << "&#xA0; " }
49
+ def insert_tab(out, count)
50
+ out.span **attr_code(style: "mso-tab-count:#{count}") do |span|
51
+ [1..count].each { span << "&#xA0; " }
52
52
  end
53
53
  end
54
54
 
@@ -137,7 +137,7 @@ module IsoDoc::WordFunction
137
137
  name = node&.at(ns("./name"))&.remove
138
138
  div.p **{ class: "Note" } do |p|
139
139
  p.span **{ class: "note_label" } do |s|
140
- name and name.children.each { |n| parse(n, s) }
140
+ name&.children&.each { |n| parse(n, s) }
141
141
  end
142
142
  insert_tab(p, 1)
143
143
  node.first_element_child.children.each { |n| parse(n, p) }
@@ -149,7 +149,7 @@ module IsoDoc::WordFunction
149
149
  name = node&.at(ns("./name"))&.remove
150
150
  div.p **{ class: "Note" } do |p|
151
151
  p.span **{ class: "note_label" } do |s|
152
- name and name.children.each { |n| parse(n, s) }
152
+ name&.children&.each { |n| parse(n, s) }
153
153
  end
154
154
  insert_tab(p, 1)
155
155
  end
@@ -37,12 +37,12 @@ module IsoDoc
37
37
  input_filename,
38
38
  output_filename || "#{filename}.#{@suffix}",
39
39
  File.join(@libdir, pdf_stylesheet(docxml)),
40
- pdf_options(docxml)
40
+ pdf_options(docxml),
41
41
  )
42
42
  end
43
43
 
44
44
  def xref_parse(node, out)
45
- out.a(**{ "href": target_pdf(node) }) { |l| l << get_linkend(node) }
45
+ out.a(**{ href: target_pdf(node) }) { |l| l << get_linkend(node) }
46
46
  end
47
47
 
48
48
  def input_xml_path(input_filename, xml_file, debug)
@@ -2534,73 +2534,156 @@ RSpec.describe IsoDoc do
2534
2534
  </sections>
2535
2535
  </standard-document>
2536
2536
  INPUT
2537
+ presxml = <<~INPUT
2538
+ <standard-document xmlns="https://www.metanorma.org/ns/standoc" type="presentation" version="1.10.2">
2539
+ <bibdata type="standard">
2540
+ <title language="en" format="text/plain">Document title</title>
2541
+ <language current="true">en</language>
2542
+ <script current="true">Latn</script>
2543
+ <status>
2544
+ <stage language="">published</stage>
2545
+ </status>
2546
+ <copyright>
2547
+ <from>2021</from>
2548
+ </copyright>
2549
+ <ext>
2550
+ <doctype language="">article</doctype>
2551
+ </ext>
2552
+ </bibdata>
2553
+ <sections>
2554
+ <clause id="clause1" inline-header="false" obligation="normative" displayorder="1">
2555
+ <title depth="1">1.<tab/>Clause 1</title>
2556
+ <clause id="clause1A" inline-header="false" obligation="normative">
2557
+ <title depth="2">1.1.<tab/>Clause 1A</title>
2558
+ <clause id="clause1Aa" inline-header="false" obligation="normative">
2559
+ <title depth="3">1.1.1.<tab/>Clause 1Aa</title>
2560
+ </clause>
2561
+ <clause id="clause1Ab" inline-header="false" obligation="normative">
2562
+ <title depth="3">1.1.2.<tab/>Clause 1Ab</title>
2563
+ </clause>
2564
+ </clause>
2565
+ <clause id="clause1B" inline-header="false" obligation="normative">
2566
+ <title depth="2">1.2.<tab/>Clause 1B</title>
2567
+ <clause id="clause1Ba" inline-header="false" obligation="normative">
2568
+ <title depth="3">1.2.1.<tab/>Clause 1Ba</title>
2569
+ </clause>
2570
+ </clause>
2571
+ </clause>
2572
+ <clause id="clause2" inline-header="false" obligation="normative" displayorder="2">
2573
+ <title depth="1">2.<tab/>Clause 2</title>
2574
+ <p id="A">And introducing: </p>
2575
+ <toc>
2576
+ <ul id="B">
2577
+ <li>
2578
+ <xref target="clause1A">1.1<tab/>Clause 1A</xref>
2579
+ </li>
2580
+ <li>
2581
+ <ul id="C">
2582
+ <li>
2583
+ <xref target="clause1Aa">1.1.1<tab/>Clause 1Aa</xref>
2584
+ </li>
2585
+ <li>
2586
+ <xref target="clause1Ab">1.1.2<tab/>Clause 1Ab</xref>
2587
+ </li>
2588
+ </ul>
2589
+ </li>
2590
+ <li>
2591
+ <xref target="clause1B">1.2<tab/>Clause 1B</xref>
2592
+ </li>
2593
+ <li>
2594
+ <ul id="D">
2595
+ <li>
2596
+ <xref target="clause1Ba">1.2.1<tab/>Clause 1Ba</xref>
2597
+ </li>
2598
+ </ul>
2599
+ </li>
2600
+ </ul>
2601
+ </toc>
2602
+ <toc>
2603
+ <ul id="E">
2604
+ <li>
2605
+ <xref target="clause1A">1.1<tab/>Clause 1A</xref>
2606
+ </li>
2607
+ <li>
2608
+ <xref target="clause1B">1.2<tab/>Clause 1B</xref>
2609
+ </li>
2610
+ </ul>
2611
+ </toc>
2612
+ </clause>
2613
+ </sections>
2614
+ </standard-document>
2615
+ INPUT
2537
2616
  output = <<~OUTPUT
2538
2617
  #{HTML_HDR}
2539
- <p class='zzSTDTitle1'>Document title</p>
2540
- <div id='clause1'>
2541
- <h1>Clause 1</h1>
2542
- <div id='clause1A'>
2543
- <h2>Clause 1A</h2>
2544
- <div id='clause1Aa'>
2545
- <h3>Clause 1Aa</h3>
2546
- </div>
2547
- <div id='clause1Ab'>
2548
- <h3>Clause 1Ab</h3>
2549
- </div>
2550
- </div>
2551
- <div id='clause1B'>
2552
- <h2>Clause 1B</h2>
2553
- <div id='clause1Ba'>
2554
- <h3>Clause 1Ba</h3>
2555
- </div>
2556
- </div>
2557
- </div>
2558
- <div id='clause2'>
2559
- <h1>Clause 2</h1>
2560
- <p id='A'>And introducing: </p>
2561
- <div class='toc'>
2562
- <ul id='B'>
2563
- <li>
2564
- <a href='#clause1A'>Clause 1A</a>
2565
- </li>
2566
- <li>
2567
- <ul id='C'>
2568
- <li>
2569
- <a href='#clause1Aa'>Clause 1Aa</a>
2570
- </li>
2571
- <li>
2572
- <a href='#clause1Ab'>Clause 1Ab</a>
2573
- </li>
2574
- </ul>
2575
- </li>
2576
- <li>
2577
- <a href='#clause1B'>Clause 1B</a>
2578
- </li>
2579
- <li>
2580
- <ul id='D'>
2581
- <li>
2582
- <a href='#clause1Ba'>Clause 1Ba</a>
2583
- </li>
2584
- </ul>
2585
- </li>
2586
- </ul>
2587
- </div>
2588
- <div class='toc'>
2589
- <ul id='E'>
2590
- <li>
2591
- <a href='#clause1A'>Clause 1A</a>
2592
- </li>
2593
- <li>
2594
- <a href='#clause1B'>Clause 1B</a>
2595
- </li>
2596
- </ul>
2597
- </div>
2598
- </div>
2599
- </div>
2600
- </body>
2601
- </html>
2618
+ <p class='zzSTDTitle1'>Document title</p>
2619
+ <div id='clause1'>
2620
+ <h1>1.&#160; Clause 1</h1>
2621
+ <div id='clause1A'>
2622
+ <h2>1.1.&#160; Clause 1A</h2>
2623
+ <div id='clause1Aa'>
2624
+ <h3>1.1.1.&#160; Clause 1Aa</h3>
2625
+ </div>
2626
+ <div id='clause1Ab'>
2627
+ <h3>1.1.2.&#160; Clause 1Ab</h3>
2628
+ </div>
2629
+ </div>
2630
+ <div id='clause1B'>
2631
+ <h2>1.2.&#160; Clause 1B</h2>
2632
+ <div id='clause1Ba'>
2633
+ <h3>1.2.1.&#160; Clause 1Ba</h3>
2634
+ </div>
2635
+ </div>
2636
+ </div>
2637
+ <div id='clause2'>
2638
+ <h1>2.&#160; Clause 2</h1>
2639
+ <p id='A'>And introducing: </p>
2640
+ <div class='toc'>
2641
+ <ul id='B'>
2642
+ <li>
2643
+ <a href='#clause1A'>1.1&#160; Clause 1A</a>
2644
+ </li>
2645
+ <li>
2646
+ <ul id='C'>
2647
+ <li>
2648
+ <a href='#clause1Aa'>1.1.1&#160; Clause 1Aa</a>
2649
+ </li>
2650
+ <li>
2651
+ <a href='#clause1Ab'>1.1.2&#160; Clause 1Ab</a>
2652
+ </li>
2653
+ </ul>
2654
+ </li>
2655
+ <li>
2656
+ <a href='#clause1B'>1.2&#160; Clause 1B</a>
2657
+ </li>
2658
+ <li>
2659
+ <ul id='D'>
2660
+ <li>
2661
+ <a href='#clause1Ba'>1.2.1&#160; Clause 1Ba</a>
2662
+ </li>
2663
+ </ul>
2664
+ </li>
2665
+ </ul>
2666
+ </div>
2667
+ <div class='toc'>
2668
+ <ul id='E'>
2669
+ <li>
2670
+ <a href='#clause1A'>1.1&#160; Clause 1A</a>
2671
+ </li>
2672
+ <li>
2673
+ <a href='#clause1B'>1.2&#160; Clause 1B</a>
2674
+ </li>
2675
+ </ul>
2676
+ </div>
2677
+ </div>
2678
+ </div>
2679
+ </body>
2680
+ </html>
2602
2681
  OUTPUT
2682
+ expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
2683
+ .convert("test", input, true)
2684
+ .sub(%r{<localized-strings>.*</localized-strings>}m, "")))
2685
+ .to be_equivalent_to xmlpp(presxml)
2603
2686
  expect(xmlpp(IsoDoc::HtmlConvert.new({})
2604
- .convert("test", input, true))).to be_equivalent_to xmlpp(output)
2687
+ .convert("test", presxml, true))).to be_equivalent_to xmlpp(output)
2605
2688
  end
2606
2689
  end
@@ -433,86 +433,86 @@ RSpec.describe IsoDoc do
433
433
  </iso-standard>
434
434
  INPUT
435
435
  presxml = <<~OUTPUT
436
- <iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
437
- <preface><foreword displayorder="1">
438
- <p>
439
- <ul>
440
- <li>
436
+ <iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
437
+ <preface><foreword displayorder="1">
438
+ <p>
439
+ <ul>
440
+ <li>
441
441
 
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>
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>
449
453
  <li>
450
- <em>term</em>
451
- [term defined in <xref target="clause1">Clause 1</xref>],
452
- </li>
454
+ term
455
+ [term defined in <xref target="clause1">Clause 1</xref>],
456
+ </li>
453
457
  <li>
454
- term
455
- [term defined in <xref target="clause1">Clause 1</xref>],
456
- </li>
457
- <li>
458
- <em>term</em>,
458
+ <em>term</em>,
459
459
 
460
- </li>
461
- <li>
462
- term,
460
+ </li>
461
+ <li>
462
+ term,
463
463
 
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>
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>
471
471
  OUTPUT
472
472
  output = <<~OUTPUT
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>
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>
516
516
  OUTPUT
517
517
  expect((IsoDoc::PresentationXMLConvert.new({})
518
518
  .convert("test", input, true))).to be_equivalent_to xmlpp(presxml)
@@ -837,6 +837,102 @@ RSpec.describe IsoDoc do
837
837
  .convert("test", input, true))).to be_equivalent_to xmlpp(output)
838
838
  end
839
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
+
840
936
  it "processes eref types" do
841
937
  input = <<~INPUT
842
938
  <iso-standard xmlns="http://riboseinc.com/isoxml">
@@ -863,22 +959,27 @@ RSpec.describe IsoDoc do
863
959
  INPUT
864
960
  output = <<~OUTPUT
865
961
  #{HTML_HDR}
866
- <br/>
867
- <div>
868
- <h1 class="ForewordTitle">Foreword</h1>
869
- <p>
870
- <sup><a href="#ISO712">A</a></sup>
871
- <a href="#ISO712">A</a>
872
- </p>
873
- </div>
874
- <p class="zzSTDTitle1"/>
875
- <div>
876
- <h1>Normative References</h1>
877
- <p id="ISO712" class="NormRef">ISO 712, <i>Cereals and cereal products</i></p>
878
- </div>
879
- </div>
880
- </body>
881
- </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>
882
983
  OUTPUT
883
984
  expect(xmlpp(IsoDoc::HtmlConvert.new({})
884
985
  .convert("test", input, true))).to be_equivalent_to xmlpp(output)