isodoc 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +1 -1
  3. data/.rubocop.yml +6 -2
  4. data/Gemfile +2 -2
  5. data/isodoc.gemspec +11 -11
  6. data/lib/isodoc/base_style/all.css +7 -0
  7. data/lib/isodoc/base_style/metanorma_word.css +7 -0
  8. data/lib/isodoc/base_style/metanorma_word.scss +8 -0
  9. data/lib/isodoc/base_style/reset.css +7 -0
  10. data/lib/isodoc/base_style/reset.scss +9 -0
  11. data/lib/isodoc/base_style/scripts.html +187 -0
  12. data/lib/isodoc/class_utils.rb +6 -5
  13. data/lib/isodoc/convert.rb +28 -15
  14. data/lib/isodoc/css.rb +14 -4
  15. data/lib/isodoc/function/blocks.rb +4 -0
  16. data/lib/isodoc/function/inline.rb +31 -10
  17. data/lib/isodoc/function/references.rb +1 -1
  18. data/lib/isodoc/function/to_word_html.rb +19 -8
  19. data/lib/isodoc/function/utils.rb +1 -0
  20. data/lib/isodoc/html_function/postprocess.rb +8 -5
  21. data/lib/isodoc/pdf_convert.rb +1 -3
  22. data/lib/isodoc/presentation_function/block.rb +11 -5
  23. data/lib/isodoc/presentation_function/inline.rb +42 -38
  24. data/lib/isodoc/presentation_function/section.rb +1 -1
  25. data/lib/isodoc/presentation_xml_convert.rb +1 -1
  26. data/lib/isodoc/version.rb +1 -1
  27. data/lib/isodoc/word_function/inline.rb +6 -0
  28. data/lib/isodoc/word_function/postprocess.rb +16 -6
  29. data/lib/isodoc/xref.rb +1 -1
  30. data/lib/isodoc/xref/xref_gen.rb +16 -15
  31. data/lib/isodoc/xslfo_convert.rb +36 -25
  32. data/spec/assets/html_override.css +1 -0
  33. data/spec/assets/word_override.css +1 -0
  34. data/spec/isodoc/blocks_spec.rb +87 -0
  35. data/spec/isodoc/footnotes_spec.rb +1 -16
  36. data/spec/isodoc/inline_spec.rb +38 -1
  37. data/spec/isodoc/postproc_spec.rb +42 -14
  38. data/spec/isodoc/presentation_xml_spec.rb +345 -338
  39. data/spec/isodoc/section_spec.rb +910 -902
  40. data/spec/isodoc/table_spec.rb +566 -556
  41. data/spec/isodoc/terms_spec.rb +252 -256
  42. data/spec/isodoc/xref_spec.rb +2990 -2987
  43. data/spec/isodoc/xslfo_convert_spec.rb +39 -0
  44. data/spec/spec_helper.rb +30 -29
  45. metadata +71 -69
  46. data/.rubocop.ribose.yml +0 -65
  47. data/.rubocop.tb.yml +0 -650
@@ -47,7 +47,7 @@ module IsoDoc
47
47
  end
48
48
 
49
49
  def index(docxml)
50
- docxml.xpath(ns("//index | //index-xref")).each do |f|
50
+ docxml.xpath(ns("//index | //index-xref | //indexsect")).each do |f|
51
51
  f.remove
52
52
  end
53
53
  end
@@ -59,7 +59,7 @@ module IsoDoc
59
59
  variant docxml
60
60
  end
61
61
 
62
- def postprocess(result, filename, dir)
62
+ def postprocess(result, filename, _dir)
63
63
  toXML(result, filename)
64
64
  @files_to_delete.each { |f| FileUtils.rm_rf f }
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "1.5.1".freeze
2
+ VERSION = "1.6.0".freeze
3
3
  end
@@ -22,6 +22,12 @@ module IsoDoc::WordFunction
22
22
  end
23
23
  end
24
24
 
25
+ def svg_parse(node, out)
26
+ svg = Base64.strict_encode64(node.to_xml)
27
+ r = node.replace("<img src='data:image/svg+xml;base64,#{svg}' mimetype='image/svg+xml'/>").first
28
+ image_parse(r, out, nil)
29
+ end
30
+
25
31
  def imgsrc(node)
26
32
  ret = svg_to_emf(node) and return ret
27
33
  return node["src"] unless %r{^data:}.match node["src"]
@@ -37,17 +37,27 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
37
37
 
38
38
  def toWord(result, filename, dir, header)
39
39
  result = from_xhtml(word_cleanup(to_xhtml(result)))
