isodoc 0.5.5 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CODE_OF_CONDUCT.md +46 -0
  3. data/LICENSE +25 -0
  4. data/README.adoc +1 -1
  5. data/Rakefile +6 -0
  6. data/isodoc.gemspec +1 -0
  7. data/lib/isodoc.rb +4 -95
  8. data/lib/isodoc/cleanup.rb +14 -10
  9. data/lib/isodoc/{notes.rb → comments.rb} +0 -73
  10. data/lib/isodoc/convert.rb +97 -0
  11. data/lib/isodoc/footnotes.rb +74 -0
  12. data/lib/isodoc/html.rb +41 -4
  13. data/lib/isodoc/i18n-en.yaml +1 -0
  14. data/lib/isodoc/i18n-fr.yaml +1 -0
  15. data/lib/isodoc/i18n-zh-Hans.yaml +1 -0
  16. data/lib/isodoc/i18n.rb +1 -0
  17. data/lib/isodoc/inline.rb +4 -12
  18. data/lib/isodoc/iso2wordhtml.rb +26 -13
  19. data/lib/isodoc/metadata.rb +23 -10
  20. data/lib/isodoc/references.rb +20 -22
  21. data/lib/isodoc/section.rb +4 -3
  22. data/lib/isodoc/table.rb +0 -2
  23. data/lib/isodoc/terms.rb +2 -13
  24. data/lib/isodoc/utils.rb +24 -3
  25. data/lib/isodoc/version.rb +1 -1
  26. data/lib/isodoc/wordconvert/comments.rb +155 -0
  27. data/lib/isodoc/wordconvert/convert.rb +31 -0
  28. data/lib/isodoc/wordconvert/footnotes.rb +80 -0
  29. data/lib/isodoc/wordconvert/wordconvertmodule.rb +212 -0
  30. data/lib/isodoc/xref_gen.rb +50 -79
  31. data/lib/isodoc/xref_sect_gen.rb +82 -0
  32. data/spec/assets/header.html +7 -0
  33. data/spec/assets/html.css +2 -0
  34. data/spec/assets/htmlcover.html +4 -0
  35. data/spec/assets/htmlintro.html +5 -0
  36. data/spec/assets/i18n.yaml +2 -0
  37. data/spec/assets/iso.xml +8 -0
  38. data/spec/assets/rice_image1.png +0 -0
  39. data/spec/assets/std.css +2 -0
  40. data/spec/assets/word.css +2 -0
  41. data/spec/assets/wordcover.html +3 -0
  42. data/spec/assets/wordintro.html +4 -0
  43. data/spec/isodoc/blocks_spec.rb +130 -47
  44. data/spec/isodoc/cleanup_spec.rb +693 -0
  45. data/spec/isodoc/footnotes_spec.rb +282 -0
  46. data/spec/isodoc/i18n_spec.rb +662 -0
  47. data/spec/isodoc/inline_spec.rb +344 -0
  48. data/spec/isodoc/lists_spec.rb +81 -18
  49. data/spec/isodoc/metadata_spec.rb +141 -0
  50. data/spec/isodoc/postproc_spec.rb +444 -0
  51. data/spec/isodoc/ref_spec.rb +158 -0
  52. data/spec/isodoc/section_spec.rb +275 -112
  53. data/spec/isodoc/table_spec.rb +146 -8
  54. data/spec/isodoc/terms_spec.rb +118 -0
  55. data/spec/isodoc/xref_spec.rb +490 -114
  56. metadata +46 -4
  57. data/lib/isodoc/postprocessing.rb +0 -176
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2018-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: roman-numerals
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: bundler
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -306,13 +320,19 @@ files:
306
320
  - ".rubocop.ribose.yml"
307
321
  - ".rubocop.tb.yml"
308
322
  - ".rubocop.yml"
323
+ - CODE_OF_CONDUCT.md
309
324
  - Gemfile
325
+ - LICENSE
310
326
  - README.adoc
327
+ - Rakefile
311
328
  - bin/rspec
312
329
  - isodoc.gemspec
313
330
  - lib/isodoc.rb
314
331
  - lib/isodoc/blocks.rb
315
332
  - lib/isodoc/cleanup.rb
333
+ - lib/isodoc/comments.rb
334
+ - lib/isodoc/convert.rb
335
+ - lib/isodoc/footnotes.rb
316
336
  - lib/isodoc/html.rb
317
337
  - lib/isodoc/i18n-en.yaml
318
338
  - lib/isodoc/i18n-fr.yaml
@@ -322,19 +342,41 @@ files:
322
342
  - lib/isodoc/iso2wordhtml.rb
323
343
  - lib/isodoc/lists.rb
324
344
  - lib/isodoc/metadata.rb
