metanorma-ieee 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/rake.yml +13 -0
  3. data/.rubocop.yml +10 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +11 -0
  6. data/LICENSE +25 -0
  7. data/README.adoc +30 -0
  8. data/Rakefile +8 -0
  9. data/bin/console +14 -0
  10. data/bin/rspec +17 -0
  11. data/bin/setup +8 -0
  12. data/lib/html2doc/ieee.rb +89 -0
  13. data/lib/isodoc/ieee/base_convert.rb +33 -0
  14. data/lib/isodoc/ieee/html/header.html +146 -0
  15. data/lib/isodoc/ieee/html/html_ieee_intro.html +12 -0
  16. data/lib/isodoc/ieee/html/html_ieee_titlepage.html +44 -0
  17. data/lib/isodoc/ieee/html/htmlstyle.css +1027 -0
  18. data/lib/isodoc/ieee/html/htmlstyle.scss +736 -0
  19. data/lib/isodoc/ieee/html/ieee.css +3603 -0
  20. data/lib/isodoc/ieee/html/ieee.scss +3418 -0
  21. data/lib/isodoc/ieee/html/scripts.html +70 -0
  22. data/lib/isodoc/ieee/html/word_ieee_intro.html +70 -0
  23. data/lib/isodoc/ieee/html/word_ieee_titlepage.html +28 -0
  24. data/lib/isodoc/ieee/html/wordstyle.css +5310 -0
  25. data/lib/isodoc/ieee/html/wordstyle.scss +5026 -0
  26. data/lib/isodoc/ieee/html_convert.rb +52 -0
  27. data/lib/isodoc/ieee/i18n-en.yaml +28 -0
  28. data/lib/isodoc/ieee/i18n.rb +19 -0
  29. data/lib/isodoc/ieee/ieee.amendment.xsl +11177 -0
  30. data/lib/isodoc/ieee/ieee.rb +11 -0
  31. data/lib/isodoc/ieee/ieee.standard.xsl +11177 -0
  32. data/lib/isodoc/ieee/init.rb +28 -0
  33. data/lib/isodoc/ieee/metadata.rb +136 -0
  34. data/lib/isodoc/ieee/pdf_convert.rb +24 -0
  35. data/lib/isodoc/ieee/presentation_terms.rb +181 -0
  36. data/lib/isodoc/ieee/presentation_xml_convert.rb +89 -0
  37. data/lib/isodoc/ieee/word_authority.rb +160 -0
  38. data/lib/isodoc/ieee/word_cleanup.rb +134 -0
  39. data/lib/isodoc/ieee/word_convert.rb +75 -0
  40. data/lib/isodoc/ieee/xref.rb +77 -0
  41. data/lib/isodoc/ieee.rb +11 -0
  42. data/lib/metanorma/ieee/basicdoc.rng +1150 -0
  43. data/lib/metanorma/ieee/biblio.rng +1385 -0
  44. data/lib/metanorma/ieee/boilerplate.xml +298 -0
  45. data/lib/metanorma/ieee/cleanup.rb +160 -0
  46. data/lib/metanorma/ieee/converter.rb +81 -0
  47. data/lib/metanorma/ieee/front.rb +120 -0
  48. data/lib/metanorma/ieee/ieee.rng +97 -0
  49. data/lib/metanorma/ieee/isodoc.rng +2776 -0
  50. data/lib/metanorma/ieee/processor.rb +56 -0
  51. data/lib/metanorma/ieee/reqt.rng +226 -0
  52. data/lib/metanorma/ieee/validate.rb +198 -0
  53. data/lib/metanorma/ieee/validate_section.rb +119 -0
  54. data/lib/metanorma/ieee/validate_style.rb +108 -0
  55. data/lib/metanorma/ieee/version.rb +5 -0
  56. data/lib/metanorma/ieee.rb +11 -0
  57. data/lib/metanorma-ieee.rb +8 -0
  58. data/metanorma-itu.gemspec +41 -0
  59. metadata +284 -0