40
- unless @landscapestyle.empty?
41
- @wordstylesheet&.open
42
- @wordstylesheet&.write(@landscapestyle)
43
- @wordstylesheet&.close
44
- end
40
+ @wordstylesheet = wordstylesheet_update
45
41
  Html2Doc.process(result, filename: filename, stylesheet: @wordstylesheet&.path,
46
42
  header_file: header&.path, dir: dir,
47
43
  asciimathdelims: [@openmathdelim, @closemathdelim],
48
44
  liststyles: { ul: @ulstyle, ol: @olstyle })
49
45
  header&.unlink
50
- @wordstylesheet&.unlink
46
+ @wordstylesheet&.unlink if @wordstylesheet&.is_a?(Tempfile)
47
+ end
48
+
49
+ def wordstylesheet_update()
50
+ return if @wordstylesheet.nil?
51
+ f = File.open(@wordstylesheet.path, "a")
52
+ @landscapestyle.empty? or f.write(@landscapestyle)
53
+ if @wordstylesheet_override && @wordstylesheet
54
+ f.write(@wordstylesheet_override.read)
55
+ @wordstylesheet_override.close
56
+ elsif @wordstylesheet_override && !@wordstylesheet
57
+ @wordstylesheet = @wordstylesheet_override
58
+ end
59
+ f.close
60
+ @wordstylesheet
51
61
  end
52
62
 
53
63
  def word_admonition_images(docxml)
data/lib/isodoc/xref.rb CHANGED
@@ -49,7 +49,7 @@ module IsoDoc
49
49
  note_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
50
50
  example_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
51
51
  list_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
52
- bookmark_anchor_names(docxml.xpath(ns(SECTIONS_XPATH)))
52
+ bookmark_anchor_names(docxml)
53
53
  end
54
54
 
55
55
  def ns(xpath)
@@ -94,16 +94,17 @@ module IsoDoc::XrefGen
94
94
  "not(self::xmlns:terms) and not(self::xmlns:definitions)]//"\
95
95
  "xmlns:example | ./xmlns:example".freeze
96
96
 
97
- CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | ./references"
97
+ CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | "\
98
+ "./references"
98
99
 
99
100
  def example_anchor_names(sections)
100
101
  sections.each do |s|
101
102
  notes = s.xpath(CHILD_EXAMPLES_XPATH)
102
103
  c = Counter.new
103
104
  notes.each do |n|
104
- next if @anchors[n["id"]]
105
- next if n["id"].nil? || n["id"].empty?
106
- idx = notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}"
105
+ next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
106
+ idx = notes.size == 1 && !n["number"] ? "" :
107
+ " #{c.increment(n).print}"
107
108
  @anchors[n["id"]] = anchor_struct(idx, n, @labels["example_xref"],
108
109
  "example", n["unnumbered"])
109
110
  end
@@ -119,7 +120,8 @@ module IsoDoc::XrefGen
119
120
  notes.each do |n|
120
121
  next if n["id"].nil? || n["id"].empty?
121
122
  idx = notes.size == 1 && !n["number"] ? "" : " #{c.increment(n).print}"
122
- @anchors[n["id"]] = anchor_struct(idx, n, @labels["list"], "list", false)
123
+ @anchors[n["id"]] = anchor_struct(idx, n, @labels["list"], "list",
124
+ false)
123
125
  list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
124
126
  end
125
127
  list_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
@@ -141,17 +143,16 @@ module IsoDoc::XrefGen
141
143
  end
142
144
  end
143
145
 
144
- def bookmark_anchor_names(sections)
145
- sections.each do |s|
146
- notes = s.xpath(ns(".//bookmark")) - s.xpath(ns(".//clause//bookmark")) -
147
- s.xpath(ns(".//appendix//bookmark"))
148
- notes.each do |n|
149
- next if n["id"].nil? || n["id"].empty?
150
- @anchors[n["id"]] = {
151
- type: "bookmark", label: nil, value: nil,
152
- xref: @anchors[s["id"]][:xref] }
146
+ def bookmark_anchor_names(docxml)
147
+ docxml.xpath(ns(".//bookmark")).each do |n|
148
+ next if n["id"].nil? || n["id"].empty?
149
+ parent = nil
150
+ n.ancestors.each do |a|
151
+ next unless a["id"] && parent = @anchors.dig(a["id"], :xref)
152
+ break
153
153
  end
154
- bookmark_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
154
+ @anchors[n["id"]] = { type: "bookmark", label: nil, value: nil,
155
+ xref: parent || "???" }
155
156
  end
156
157
  end
157
158
  end
@@ -2,50 +2,61 @@ require "metanorma"
2
2
 
3
3
  module IsoDoc
4
4
  class XslfoPdfConvert < ::IsoDoc::Convert