325
- - lib/isodoc/notes.rb
326
- - lib/isodoc/postprocessing.rb
327
345
  - lib/isodoc/references.rb
328
346
  - lib/isodoc/section.rb
329
347
  - lib/isodoc/table.rb
330
348
  - lib/isodoc/terms.rb
331
349
  - lib/isodoc/utils.rb
332
350
  - lib/isodoc/version.rb
351
+ - lib/isodoc/wordconvert/comments.rb
352
+ - lib/isodoc/wordconvert/convert.rb
353
+ - lib/isodoc/wordconvert/footnotes.rb
354
+ - lib/isodoc/wordconvert/wordconvertmodule.rb
333
355
  - lib/isodoc/xref_gen.rb
356
+ - lib/isodoc/xref_sect_gen.rb
357
+ - spec/assets/header.html
358
+ - spec/assets/html.css
359
+ - spec/assets/htmlcover.html
360
+ - spec/assets/htmlintro.html
361
+ - spec/assets/i18n.yaml
362
+ - spec/assets/iso.xml
363
+ - spec/assets/rice_image1.png
364
+ - spec/assets/std.css
365
+ - spec/assets/word.css
366
+ - spec/assets/wordcover.html
367
+ - spec/assets/wordintro.html
334
368
  - spec/isodoc/blocks_spec.rb
369
+ - spec/isodoc/cleanup_spec.rb
370
+ - spec/isodoc/footnotes_spec.rb
371
+ - spec/isodoc/i18n_spec.rb
372
+ - spec/isodoc/inline_spec.rb
335
373
  - spec/isodoc/lists_spec.rb
374
+ - spec/isodoc/metadata_spec.rb
375
+ - spec/isodoc/postproc_spec.rb
376
+ - spec/isodoc/ref_spec.rb
336
377
  - spec/isodoc/section_spec.rb
337
378
  - spec/isodoc/table_spec.rb
379
+ - spec/isodoc/terms_spec.rb
338
380
  - spec/isodoc/xref_spec.rb
339
381
  - spec/spec_helper.rb
340
382
  homepage: https://github.com/riboseinc/isodoc