@@ -0,0 +1,134 @@
1
+ module IsoDoc
2
+ module IEEE
3
+ class WordConvert < IsoDoc::WordConvert
4
+ def toWord(result, filename, dir, header)
5
+ result = from_xhtml(word_cleanup(to_xhtml(result)))
6
+ .gsub(/-DOUBLE_HYPHEN_ESCAPE-/, "--")
7
+ @wordstylesheet = wordstylesheet_update
8
+ ::Html2Doc::IEEE.new(
9
+ filename: filename,
10
+ imagedir: @localdir,
11
+ stylesheet: @wordstylesheet&.path,
12
+ header_file: header&.path, dir: dir,
13
+ asciimathdelims: [@openmathdelim, @closemathdelim],
14
+ liststyles: { ul: @ulstyle, ol: @olstyle }
15
+ ).process(result)
16
+ header&.unlink
17
+ @wordstylesheet.unlink if @wordstylesheet.is_a?(Tempfile)
18
+ end
19
+
20
+ def abstract_cleanup(docxml)
21
+ dest = docxml.at("div[@id = 'abstract-destination']") or return
22
+ if f = docxml.at("//div[@class = 'abstract']")
23
+ f.previous_element.remove
24
+ abstract_cleanup1(f, dest)
25
+ f.remove
26
+ elsif f = docxml.at("//div[@type = 'scope']")
27
+ abstract_cleanup1(f, dest)
28
+ end
29
+ end
30
+
31
+ def abstract_cleanup1(source, dest)
32
+ source.elements.each do |e|
33
+ next if %w(h1 h2).include?(e.name)
34
+
35
+ dest << e.dup
36
+ dest.elements.last["class"] = "IEEEStdsAbstractBody"
37
+ end
38
+ dest.elements.first.children.first.previous =
39
+ "<span class='IEEEStdsAbstractHeader'><span lang='EN-US'>"\
40
+ "Abstract:</span></span> "
41
+ end
42
+
43
+ def introduction_cleanup(docxml)
44
+ dest = docxml.at("div[@id = 'introduction-destination']") or return
45
+ unless i = docxml.at("//h1[@class = 'IntroTitle']")&.parent
46
+ dest.parent.remove
47
+ return
48
+ end
49
+ introduction_cleanup1(i, dest)
50
+ end
51
+
52
+ def introduction_cleanup1(intro, dest)
53
+ docxml = intro.document
54
+ intro.previous_element.remove
55
+ dest.replace(intro.remove)
56
+ i = docxml.at("//h1[@class = 'IntroTitle']")
57
+ i.next_element == "div" && i.next_element["class"] == "Admonition" and
58
+ i.next_element["class"] = "IEEEStdsIntroduction"
59
+ end
60
+
61
+ def word_cleanup(docxml)
62
+ super
63
+ abstract_cleanup(docxml)
64
+ introduction_cleanup(docxml)
65
+ div_cleanup(docxml)
66
+ headings_cleanup(docxml)
67
+ span_style_cleanup(docxml)
68
+ style_cleanup(docxml)
69
+ para_type_cleanup(docxml)
70
+ docxml
71
+ end
72
+
73
+ def headings_cleanup(docxml)
74
+ (1..4).each do |i|
75
+ docxml.xpath("//h#{i}").each do |h|
76
+ headings_cleanup1(h)
77
+ h.name = "p"
78
+ h["class"] = "IEEEStdsLevel#{i}Header"
79
+ end
80
+ end
81
+ end
82
+
83
+ def headings_cleanup1(hdr)
84
+ if hdr.children.size > 1 && hdr.children[1].name == "span" &&
85
+ hdr.children[1]["style"] == "mso-tab-count:1"
86
+ 2.times { hdr.children.first.remove }
87
+ end
88
+ end
89
+
90
+ def div_cleanup(docxml)
91
+ d = docxml.at("//div[@class = 'WordSection2']"\
92
+ "[div[@class = 'WordSection2']]") and
93
+ d.replace(d.children)
94
+ i = 0
95
+ docxml.xpath("//div[@class]").each do |div|
96
+ next unless /^WordSection/.match?(div["class"])
97
+
98
+ i += 1
99
+ div["class"] = "WordSection#{i}"
100
+ end
101
+ end
102
+
103
+ def para_type_cleanup(html)
104
+ html.xpath("//p[@type]").each { |p| p.delete("type") }
105
+ end
106
+
107
+ def span_style_cleanup(html)
108
+ html.xpath("//strong").each do |s|
109
+ s.name = "span"
110
+ s["class"] = "IEEEStdsParaBold"
111
+ end
112
+ html.xpath("//em").each do |s|
113
+ s.name = "span"
114
+ s["class"] = "IEEEStdsAddItal"
115
+ end
116
+ end
117
+
118
+ STYLESMAP = {
119
+ MsoNormal: "IEEEStdsParagraph",
120
+ NormRef: "IEEEStdsBibliographicEntry",
121
+ Biblio: "IEEEStdsBibliographicEntry",
122
+ }.freeze
123
+
124
+ def style_cleanup(docxml)
125
+ STYLESMAP.each do |k, v|
126
+ docxml.xpath("//*[@class = '#{k}']").each { |s| s["class"] = v }
127
+ end
128
+ docxml.xpath("//p[not(@class)]").each do |p|
129
+ p["class"] = "IEEEStdsParagraph"
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,75 @@
1
+ require "isodoc"
2
+ require_relative "init"
3
+ require_relative "word_cleanup"
4
+ require_relative "word_authority"
5
+
6
+ module IsoDoc
7
+ module IEEE
8
+ class WordConvert < IsoDoc::WordConvert
9
+ def initialize(options)
10
+ @libdir = File.dirname(__FILE__)
11
+ super
12
+ end
13
+
14
+ def default_fonts(options)
15
+ { bodyfont: (if options[:script] == "Hans"
16
+ '"Source Han Sans",serif'
17
+ else
18
+ '"Times New Roman",serif'
19
+ end),
20
+ headerfont: (if options[:script] == "Hans"
21
+ '"Source Han Sans",sans-serif'
22
+ else
23
+ '"Arial",sans-serif'
24
+ end),
25
+ monospacefont: '"Courier New",monospace',
26
+ normalfontsize: "12.0pt",
27
+ footnotefontsize: "11.0pt",
28
+ smallerfontsize: "10.0pt",
29
+ monospacefontsize: "10.0pt" }
30
+ end
31
+
32
+ def default_file_locations(_options)
33
+ { wordstylesheet: html_doc_path("wordstyle.scss"),
34
+ standardstylesheet: html_doc_path("ieee.scss"),
35
+ header: html_doc_path("header.html"),
36
+ wordcoverpage: html_doc_path("word_ieee_titlepage.html"),
37
+ wordintropage: html_doc_path("word_ieee_intro.html"),
38
+ ulstyle: "l3",
39
+ olstyle: "l2" }
40
+ end
41
+
42
+ def abstract(isoxml, out)
43
+ f = isoxml.at(ns("//preface/abstract")) || return
44
+ page_break(out)
45
+ out.div **attr_code(id: f["id"], class: "abstract") do |s|
46
+ clause_name(nil, f.at(ns("./title")), s, { class: "AbstractTitle" })
47
+ f.elements.each { |e| parse(e, s) unless e.name == "title" }
48
+ end
49
+ end
50
+
51
+ def make_body3(body, docxml)
52
+ body.div **{ class: "WordSection13" } do |_div3|
53
+ middle_title_ieee(docxml, body)
54
+ end
55
+ section_break(body, continuous: true)
56
+ body.div **{ class: "WordSection14" } do |div3|
57
+ middle docxml, div3
58
+ footnotes div3
59
+ comments div3
60
+ end
61
+ end
62
+
63
+ def middle_title(isoxml, out); end
64
+
65
+ def middle_title_ieee(_docxml, out)
66
+ out.p(**{ class: "IEEEStdsTitle", style: "margin-top:70.0pt" }) do |p|
67
+ p << @meta.get[:full_doctitle]
68
+ end
69
+ end
70
+
71
+ include BaseConvert
72
+ include Init
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,77 @@
1
+ require "isodoc"
2
+
3
+ module IsoDoc
4
+ module IEEE
5
+ class Counter < ::IsoDoc::XrefGen::Counter
6
+ end
7
+
8
+ class Xref < ::IsoDoc::Xref
9
+ def initialize(lang, script, klass, labels, options)
10
+ super
11
+ @hierarchical_assets = options[:hierarchical_assets]
12
+ end
13
+
14
+ def initial_anchor_names(doc)
15
+ if @parse_settings.empty? || @parse_settings[:clauses]
16
+ doc.xpath(ns("//preface/*")).each do |c|
17
+ c.element? and preface_names(c)
18
+ end
19
+ end
20
+ if @parse_settings.empty?
21
+ if @hierarchical_assets
22
+ hierarchical_asset_names(doc.xpath("//xmlns:preface/child::*"),
23
+ "Preface")
24
+ else
25
+ sequential_asset_names(doc.xpath(ns("//preface/*")))
26
+ end
27
+ end
28
+ if @parse_settings.empty? || @parse_settings[:clauses]
29
+ n = Counter.new
30
+ n = section_names(doc.at(ns("//clause[@type = 'overview']")), n, 1)
31
+ n = section_names(doc.at(ns(@klass.norm_ref_xpath)), n, 1)
32
+ n = section_names(doc.at(ns("//sections/terms | "\
33
+ "//sections/clause[descendant::terms]")), n, 1)
34
+ n = section_names(doc.at(ns("//sections/definitions")), n, 1)
35
+ clause_names(doc, n)
36
+ end
37
+ if @parse_settings.empty?
38
+ middle_section_asset_names(doc)
39
+ termnote_anchor_names(doc)
40
+ termexample_anchor_names(doc)
41
+ end
42
+ end
43
+
44
+ def middle_sections
45
+ " #{@klass.norm_ref_xpath} | "\
46
+ "//sections/terms | //preface/clause | "\
47
+ "//sections/definitions | //clause[parent::sections]"
48
+ end
49
+
50
+ def middle_section_asset_names(doc)
51
+ middle_sections =
52
+ "#{@klass.norm_ref_xpath} | //sections/terms | "\
53
+ "//sections/definitions | //clause[parent::sections]"
54
+ if @hierarchical_assets
55
+ doc.xpath(ns(middle_sections)).each do |c|
56
+ hierarchical_asset_names(c, @anchors[c["id"]][:label])
57
+ end
58
+ else
59
+ sequential_asset_names(doc.xpath(ns(middle_sections)))
60
+ end
61
+ end
62
+
63
+ def sequential_formula_names(clause)
64
+ c = Counter.new
65
+ clause.xpath(ns(".//formula")).reject do |n|
66
+ blank?(n["id"])
67
+ end.each do |t|
68
+ @anchors[t["id"]] = anchor_struct(
69
+ c.increment(t).print, nil,
70
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
71
+ "formula", t["unnumbered"]
72
+ )
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,11 @@
1
+ require "isodoc/ieee/metadata"
2
+ require "isodoc/ieee/base_convert"
3
+ require "isodoc/ieee/html_convert"
4
+ require "isodoc/ieee/pdf_convert"
5
+ require "isodoc/ieee/word_convert"
6
+ require "isodoc/ieee/presentation_xml_convert"
7
+
8
+ module IsoDoc
9
+ module IEEE
10
+ end
11
+ end