5
+ MN2PDF_OPTIONS = :mn2pdf
6
+ MN2PDF_FONT_MANIFEST = :font_manifest_file
5
7
 
6
8
  def initialize(options)
9
+ @format = :pdf
10
+ @suffix = "pdf"
7
11
  super
8
- @maxwidth = 500
9
- @maxheight = 800
10
12
  end
11
13
 
12
14
  def tmpimagedir_suffix
13
15
  "_pdfimages"
14
16
  end
15
17
 
16
- def initialize(options)
17
- @format = :pdf
18
- @suffix = "pdf"
19
- super
20
- end
21
-
22
- def pdf_stylesheet(docxml)
18
+ def pdf_stylesheet(_docxml)
23
19
  nil
24
20
  end
25
21
 
26
- def pdf_options(docxml)
27
- ""
22
+ def pdf_options(_docxml)
23
+ if font_manifest_file = @options.dig(MN2PDF_OPTIONS,
24
+ MN2PDF_FONT_MANIFEST)
25
+ "--font-manifest #{font_manifest_file}"
26
+ else
27
+ ""
28
+ end
28
29
  end
29
30
 
30
- def convert(input_filename, file = nil, debug = false, output_filename = nil)
31
+ def convert(input_filename, file = nil, debug = false,
32
+ output_filename = nil)
31
33
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
32
- docxml, filename, dir = convert_init(file, input_filename, debug)
33
- /\.xml$/.match(input_filename) or
34
- input_filename = Tempfile.open([filename, ".xml"], encoding: "utf-8") do |f|
35
- f.write file
34
+ input_filename, docxml, filename = input_xml_path(input_filename,
35
+ file, debug)
36
+ ::Metanorma::Output::XslfoPdf.new.convert(
37
+ input_filename,
38
+ output_filename || "#{filename}.#{@suffix}",
39
+ File.join(@libdir, pdf_stylesheet(docxml)),
40
+ pdf_options(docxml)
41
+ )
42
+ end
43
+
44
+ def xref_parse(node, out)
45
+ out.a(**{ "href": target_pdf(node) }) { |l| l << get_linkend(node) }
46
+ end
47
+
48
+ def input_xml_path(input_filename, xml_file, debug)
49
+ docxml, filename, dir = convert_init(xml_file, input_filename, debug)
50
+ unless /\.xml$/.match?(input_filename)
51
+ input_filename = Tempfile.open([filename, ".xml"],
52
+ encoding: "utf-8") do |f|
53
+ f.write xml_file
36
54
  f.path
37
55
  end
56
+ end
38
57
  FileUtils.rm_rf dir
39
- ::Metanorma::Output::XslfoPdf.new.convert(input_filename,
40
- output_filename || "#{filename}.#{@suffix}",
41
- File.join(@libdir, pdf_stylesheet(docxml)),
42
- pdf_options(docxml))
43
- end
44
58
 
45
- def xref_parse(node, out)
46
- target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".pdf#") :
47
- "##{node["target"]}"
48
- out.a(**{ "href": target }) { |l| l << get_linkend(node) }
59
+ [input_filename, docxml, filename]
49
60
  end
50
61
  end
51
62
  end
@@ -0,0 +1 @@
1
+ /* html-override */
@@ -0,0 +1 @@
1
+ /* word-override */
@@ -768,6 +768,93 @@ B</pre>
768
768
  expect(xmlpp(strip_guid(IsoDoc::WordConvert.new({}).convert("test", presxml, true).gsub(/['"][^'".]+\.(gif|xml)['"]/, "'_.\\1'").gsub(/mso-bookmark:_Ref\d+/, "mso-bookmark:_Ref")))).to be_equivalent_to xmlpp(word)
769
769
  end
770
770
 