@@ -1,176 +0,0 @@
1
- require "html2doc"
2
- require "htmlentities"
3
- require "nokogiri"
4
- require "liquid"
5
- require "pp"
6
-
7
- module IsoDoc
8
- class Convert
9
- def postprocess(result, filename, dir)
10
- generate_header(filename, dir)
11
- result = from_xhtml(cleanup(to_xhtml(result)))
12
- toWord(result, filename, dir)
13
- toHTML(result, filename)
14
- end
15
-
16
- def toWord(result, filename, dir)
17
- result = from_xhtml(word_cleanup(to_xhtml(result)))
18
- result = populate_template(result, :word)
19
- Html2Doc.process(result, filename: filename, stylesheet: @wordstylesheet,
20
- header_file: "header.html", dir: dir,
21
- asciimathdelims: [@openmathdelim, @closemathdelim],
22
- liststyles: { ul: @ulstyle, ol: @olstyle })
23
- end
24
-
25
- def word_cleanup(docxml)
26
- word_preface(docxml)
27
- word_annex_cleanup(docxml)
28
- word_dl_cleanup(docxml)
29
- docxml
30
- end
31
-
32
- def word_dl_cleanup1(dtd, tr)
33
- dtd[:dt].name = "td"
34
- dtd[:dt]["valign"] = "top"
35
- dtd[:dt].parent = tr
36
- dtd[:dd].name = "td"
37
- dtd[:dd]["valign"] = "top"
38
- dtd[:dd].parent = tr
39
- end
40
-
41
- def word_dl_cleanup(docxml)
42
- docxml.xpath("//dl").each do |dl|
43
- dl.name = "table"
44
- extract_symbols_list(dl).each do |dtd|
45
- tr = dl.add_child("<tr></tr>").first
46
- word_dl_cleanup1(dtd, tr)
47
- end
48
- end
49
- end
50
-
51
- # force Annex h2 to be p.h2Annex, so it is not picked up by ToC
52
- def word_annex_cleanup(docxml)
53
- docxml.xpath("//h2[ancestor::*[@class = 'Section3']]").each do |h2|
54
- h2.name = "p"
55
- h2["class"] = "h2Annex"
56
- end
57
- end
58
-
59
- def word_preface(docxml)
60
- cover = to_xhtml_fragment(File.read(@wordcoverpage, encoding: "UTF-8"))
61
- docxml.at('//div[@class="WordSection1"]').children.first.previous =
62
- cover.to_xml(encoding: "US-ASCII")
63
- intro = to_xhtml_fragment(File.read(@wordintropage, encoding: "UTF-8").
64
- sub(/WORDTOC/, make_WordToC(docxml)))
65
- docxml.at('//div[@class="WordSection2"]').children.first.previous =
66
- intro.to_xml(encoding: "US-ASCII")
67
- end
68
-
69
- def populate_template(docxml, _format)
70
- meta = get_metadata
71
- docxml = docxml.
72
- gsub(/\[TERMREF\]\s*/, l10n("[#{@source_lbl}: ")).
73
- gsub(/\s*\[\/TERMREF\]\s*/, l10n("]")).
74
- gsub(/\s*\[ISOSECTION\]/, l10n(", ")).
75
- gsub(/\s*\[MODIFICATION\]/, l10n(", #{@modified_lbl} &mdash; "))
76
- template = Liquid::Template.parse(docxml)
77
- template.render(meta.map { |k, v| [k.to_s, v] }.to_h)
78
- end
79
-
80
- def generate_header(filename, _dir)
81
- template = Liquid::Template.parse(File.read(@header, encoding: "UTF-8"))
82
- meta = get_metadata
83
- meta[:filename] = filename
84
- params = meta.map { |k, v| [k.to_s, v] }.to_h
85
- File.open("header.html", "w") do |f|
86
- f.write(template.render(params))
87
- end
88
- end
89
-
90
- # these are in fact preprocess,
91
- # but they are extraneous to main HTML file
92
- def html_header(html, docxml, filename, dir)
93
- anchor_names docxml
94
- define_head html, filename, dir
95
- end
96
-
97
- # isodoc.css overrides any CSS injected by Html2Doc, which
98
- # is inserted before this CSS.
99
- def define_head(html, filename, _dir)
100
- html.head do |head|
101
- head.title { |t| t << filename }
102
- return unless @standardstylesheet
103
- head.style do |style|
104
- stylesheet = File.read(@standardstylesheet).
105
- gsub("FILENAME", filename)
106
- style.comment "\n#{stylesheet}\n"
107
- end
108
- end
109
- end
110
-
111
- def titlepage(_docxml, div)
112
- titlepage = File.read(@wordcoverpage, encoding: "UTF-8")
113
- div.parent.add_child titlepage
114
- end
115
-
116
- def word_toc_entry(toclevel, heading)
117
- bookmark = Random.rand(1000000000)
118
- <<~TOC
119
- <p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span
120
- lang="EN-GB" style='mso-no-proof:yes'>
121
- <a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB"
122
- class="MsoTocTextSpan">
123
- <span style='mso-tab-count:1 dotted'>. </span>
124
- </span><span lang="EN-GB" class="MsoTocTextSpan">
125
- <span style='mso-element:field-begin'></span></span>
126
- <span lang="EN-GB"
127
- class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
128
- <span lang="EN-GB" class="MsoTocTextSpan"><span
129
- style='mso-element:field-separator'></span></span><span
130
- lang="EN-GB" class="MsoTocTextSpan">1</span>
131
- <span lang="EN-GB"
132
- class="MsoTocTextSpan"></span><span
133
- lang="EN-GB" class="MsoTocTextSpan"><span
134
- style='mso-element:field-end'></span></span></a></span></span></p>
135
-
136
- TOC
137
- end
138
-
139
- WORD_TOC_PREFACE = <<~TOC.freeze
140
- <span lang="EN-GB"><span
141
- style='mso-element:field-begin'></span><span
142
- style='mso-spacerun:yes'>&#xA0;</span>TOC
143
- \\o &quot;1-2&quot; \\h \\z \\u <span
144
- style='mso-element:field-separator'></span></span>
145
- TOC
146
-
147
- WORD_TOC_SUFFIX = <<~TOC.freeze
148
- <p class="MsoToc1"><span lang="EN-GB"><span
149
- style='mso-element:field-end'></span></span><span
150
- lang="EN-GB"><o:p>&nbsp;</o:p></span></p>
151
- TOC
152
-
153
- def header_strip(h)
154
- h = h.to_s.gsub(%r{<br/>}, " ").
155
- sub(/<h[12][^>]*>/, "").sub(%r{</h[12]>}, "")
156
- h1 = to_xhtml_fragment(h)
157
- h1.xpath(".//*").each do |x|
158
- if x.name == "span" && x["style"] == "MsoCommentReference"
159
- x.children.remove
160
- x.content = ""
161
- end
162
- end
163
- from_xhtml(h1)
164
- end
165
-
166
- def make_WordToC(docxml)
167
- toc = ""
168
- docxml.xpath("//h1 | //h2[not(ancestor::*[@class = 'Section3'])]").
169
- each do |h|
170
- toc += word_toc_entry(h.name == "h1" ? 1 : 2, header_strip(h))
171
- end
172
- toc.sub(/(<p class="MsoToc1">)/,
173
- %{\\1#{WORD_TOC_PREFACE}}) + WORD_TOC_SUFFIX
174
- end
175
- end
176
- end