771
+ it "processes SVG" do
772
+ input = <<~INPUT
773
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
774
+ <preface><foreword>
775
+ <figure id="figureA-1">
776
+ <image src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICA8Y2lyY2xlIGZpbGw9IiMwMDkiIHI9IjQ1IiBjeD0iNTAiIGN5PSI1MCIvPgogIDxwYXRoIGQ9Ik0zMywyNkg3OEEzNywzNywwLDAsMSwzMyw4M1Y1N0g1OVY0M0gzM1oiIGZpbGw9IiNGRkYiLz4KPC9zdmc+Cg==" id="_d3731866-1a07-435a-a6c2-1acd41023a4e" mimetype="image/svg+xml" height="auto" width="auto"/>
777
+ </figure>
778
+ </foreword></preface>
779
+ </iso-standard>
780
+ INPUT
781
+
782
+ presxml = <<~OUTPUT
783
+ <iso-standard xmlns='http://riboseinc.com/isoxml' type='presentation'>
784
+ <preface>
785
+ <foreword>
786
+ <figure id='figureA-1'>
787
+ <name>Figure 1</name>
788
+ <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'>
789
+ <circle fill='#009' r='45' cx='50' cy='50'/>
790
+ <path d='M33,26H78A37,37,0,0,1,33,83V57H59V43H33Z' fill='#FFF'/>
791
+ </svg>
792
+ </figure>
793
+ </foreword>
794
+ </preface>
795
+ </iso-standard>
796
+ OUTPUT
797
+
798
+ html = <<~HTML
799
+ #{HTML_HDR}
800
+ <br/>
801
+ <div>
802
+ <h1 class='ForewordTitle'>Foreword</h1>
803
+ <div id='figureA-1' class='figure'>
804
+ <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'>
805
+ <circle fill='#009' r='45' cx='50' cy='50'/>
806
+ <path d='M33,26H78A37,37,0,0,1,33,83V57H59V43H33Z' fill='#FFF'/>
807
+ </svg>
808
+ <p class='FigureTitle' style='text-align:center;'>Figure 1</p>
809
+ </div>
810
+ </div>
811
+ <p class='zzSTDTitle1'/>
812
+ </div>
813
+ </body>
814
+ </html>
815
+ HTML
816
+
817
+ doc = <<~DOC
818
+ <html xmlns:epub='http://www.idpf.org/2007/ops' lang='en'>
819
+ <head>
820
+ <style>
821
+ </style>
822
+ </head>
823
+ <body lang='EN-US' link='blue' vlink='#954F72'>
824
+ <div class='WordSection1'>
825
+ <p>&#160;</p>
826
+ </div>
827
+ <p>
828
+ <br clear='all' class='section'/>
829
+ </p>
830
+ <div class='WordSection2'>
831
+ <p>
832
+ <br clear='all' style='mso-special-character:line-break;page-break-before:always'/>
833
+ </p>
834
+ <div>
835
+ <h1 class='ForewordTitle'>Foreword</h1>
836
+ <div id='figureA-1' class='figure'>
837
+ <img src='_.emf'/>
838
+ <p class='FigureTitle' style='text-align:center;'>Figure 1</p>
839
+ </div>
840
+ </div>
841
+ <p>&#160;</p>
842
+ </div>
843
+ <p>
844
+ <br clear='all' class='section'/>
845
+ </p>
846
+ <div class='WordSection3'>
847
+ <p class='zzSTDTitle1'/>
848
+ </div>
849
+ </body>
850
+ </html>
851
+ DOC
852
+
853
+ expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}).convert("test", input, true).gsub(/\&lt;/, "&#x3c;"))).to be_equivalent_to xmlpp(presxml)
854
+ expect(xmlpp(strip_guid(IsoDoc::HtmlConvert.new({}).convert("test", presxml, true)))).to be_equivalent_to xmlpp(html)
855
+ expect(xmlpp(strip_guid(IsoDoc::WordConvert.new({}).convert("test", presxml, true).gsub(/['"][^'".]+(?<!odf1)(?<!odf)\.emf['"]/, "'_.emf'").gsub(/['"][^'".]+\.(gif|xml)['"]/, "'_.\\1'")))).to be_equivalent_to xmlpp(doc)
856
+ end
857
+
771
858
  it "converts SVG (Word)" do
772
859
  FileUtils.rm_rf "spec/assets/odf1.emf"
773
860
  expect(xmlpp(strip_guid(IsoDoc::WordConvert.new({}).convert("test", <<~"INPUT", true).gsub(/['"][^'".]+(?<!odf1)(?<!odf)\.emf['"]/, "'_.emf'").gsub(/['"][^'".]+\.(gif|xml)['"]/, "'_.\\1'").gsub(/mso-bookmark:_Ref\d+/, "mso-bookmark:_Ref")))).to be_equivalent_to xmlpp(<<~"OUTPUT")
@@ -155,17 +155,8 @@ RSpec.describe IsoDoc do
155
155
  </preface>
156
156
  </iso-standard>
157
157
  INPUT
158
- html = File.read("test.html").sub(/^.*<body/m, "<body").sub(%r{</body>.*$}m, "</body>")
158
+ html = File.read("test.html").sub(/^.*<main/m, "<main").sub(%r{</main>.*$}m, "</main>")
159
159
  expect(xmlpp(html)).to be_equivalent_to xmlpp(<<~"OUTPUT")
160
- <body lang="en" xml:lang="en">
161
- <div class="title-section">
162
- <p>&#xA0;</p>
163
- </div>
164
- <br />
165
- <div class="prefatory-section">
166
- <p>&#xA0;</p>
167
- </div>
168
- <br />
169
160
  <main class="main-section"><button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
170
161
  <br />
171
162
  <div>
@@ -180,12 +171,6 @@ RSpec.describe IsoDoc do
180
171
  </div>
181
172
  <p class="zzSTDTitle1"></p>
182
173
  </main>
183
- <script type='text/x-mathjax-config'>
184
- MathJax.Hub.Config({ "HTML-CSS": { preferredFont: "STIX" }, asciimath2jax:
185
- { delimiters: [['(#(', ')#)']] } });
186
- </script>
187
- <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=MML_HTMLorMML-full" async="async"></script>
188
- <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script></body>
189
174
  OUTPUT
190
175
  end
191
176
 
@@ -124,7 +124,10 @@ OUTPUT
124
124
  <preface><foreword>
125
125
  <p><index primary="A" secondary="B" tertiary="C"/></p>
126
126
  </foreword></preface>
127
- <sections>
127
+ <sections/>
128
+ <indexsect>
129
+ <title>Index</title>
130
+ </indexsect>
128
131
  </iso-standard>
129
132
  INPUT
130
133
  <iso-standard xmlns='http://riboseinc.com/isoxml' type='presentation'>
@@ -587,6 +590,8 @@ OUTPUT
587
590
  <eref type="inline" bibitemid="ISO712" citeas="ISO 712">A</eref>
588
591
  <eref type="inline" bibitemid="ISO712"><locality type="anchor"><referenceFrom>1</referenceFrom></locality></eref>
589
592
  <eref type="inline" bibitemid="ISO712"><locality type="anchor"><referenceFrom>1</referenceFrom></locality><locality type="clause"><referenceFrom>1</referenceFrom></locality></eref>
593
+ <eref type="inline" droploc="true" bibitemid="ISO712"><locality type="anchor"><referenceFrom>1</referenceFrom></locality><locality type="clause"><referenceFrom>1</referenceFrom></locality></eref>
594
+ <eref type="inline" case="lowercase" bibitemid="ISO712"><locality type="anchor"><referenceFrom>1</referenceFrom></locality><locality type="clause"><referenceFrom>1</referenceFrom></locality></eref>
590
595
  </p>
591
596
  </foreword></preface>
592
597
  <bibliography><references id="_normative_references" obligation="informative" normative="true"><title>Normative References</title>
@@ -623,6 +628,8 @@ OUTPUT
623
628
  <eref type="inline" bibitemid="ISO712" citeas="ISO 712">A</eref>
624
629
  <eref type="inline" bibitemid="ISO712"><locality type="anchor"><referenceFrom>1</referenceFrom></locality>ISO 712</eref>
625
630
  <eref type="inline" bibitemid="ISO712"><locality type="anchor"><referenceFrom>1</referenceFrom></locality><locality type="clause"><referenceFrom>1</referenceFrom></locality>ISO 712, Clause 1</eref>
631
+ <eref type="inline" droploc="true" bibitemid="ISO712"><locality type="anchor"><referenceFrom>1</referenceFrom></locality><locality type="clause"><referenceFrom>1</referenceFrom></locality>ISO 712, 1</eref>
632
+ <eref type="inline" case="lowercase" bibitemid="ISO712"><locality type="anchor"><referenceFrom>1</referenceFrom></locality><locality type="clause"><referenceFrom>1</referenceFrom></locality>ISO 712, clause 1</eref>
626
633
  </p>
627
634
  </foreword></preface>
628
635
  <bibliography><references id="_normative_references" obligation="informative" normative="true"><title depth='1'>1.<tab/>Normative References</title>
@@ -662,6 +669,8 @@ html = <<~OUTPUT
662
669
  <a href="#ISO712">A</a>
663
670
  <a href='#ISO712'>ISO 712</a>
664
671
  <a href='#ISO712'>ISO 712, Clause 1</a>
672
+ <a href='#ISO712'>ISO 712, 1</a>
673
+ <a href='#ISO712'>ISO 712, clause 1</a>
665
674
  </p>
666
675
  </div>
667
676
  <p class="zzSTDTitle1"/>
@@ -1014,4 +1023,32 @@ INPUT
1014
1023
  OUTPUT
1015
1024
  end
1016
1025
 
1026
+ it "processes add, del" do
1027
+ expect(xmlpp(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true))).to be_equivalent_to xmlpp(<<~"OUTPUT")
1028
+ <itu-standard xmlns="https://www.calconnect.org/standards/itu">
1029
+ <preface><foreword id="A">
1030
+ <add>ABC <xref target="A"></add> <del><strong>B</strong></del>
1031
+ </foreword></preface>
1032
+ </itu-standard>
1033
+ INPUT
1034
+ #{HTML_HDR}
1035
+ <br/>
1036
+ <div id='A'>
1037
+ <h1 class='ForewordTitle'>Foreword</h1>
1038
+ <span class='addition'>
1039
+ ABC
1040
+ <a href='#A'/>
1041
+ <span class='deletion'>
1042
+ <b>B</b>
1043
+ </span>
1044
+ </span>
1045
+ </div>
1046
+ <p class='zzSTDTitle1'/>
1047
+ </div>
1048
+ </body>
1049
+ </html>
1050
+ OUTPUT
1051
+ end
1052
+
1053
+
1017
1054
  end
@@ -27,6 +27,27 @@ RSpec.describe IsoDoc do
27
27
  expect(html).to match(/delimiters: \[\['\(#\(', '\)#\)'\]\]/)
28
28
  end
29
29
 
30
+ it "generates file in a remote directory" do
31
+ FileUtils.rm_f "spec/assets/test.doc"
32
+ FileUtils.rm_f "spec/assets/test.html"
33
+ IsoDoc::HtmlConvert.new({wordstylesheet: "word.css", htmlstylesheet: "html.scss", filename: "test"}).convert("spec/assets/test", <<~"INPUT", false)
34
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
35
+ <bibdata>
36
+ <title language="en">test</title>
37
+ </bibdata>
38
+ <preface><foreword>
39
+ <note>
40
+ <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p>
41
+ </note>
42
+ </foreword></preface>
43
+ </iso-standard>
44
+ INPUT
45
+ expect(File.exist?("spec/assets/test.html")).to be true
46
+ html = File.read("spec/assets/test.html")
47
+ expect(html).to match(%r{<title>test</title>})
48
+ expect(html).to match(/another empty stylesheet/)
49
+ end
50
+
30
51
  it "ignores Liquid markup in the document body" do
31
52
  FileUtils.rm_f "test.doc"
32
53
  FileUtils.rm_f "test.html"
@@ -83,6 +104,7 @@ expect(File.exist?("test.doc")).to be true
83
104
  expect(html).not_to match(/another empty stylesheet/)
84
105
  expect(html).to match(%r{cdnjs\.cloudflare\.com/ajax/libs/mathjax/})
85
106
  expect(html).to match(/delimiters: \[\['\(#\(', '\)#\)'\]\]/)
107
+ expect(html).not_to match(/html-override/)
86
108
  end
87
109
 
88
110
  it "generates Word output docs with null configuration" do
@@ -101,22 +123,25 @@ expect(File.exist?("test.doc")).to be true
101
123
  word = File.read("test.doc")
102
124
  expect(word).to match(/one empty stylesheet/)
103
125
  expect(word).to match(/div\.table_container/)
126
+ expect(word).not_to match(/word-override/)
104
127
  end
105
128
 
106
129
  it "generates HTML output docs with null configuration from file" do
107
130
  FileUtils.rm_f "spec/assets/iso.doc"
108
131
  FileUtils.rm_f "spec/assets/iso.html"
109
- IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss"}).convert("spec/assets/iso.xml", nil, false)
132
+ IsoDoc::HtmlConvert.new({wordstylesheet: "word.css", htmlstylesheet: "html.scss"}).convert("spec/assets/iso.xml", nil, false)
110
133
  expect(File.exist?("spec/assets/iso.html")).to be true
111
134
  html = File.read("spec/assets/iso.html")
112
135
  expect(html).to match(/another empty stylesheet/)
113
136
  expect(html).to match(%r{https://use.fontawesome.com})
114
137
  expect(html).to match(%r{libs/jquery})
138
+ expect(html).to include "$('#toggle')"
139
+ expect(html).not_to match(/CDATA/)
115
140
  end
116
141
 
117
142
  it "generates Headless HTML output docs with null configuration from file" do
118
143
  FileUtils.rm_f "spec/assets/iso.html"
119
- IsoDoc::HeadlessHtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss"}).convert("spec/assets/iso.xml", nil, false)
144
+ IsoDoc::HeadlessHtmlConvert.new({wordstylesheet: "word.css", htmlstylesheet: "html.scss"}).convert("spec/assets/iso.xml", nil, false)
120
145
  expect(File.exist?("spec/assets/iso.headless.html")).to be true
121
146
  html = File.read("spec/assets/iso.headless.html")
122
147
  expect(html).not_to match(/another empty stylesheet/)
@@ -130,7 +155,7 @@ expect(File.exist?("test.doc")).to be true
130
155
 
131
156
  it "generates Word output docs with null configuration from file" do
132
157
  FileUtils.rm_f "spec/assets/iso.doc"
133
- IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss"}).convert("spec/assets/iso.xml", nil, false)
158
+ IsoDoc::WordConvert.new({wordstylesheet: "word.css", htmlstylesheet: "html.scss"}).convert("spec/assets/iso.xml", nil, false)
134
159
  expect(File.exist?("spec/assets/iso.doc")).to be true
135
160
  word = File.read("spec/assets/iso.doc")
136
161
  expect(word).to match(/one empty stylesheet/)
@@ -139,7 +164,7 @@ expect(File.exist?("test.doc")).to be true
139
164
  it "generates HTML output docs with complete configuration" do
140
165
  FileUtils.rm_f "test.doc"
141
166
  FileUtils.rm_f "test.html"
142
- IsoDoc::HtmlConvert.new({bodyfont: "Zapf", monospacefont: "Consolas", headerfont: "Comic Sans", normalfontsize: "30pt", monospacefontsize: "29pt", smallerfontsize: "28pt", footnotefontsize: "27pt", htmlstylesheet: "spec/assets/html.scss", htmlcoverpage: "spec/assets/htmlcover.html", htmlintropage: "spec/assets/htmlintro.html", scripts: "spec/assets/scripts.html", i18nyaml: "spec/assets/i18n.yaml", ulstyle: "l1", olstyle: "l2"}).convert("test", <<~"INPUT", false)
167
+ IsoDoc::HtmlConvert.new({bodyfont: "Zapf", monospacefont: "Consolas", headerfont: "Comic Sans", normalfontsize: "30pt", monospacefontsize: "29pt", smallerfontsize: "28pt", footnotefontsize: "27pt", htmlstylesheet: "spec/assets/html.scss", htmlstylesheet_override: "spec/assets/html_override.css", htmlcoverpage: "spec/assets/htmlcover.html", htmlintropage: "spec/assets/htmlintro.html", scripts: "spec/assets/scripts.html", i18nyaml: "spec/assets/i18n.yaml", ulstyle: "l1", olstyle: "l2"}).convert("test", <<~"INPUT", false)
143
168
  <iso-standard xmlns="http://riboseinc.com/isoxml">
144
169
  <preface><foreword>
145
170
  <note>
@@ -162,6 +187,7 @@ expect(File.exist?("test.doc")).to be true
162
187
  expect(html).to match(/This is > a script/)
163
188
  expect(html).not_to match(/CDATA/)
164
189
  expect(html).to match(%r{Anta&#x16D;parolo</h1>})
190
+ expect(html).to match(%r{html-override})
165
191
  end
166
192
 
167
193
  it "generates HTML output docs with default fonts" do
@@ -195,7 +221,7 @@ expect(File.exist?("test.doc")).to be true
195
221
  it "generates Word output docs with complete configuration" do
196
222
  FileUtils.rm_f "test.doc"
197
223
  FileUtils.rm_f "test.html"
198
- IsoDoc::WordConvert.new({bodyfont: "Zapf", monospacefont: "Consolas", headerfont: "Comic Sans", normalfontsize: "30pt", monospacefontsize: "29pt", smallerfontsize: "28pt", footnotefontsize: "27pt", wordstylesheet: "spec/assets/html.scss", standardstylesheet: "spec/assets/std.css", header: "spec/assets/header.html", wordcoverpage: "spec/assets/wordcover.html", wordintropage: "spec/assets/wordintro.html", i18nyaml: "spec/assets/i18n.yaml", ulstyle: "l1", olstyle: "l2"}).convert("test", <<~"INPUT", false)
224
+ IsoDoc::WordConvert.new({bodyfont: "Zapf", monospacefont: "Consolas", headerfont: "Comic Sans", normalfontsize: "30pt", monospacefontsize: "29pt", smallerfontsize: "28pt", footnotefontsize: "27pt", wordstylesheet: "spec/assets/html.scss", wordstylesheet_override: "spec/assets/word_override.css", standardstylesheet: "spec/assets/std.css", header: "spec/assets/header.html", wordcoverpage: "spec/assets/wordcover.html", wordintropage: "spec/assets/wordintro.html", i18nyaml: "spec/assets/i18n.yaml", ulstyle: "l1", olstyle: "l2"}).convert("test", <<~"INPUT", false)
199
225
  <iso-standard xmlns="http://riboseinc.com/isoxml">
200
226
  <preface><foreword>
201
227
  <note>
@@ -214,11 +240,11 @@ expect(File.exist?("test.doc")).to be true
214
240
  expect(word).to match(/p\.note \{[^}]*?font-size: 28pt/m)
215
241
  expect(word).to match(/aside \{[^}]*?font-size: 27pt/m)
216
242
  expect(word).to match(/a third empty stylesheet/)
217
- #expect(word).to match(/<title>test<\/title>/)
218
- expect(word).to match(/test_files\/header.html/)
243
+ expect(word).to match(/Content-Disposition: inline; filename="filelist.xml"/)
219
244
  expect(word).to match(/an empty word cover page/)
220
245
  expect(word).to match(/an empty word intro page/)
221
246
  expect(word).to match(%r{Anta&#x16D;parolo</h1>})
247
+ expect(word).to match(%r{word-override})
222
248
  end
223
249
 
224
250
  it "generates Word output docs with default fonts" do
@@ -244,7 +270,7 @@ expect(File.exist?("test.doc")).to be true
244
270
  expect(word).to match(/aside \{[^}]*?font-size: 9pt/m)
245
271
  expect(word).to match(/a third empty stylesheet/)
246
272
  #expect(word).to match(/<title>test<\/title>/)
247
- expect(word).to match(/test_files\/header.html/)
273
+ expect(word).to match(/Content-Disposition: inline; filename="filelist.xml"/)
248
274
  expect(word).to match(/an empty word cover page/)
249
275
  expect(word).to match(/an empty word intro page/)
250
276
  expect(word).to match(%r{Anta&#x16D;parolo</h1>})
@@ -335,10 +361,12 @@ expect(File.exist?("test.doc")).to be true
335
361
  </bibdata>
336
362
  </iso-standard>
337
363
  INPUT
338
- word = File.read("test.doc").sub(%r{^.*Content-Location: file:///C:/Doc/test_files/header.html}m, "Content-Location: file:///C:/Doc/test_files/header.html").
339
- sub(/------=_NextPart.*$/m, "")
364
+ word = File.read("test.doc")
365
+ .sub(%r{^.*Content-ID: <header.html>}m, "Content-ID: <header.html>")
366
+ .sub(/------=_NextPart.*$/m, "")
340
367
  expect(word).to be_equivalent_to <<~"OUTPUT"
341
- Content-Location: file:///C:/Doc/test_files/header.html
368
+ Content-ID: <header.html>
369
+ Content-Disposition: inline; filename="header.html"
342
370
  Content-Transfer-Encoding: base64
343
371
  Content-Type: text/html charset="utf-8"
344
372
  Ci8qIGFuIGVtcHR5IGhlYWRlciAqLwoKU1RBUlQgRE9DIElEOiAKICAgICAgICAgICAxMDAwCiAg
@@ -352,7 +380,7 @@ ICAgICAgIDogRU5EIERPQyBJRAoKRklMRU5BTUU6IHRlc3QKCg==
352
380
  <iso-standard xmlns="http://riboseinc.com/isoxml">
353
381
  <sections>
354
382
  <clause id="A" inline-header="false" obligation="normative"><title>Clause 4</title><clause id="N" inline-header="false" obligation="normative">
355
- <title>Introduction<bookmark id="Q"/> to this<fn reference="1">
383
+ <title>Introduction<bookmark id="Q"/> to this <image src="spec/assets/rice_image1.png" id="_" mimetype="image/png"/> <fn reference="1">
356
384
  <p id="_ff27c067-2785-4551-96cf-0a73530ff1e6">Formerly denoted as 15 % (m/m).</p>
357
385
  </fn></title>
358
386
  </clause>
@@ -822,7 +850,7 @@ TOCLEVEL
822
850
  it "moves images in HTML, using relative file location" do
823
851
  FileUtils.rm_f "spec/test.html"
824
852
  FileUtils.rm_rf "spec/test_htmlimages"
825
- IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss"}).convert("spec/test", <<~"INPUT", false)
853
+ IsoDoc::HtmlConvert.new({wordstylesheet: "assets/word.css", htmlstylesheet: "assets/html.scss"}).convert("spec/test", <<~"INPUT", false)
826
854
  <iso-standard xmlns="http://riboseinc.com/isoxml">
827
855
  <preface><foreword>
828
856
  <figure id="_">
@@ -891,7 +919,7 @@ TOCLEVEL
891
919
  it "encodes images in HTML as data URIs, using relative file location" do
892
920
  FileUtils.rm_f "spec/test.html"
893
921
  FileUtils.rm_rf "spec/test_htmlimages"
894
- IsoDoc::HtmlConvert.new({htmlstylesheet: "spec/assets/html.scss", datauriimage: true}).convert("spec/test", <<~"INPUT", false)
922
+ IsoDoc::HtmlConvert.new({htmlstylesheet: "assets/html.scss", datauriimage: true}).convert("spec/test", <<~"INPUT", false)
895
923
  <iso-standard xmlns="http://riboseinc.com/isoxml">
896
924
  <preface><foreword>
897
925
  <figure id="_">