metanorma-standoc 1.11.3 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +3 -31
  3. data/.gitignore +23 -0
  4. data/Gemfile +0 -1
  5. data/lib/asciidoctor/standoc/base.rb +2 -145
  6. data/lib/asciidoctor/standoc/blocks.rb +2 -238
  7. data/lib/asciidoctor/standoc/blocks_notes.rb +2 -100
  8. data/lib/asciidoctor/standoc/cleanup.rb +2 -208
  9. data/lib/asciidoctor/standoc/cleanup_amend.rb +2 -53
  10. data/lib/asciidoctor/standoc/cleanup_block.rb +2 -172
  11. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -212
  12. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +2 -108
  13. data/lib/asciidoctor/standoc/cleanup_image.rb +2 -69
  14. data/lib/asciidoctor/standoc/cleanup_inline.rb +2 -189
  15. data/lib/asciidoctor/standoc/cleanup_maths.rb +2 -221
  16. data/lib/asciidoctor/standoc/cleanup_ref.rb +2 -169
  17. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +2 -103
  18. data/lib/asciidoctor/standoc/cleanup_reqt.rb +2 -110
  19. data/lib/asciidoctor/standoc/cleanup_section.rb +2 -184
  20. data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -91
  21. data/lib/asciidoctor/standoc/cleanup_symbols.rb +2 -47
  22. data/lib/asciidoctor/standoc/cleanup_table.rb +2 -67
  23. data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -139
  24. data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +2 -192
  25. data/lib/asciidoctor/standoc/cleanup_text.rb +2 -95
  26. data/lib/asciidoctor/standoc/cleanup_toc.rb +3 -0
  27. data/lib/asciidoctor/standoc/cleanup_xref.rb +2 -106
  28. data/lib/asciidoctor/standoc/converter.rb +2 -123
  29. data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +2 -56
  30. data/lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb +2 -102
  31. data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +3 -404
  32. data/lib/asciidoctor/standoc/deprecated.rb +5 -0
  33. data/lib/asciidoctor/standoc/front.rb +2 -219
  34. data/lib/asciidoctor/standoc/front_contributor.rb +2 -191
  35. data/lib/asciidoctor/standoc/inline.rb +2 -231
  36. data/lib/asciidoctor/standoc/lists.rb +2 -119
  37. data/lib/asciidoctor/standoc/macros.rb +2 -203
  38. data/lib/asciidoctor/standoc/macros_form.rb +2 -62
  39. data/lib/asciidoctor/standoc/macros_note.rb +2 -44
  40. data/lib/asciidoctor/standoc/macros_plantuml.rb +2 -112
  41. data/lib/asciidoctor/standoc/macros_terms.rb +2 -180
  42. data/lib/asciidoctor/standoc/ref.rb +2 -251
  43. data/lib/asciidoctor/standoc/ref_sect.rb +2 -153
  44. data/lib/asciidoctor/standoc/ref_utility.rb +2 -0
  45. data/lib/asciidoctor/standoc/render.rb +2 -116
  46. data/lib/asciidoctor/standoc/reqt.rb +2 -89
  47. data/lib/asciidoctor/standoc/section.rb +2 -194
  48. data/lib/asciidoctor/standoc/table.rb +2 -84
  49. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +2 -178
  50. data/lib/asciidoctor/standoc/terms.rb +2 -153
  51. data/lib/asciidoctor/standoc/utils.rb +2 -100
  52. data/lib/asciidoctor/standoc/validate.rb +2 -157
  53. data/lib/asciidoctor/standoc/validate_section.rb +2 -54
  54. data/lib/isodoc/html/htmlstyle.css +44 -29
  55. data/lib/isodoc/html/htmlstyle.scss +17 -12
  56. data/lib/metanorma/standoc/base.rb +163 -0
  57. data/lib/{asciidoctor → metanorma}/standoc/basicdoc.rng +0 -0
  58. data/lib/{asciidoctor → metanorma}/standoc/biblio.rng +2 -2
  59. data/lib/metanorma/standoc/blocks.rb +239 -0
  60. data/lib/metanorma/standoc/blocks_notes.rb +101 -0
  61. data/lib/metanorma/standoc/cleanup.rb +157 -0
  62. data/lib/metanorma/standoc/cleanup_amend.rb +54 -0
  63. data/lib/metanorma/standoc/cleanup_block.rb +173 -0
  64. data/lib/metanorma/standoc/cleanup_boilerplate.rb +213 -0
  65. data/lib/metanorma/standoc/cleanup_footnotes.rb +109 -0
  66. data/lib/metanorma/standoc/cleanup_image.rb +70 -0
  67. data/lib/metanorma/standoc/cleanup_inline.rb +190 -0
  68. data/lib/metanorma/standoc/cleanup_maths.rb +222 -0
  69. data/lib/metanorma/standoc/cleanup_ref.rb +170 -0
  70. data/lib/metanorma/standoc/cleanup_ref_dl.rb +104 -0
  71. data/lib/metanorma/standoc/cleanup_reqt.rb +111 -0
  72. data/lib/metanorma/standoc/cleanup_section.rb +212 -0
  73. data/lib/metanorma/standoc/cleanup_section_names.rb +92 -0
  74. data/lib/metanorma/standoc/cleanup_symbols.rb +48 -0
  75. data/lib/metanorma/standoc/cleanup_table.rb +68 -0
  76. data/lib/metanorma/standoc/cleanup_terms.rb +140 -0
  77. data/lib/metanorma/standoc/cleanup_terms_designations.rb +199 -0
  78. data/lib/metanorma/standoc/cleanup_text.rb +74 -0
  79. data/lib/metanorma/standoc/cleanup_toc.rb +98 -0
  80. data/lib/metanorma/standoc/cleanup_xref.rb +107 -0
  81. data/lib/metanorma/standoc/converter.rb +126 -0
  82. data/lib/metanorma/standoc/datamodel/attributes_table_preprocessor.rb +57 -0
  83. data/lib/metanorma/standoc/datamodel/diagram_preprocessor.rb +103 -0
  84. data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +409 -0
  85. data/lib/metanorma/standoc/front.rb +224 -0
  86. data/lib/metanorma/standoc/front_contributor.rb +192 -0
  87. data/lib/metanorma/standoc/inline.rb +232 -0
  88. data/lib/{asciidoctor → metanorma}/standoc/isodoc.rng +104 -3
  89. data/lib/metanorma/standoc/lists.rb +120 -0
  90. data/lib/metanorma/standoc/macros.rb +205 -0
  91. data/lib/metanorma/standoc/macros_embed.rb +72 -0
  92. data/lib/metanorma/standoc/macros_form.rb +63 -0
  93. data/lib/metanorma/standoc/macros_note.rb +45 -0
  94. data/lib/metanorma/standoc/macros_plantuml.rb +113 -0
  95. data/lib/metanorma/standoc/macros_terms.rb +194 -0
  96. data/lib/metanorma/standoc/ref.rb +243 -0
  97. data/lib/metanorma/standoc/ref_sect.rb +153 -0
  98. data/lib/{asciidoctor/standoc/ref_date_id.rb → metanorma/standoc/ref_utility.rb} +43 -5
  99. data/lib/metanorma/standoc/render.rb +115 -0
  100. data/lib/metanorma/standoc/reqt.rb +90 -0
  101. data/lib/{asciidoctor → metanorma}/standoc/reqt.rng +0 -0
  102. data/lib/metanorma/standoc/section.rb +209 -0
  103. data/lib/metanorma/standoc/table.rb +85 -0
  104. data/lib/metanorma/standoc/term_lookup_cleanup.rb +179 -0
  105. data/lib/metanorma/standoc/terms.rb +160 -0
  106. data/lib/metanorma/standoc/utils.rb +101 -0
  107. data/lib/metanorma/standoc/validate.rb +158 -0
  108. data/lib/metanorma/standoc/validate_section.rb +55 -0
  109. data/lib/metanorma/standoc/version.rb +1 -1
  110. data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/model_representation.adoc.erb +0 -0
  111. data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/plantuml_representation.adoc.erb +0 -0
  112. data/lib/metanorma-standoc.rb +1 -1
  113. data/metanorma-standoc.gemspec +1 -1
  114. data/spec/assets/a1.adoc +8 -0
  115. data/spec/assets/a2.adoc +8 -0
  116. data/spec/assets/a3.adoc +9 -0
  117. data/spec/assets/a4.adoc +4 -0
  118. data/spec/{asciidoctor → metanorma}/base_spec.rb +499 -407
  119. data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
  120. data/spec/{asciidoctor → metanorma}/blocks_spec.rb +1 -1
  121. data/spec/{asciidoctor → metanorma}/cleanup_blocks_spec.rb +1 -1
  122. data/spec/{asciidoctor → metanorma}/cleanup_sections_spec.rb +1 -1
  123. data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +5 -5
  124. data/spec/{asciidoctor → metanorma}/cleanup_terms_spec.rb +227 -119
  125. data/spec/{asciidoctor → metanorma}/datamodel/attributes_table_preprocessor_spec.rb +1 -1
  126. data/spec/{asciidoctor → metanorma}/datamodel/diagram_preprocessor_spec.rb +1 -1
  127. data/spec/{asciidoctor → metanorma}/inline_spec.rb +170 -1
  128. data/spec/{asciidoctor → metanorma}/isobib_cache_spec.rb +1 -1
  129. data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
  130. data/spec/{asciidoctor → metanorma}/macros_json2text_spec.rb +0 -0
  131. data/spec/{asciidoctor → metanorma}/macros_plantuml_spec.rb +3 -3
  132. data/spec/{asciidoctor → metanorma}/macros_spec.rb +97 -6
  133. data/spec/{asciidoctor → metanorma}/macros_yaml2text_spec.rb +0 -0
  134. data/spec/metanorma/refs_dl_spec.rb +863 -0
  135. data/spec/{asciidoctor → metanorma}/refs_spec.rb +522 -15
  136. data/spec/{asciidoctor → metanorma}/section_spec.rb +59 -1
  137. data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
  138. data/spec/{asciidoctor → metanorma}/validate_spec.rb +2 -2
  139. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +46 -46
  140. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  141. data/spec/vcr_cassettes/hide_refs.yml +599 -0
  142. data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
  143. data/spec/vcr_cassettes/isobib_get_123_1.yml +24 -24
  144. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +35 -35
  145. data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
  146. data/spec/vcr_cassettes/isobib_get_124.yml +10 -10
  147. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +18 -18
  148. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  149. metadata +88 -32
  150. data/spec/asciidoctor/refs_dl_spec.rb +0 -864
@@ -0,0 +1,192 @@
1
+ require "date"
2
+ require "nokogiri"
3
+ require "htmlentities"
4
+ require "pathname"
5
+ require "csv"
6
+
7
+ module Metanorma
8
+ module Standoc
9
+ module Front
10
+ def committee_component(compname, node, out)
11
+ out.send compname.gsub(/-/, "_"), node.attr(compname),
12
+ **attr_code(number: node.attr("#{compname}-number"),
13
+ type: node.attr("#{compname}-type"))
14
+ i = 2
15
+ while node.attr(compname + "_#{i}")
16
+ out.send compname.gsub(/-/, "_"), node.attr(compname + "_#{i}"),
17
+ **attr_code(number: node.attr("#{compname}-number_#{i}"),
18
+ type: node.attr("#{compname}-type_#{i}"))
19
+ i += 1
20
+ end
21
+ end
22
+
23
+ def organization(org, orgname, is_pub, node = nil, default_org = nil)
24
+ abbrevs = org_abbrev
25
+ n = abbrevs.invert[orgname] and orgname = n
26
+ org.name orgname
27
+ default_org and a = node.attr("subdivision") and org.subdivision a
28
+ abbr = org_abbrev[orgname]
29
+ default_org && b = node.attr("subdivision-abbr") and abbr = b
30
+ abbr and org.abbreviation abbr
31
+ is_pub && node and org_address(node, org)
32
+ end
33
+
34
+ def org_address(node, person)
35
+ node.attr("pub-address") and person.address do |ad|
36
+ ad.formattedAddress do |f|
37
+ f << node.attr("pub-address").gsub(/ \+\n/, "<br/>")
38
+ end
39
+ end
40
+ node.attr("pub-phone") and person.phone node.attr("pub-phone")
41
+ node.attr("pub-fax") and
42
+ person.phone node.attr("pub-fax"), **{ type: "fax" }
43
+ node.attr("pub-email") and person.email node.attr("pub-email")
44
+ node.attr("pub-uri") and person.uri node.attr("pub-uri")
45
+ end
46
+
47
+ # , " => ," : CSV definition does not deal with space followed by quote
48
+ # at start of field
49
+ def csv_split(text, delim = ";")
50
+ return if text.nil?
51
+
52
+ CSV.parse_line(text&.gsub(/#{delim} "(?!")/, "#{delim}\""),
53
+ liberal_parsing: true,
54
+ col_sep: delim)&.compact&.map(&:strip)
55
+ end
56
+
57
+ def metadata_author(node, xml)
58
+ csv_split(node.attr("publisher") || default_publisher || "")
59
+ &.each do |p|
60
+ xml.contributor do |c|
61
+ c.role **{ type: "author" }
62
+ c.organization do |a|
63
+ organization(a, p, false, node, !node.attr("publisher"))
64
+ end
65
+ end
66
+ end
67
+ personal_author(node, xml)
68
+ end
69
+
70
+ def personal_author(node, xml)
71
+ (node.attr("fullname") || node.attr("surname")) and
72
+ personal_author1(node, xml, "")
73
+ i = 2
74
+ while node.attr("fullname_#{i}") || node.attr("surname_#{i}")
75
+ personal_author1(node, xml, "_#{i}")
76
+ i += 1
77
+ end
78
+ end
79
+
80
+ def personal_role(node, contrib, suffix)
81
+ type = node.attr("role#{suffix}")&.downcase || "author"
82
+ contrib.role **{ type: type }
83
+ end
84
+
85
+ def personal_contact(node, suffix, person)
86
+ node.attr("phone#{suffix}") and person.phone node.attr("phone#{suffix}")
87
+ node.attr("fax#{suffix}") and
88
+ person.phone node.attr("fax#{suffix}"), **{ type: "fax" }
89
+ node.attr("email#{suffix}") and person.email node.attr("email#{suffix}")
90
+ node.attr("contributor-uri#{suffix}") and
91
+ person.uri node.attr("contributor-uri#{suffix}")
92
+ end
93
+
94
+ def personal_author1(node, xml, suffix)
95
+ xml.contributor do |c|
96
+ personal_role(node, c, suffix)
97
+ c.person do |p|
98
+ person_name(node, xml, suffix, p)
99
+ person_affiliation(node, xml, suffix, p)
100
+ personal_contact(node, suffix, p)
101
+ end
102
+ end
103
+ end
104
+
105
+ def person_name(node, _xml, suffix, person)
106
+ person.name do |n|
107
+ if node.attr("fullname#{suffix}")
108
+ n.completename node.attr("fullname#{suffix}")
109
+ else
110
+ n.forename node.attr("givenname#{suffix}")
111
+ n.initial node.attr("initials#{suffix}")
112
+ n.surname node.attr("surname#{suffix}")
113
+ end
114
+ end
115
+ end
116
+
117
+ def person_affiliation(node, _xml, suffix, person)
118
+ node.attr("affiliation#{suffix}") and person.affiliation do |a|
119
+ a.organization do |o|
120
+ person_organization(node, suffix, o)
121
+ end
122
+ end
123
+ end
124
+
125
+ def person_organization(node, suffix, xml)
126
+ xml.name node.attr("affiliation#{suffix}")
127
+ abbr = node.attr("affiliation_abbrev#{suffix}") and
128
+ xml.abbreviation abbr
129
+ csv_split(node.attr("affiliation_subdiv#{suffix}"))&.each do |s|
130
+ xml.subdivision s
131
+ end
132
+ person_address(node, suffix, xml)
133
+ end
134
+
135
+ def person_address(node, suffix, xml)
136
+ if node.attr("address#{suffix}")
137
+ xml.address do |ad|
138
+ ad.formattedAddress do |f|
139
+ f << node.attr("address#{suffix}").gsub(/ \+\n/, "<br/>")
140
+ end
141
+ end
142
+ elsif node.attr("country#{suffix}") || node.attr("city#{suffix}")
143
+ person_address_components(node, suffix, xml)
144
+ end
145
+ end
146
+
147
+ def person_address_components(node, suffix, xml)
148
+ xml.address do |ad|
149
+ s = node.attr("street#{suffix}") and ad.street s
150
+ s = node.attr("city#{suffix}") and ad.city s
151
+ s = node.attr("state#{suffix}") and ad.state s
152
+ s = node.attr("country#{suffix}") and ad.country s
153
+ s = node.attr("postcode#{suffix}") and ad.postcode s
154
+ end
155
+ end
156
+
157
+ def default_publisher
158
+ nil
159
+ end
160
+
161
+ def org_abbrev
162
+ {}
163
+ end
164
+
165
+ def metadata_publisher(node, xml)
166
+ publishers = node.attr("publisher") || default_publisher || return
167
+ csv_split(publishers)&.each do |p|
168
+ xml.contributor do |c|
169
+ c.role **{ type: "publisher" }
170
+ c.organization do |a|
171
+ organization(a, p, true, node, !node.attr("publisher"))
172
+ end
173
+ end
174
+ end
175
+ end
176
+
177
+ def metadata_copyright(node, xml)
178
+ pub = node.attr("copyright-holder") || node.attr("publisher")
179
+ csv_split(pub || default_publisher || "-")&.each do |p|
180
+ xml.copyright do |c|
181
+ c.from (node.attr("copyright-year") || Date.today.year)
182
+ p.match(/[A-Za-z]/).nil? or c.owner do |owner|
183
+ owner.organization do |a|
184
+ organization(a, p, true, node, !pub)
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,232 @@
1
+ require "asciidoctor/extensions"
2
+ require "htmlentities"
3
+ require "unicode2latex"
4
+ require "mime/types"
5
+ require "base64"
6
+ require "English"
7
+ require "latexmath"
8
+
9
+ module Metanorma
10
+ module Standoc
11
+ module Inline
12
+ def refid?(ref)
13
+ @refids.include? ref
14
+ end
15
+
16
+ def inline_anchor(node)
17
+ case node.type
18
+ when :ref then inline_anchor_ref node
19
+ when :xref then inline_anchor_xref node
20
+ when :link then inline_anchor_link node
21
+ when :bibref then inline_anchor_bibref node
22
+ end
23
+ end
24
+
25
+ def inline_anchor_ref(node)
26
+ noko do |xml|
27
+ xml.bookmark nil, **attr_code(id: node.id)
28
+ end.join
29
+ end
30
+
31
+ def inline_anchor_xref(node)
32
+ noko do |xml|
33
+ attrs = inline_anchor_xref_attrs(node)
34
+ c = attrs[:text]
35
+ attrs.delete(:text) unless c.nil?
36
+ xml.xref **attr_code(attrs) do |x|
37
+ x << c
38
+ end
39
+ end.join
40
+ end
41
+
42
+ def inline_anchor_xref_attrs(node)
43
+ m = /^(?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
44
+ (?<fn>fn:?\s*)?(?<text>.*)$/x.match node.text
45
+ t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
46
+ m.nil? and return { target: t, type: "inline", text: node.text }
47
+ droploc = m[:drop].nil? && m[:drop2].nil? ? nil : true
48
+ f = m[:fn].nil? ? "inline" : "footnote"
49
+ c = if %i[case fn drop drop2].any? do |x|
50
+ !m[x].nil?
51
+ end
52
+ m[:text]
53
+ else node.text
54
+ end
55
+ { target: t, type: f, case: m[:case]&.sub(/%$/, ""), droploc: droploc,
56
+ text: c }
57
+ end
58
+
59
+ def inline_anchor_link(node)
60
+ contents = node.text
61
+ contents = "" if node.target.gsub(%r{^mailto:}, "") == node.text
62
+ attributes = { target: node.target, alt: node.attr("title"),
63
+ "update-type": node.attr("updatetype") ||
64
+ node.attr("update-type") }
65
+ noko do |xml|
66
+ xml.link **attr_code(attributes) do |l|
67
+ l << contents
68
+ end
69
+ end.join
70
+ end
71
+
72
+ def inline_anchor_bibref(node)
73
+ eref_contents = (node.text || node.target || node.id)
74
+ &.sub(/^\[?([^\[\]]+?)\]?$/, "[\\1]")
75
+ eref_attributes = { id: node.target || node.id }
76
+ @refids << (node.target || node.id)
77
+ noko do |xml|
78
+ xml.ref **attr_code(eref_attributes) do |r|
79
+ r << eref_contents
80
+ end
81
+ end.join
82
+ end
83
+
84
+ def inline_callout(node)
85
+ noko do |xml|
86
+ xml.callout node.text
87
+ end.join
88
+ end
89
+
90
+ def inline_footnote(node)
91
+ @fn_number ||= 0
92
+ noko do |xml|
93
+ @fn_number += 1
94
+ xml.fn **{ reference: @fn_number } do |fn|
95
+ fn.p { |p| p << node.text }
96
+ end
97
+ end.join
98
+ end
99
+
100
+ def inline_break(node)
101
+ noko do |xml|
102
+ xml << node.text
103
+ xml.br
104
+ end.join
105
+ end
106
+
107
+ def page_break(node)
108
+ attrs = {}
109
+ node.option?("landscape") and attrs[:orientation] = "landscape"
110
+ node.option?("portrait") and attrs[:orientation] = "portrait"
111
+ noko { |xml| xml.pagebreak **attr_code(attrs) }.join
112
+ end
113
+
114
+ def thematic_break(_node)
115
+ noko { |xml| xml.hr }.join
116
+ end
117
+
118
+ def xml_encode(text)
119
+ HTMLEntities.new.encode(text, :basic, :hexadecimal)
120
+ .gsub(/&amp;gt;/, ">").gsub(/&amp;lt;/, "<").gsub(/&amp;amp;/, "&")
121
+ .gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&")
122
+ .gsub(/&quot;/, '"').gsub(/&#xa;/, "\n").gsub(/&amp;#/, "&#")
123
+ end
124
+
125
+ def latex_parse1(text)
126
+ lxm_input = Unicode2LaTeX.unicode2latex(HTMLEntities.new.decode(text))
127
+ results = Latexmath.parse(lxm_input).to_mathml
128
+ results.nil? and
129
+ @log.add("Math", nil,
130
+ "latexmlmath failed to process equation:\n#{lxm_input}")
131
+ results&.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
132
+ end
133
+
134
+ def stem_parse(text, xml, style)
135
+ if /&lt;([^:>&]+:)?math(\s+[^>&]+)?&gt; |
136
+ <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
137
+ math = xml_encode(text)
138
+ xml.stem math, **{ type: "MathML" }
139
+ elsif style == :latexmath then latex_parse(text, xml)
140
+ else
141
+ xml.stem text&.gsub(/&amp;#/, "&#"), **{ type: "AsciiMath" }
142
+ end
143
+ end
144
+
145
+ def latex_parse(text, xml)
146
+ latex = latex_parse1(text) or return xml.stem **{ type: "MathML" }
147
+ xml.stem **{ type: "MathML" } do |s|
148
+ math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, ""))
149
+ .elements[0]
150
+ math.delete("alttext")
151
+ s.parent.children = math
152
+ end
153
+ end
154
+
155
+ def highlight_parse(text, xml)
156
+ xml << text
157
+ end
158
+
159
+ def inline_quoted(node)
160
+ noko do |xml|
161
+ case node.type
162
+ when :emphasis then xml.em { |s| s << node.text }
163
+ when :strong then xml.strong { |s| s << node.text }
164
+ when :monospaced then xml.tt { |s| s << node.text }
165
+ when :double then xml << "\"#{node.text}\""
166
+ when :single then xml << "'#{node.text}'"
167
+ when :superscript then xml.sup { |s| s << node.text }
168
+ when :subscript then xml.sub { |s| s << node.text }
169
+ when :asciimath then stem_parse(node.text, xml, :asciimath)
170
+ when :latexmath then stem_parse(node.text, xml, :latexmath)
171
+ when :mark then highlight_parse(node.text, xml)
172
+ else
173
+ case node.role
174
+ # the following three are legacy, they are now handled by macros
175
+ when "alt"
176
+ term_designation(xml, node, "admitted", node.text)
177
+ when "deprecated"
178
+ term_designation(xml, node, "deprecates", node.text)
179
+ when "domain" then xml.domain { |a| a << node.text }
180
+
181
+ when "strike" then xml.strike { |s| s << node.text }
182
+ when "underline" then xml.underline { |s| s << node.text }
183
+ when "smallcap" then xml.smallcap { |s| s << node.text }
184
+ when "keyword" then xml.keyword { |s| s << node.text }
185
+ else
186
+ xml << node.text
187
+ end
188
+ end
189
+ end.join
190
+ end
191
+
192
+ def image_attributes(node)
193
+ uri = node.image_uri (node.attr("target") || node.target)
194
+ types = if /^data:/.match?(uri) then Metanorma::Utils::datauri2mime(uri)
195
+ else MIME::Types.type_for(uri)
196
+ end
197
+ type = types.first.to_s
198
+ uri = uri.sub(%r{^data:image/\*;}, "data:#{type};")
199
+ image_attributes1(node, uri, type)
200
+ end
201
+
202
+ def image_attributes1(node, uri, type)
203
+ attr_code(src: uri,
204
+ id: Metanorma::Utils::anchor_or_uuid,
205
+ mimetype: type,
206
+ height: node.attr("height") || "auto",
207
+ width: node.attr("width") || "auto",
208
+ filename: node.attr("filename"),
209
+ title: node.attr("titleattr"),
210
+ alt: node.alt == node.attr("default-alt") ? nil : node.alt)
211
+ end
212
+
213
+ def inline_image(node)
214
+ noko do |xml|
215
+ xml.image **image_attributes(node)
216
+ end.join
217
+ end
218
+
219
+ def inline_indexterm(node)
220
+ noko do |xml|
221
+ node.type == :visible and xml << node.text
222
+ terms = (node.attr("terms") || [node.text]).map { |x| xml_encode(x) }
223
+ xml.index do |i|
224
+ i.primary { |x| x << terms[0] }
225
+ a = terms[1] and i.secondary { |x| x << a }
226
+ a = terms[2] and i.tertiary { |x| x << a }
227
+ end
228
+ end.join
229
+ end
230
+ end
231
+ end
232
+ end
@@ -32,6 +32,56 @@
32
32
  <ref name="DocumentType"/>
33
33
  </element>
34
34
  </define>
35
+ <define name="index">
36
+ <element name="index">
37
+ <optional>
38
+ <attribute name="to">
39
+ <data type="IDREF"/>
40
+ </attribute>
41
+ </optional>
42
+ <element name="primary">
43
+ <oneOrMore>
44
+ <choice>
45
+ <ref name="PureTextElement"/>
46
+ <ref name="stem"/>
47
+ </choice>
48
+ </oneOrMore>
49
+ </element>
50
+ <optional>
51
+ <element name="secondary">
52
+ <oneOrMore>
53
+ <choice>
54
+ <ref name="PureTextElement"/>
55
+ <ref name="stem"/>
56
+ </choice>
57
+ </oneOrMore>
58
+ </element>
59
+ </optional>
60
+ <optional>
61
+ <element name="tertiary">
62
+ <oneOrMore>
63
+ <choice>
64
+ <ref name="PureTextElement"/>
65
+ <ref name="stem"/>
66
+ </choice>
67
+ </oneOrMore>
68
+ </element>
69
+ </optional>
70
+ </element>
71
+ </define>
72
+ <define name="bibitem">
73
+ <element name="bibitem">
74
+ <attribute name="id">
75
+ <data type="ID"/>
76
+ </attribute>
77
+ <optional>
78
+ <attribute name="hidden">
79
+ <data type="boolean"/>
80
+ </attribute>
81
+ </optional>
82
+ <ref name="BibliographicItem"/>
83
+ </element>
84
+ </define>
35
85
  <define name="section-title">
36
86
  <element name="title">
37
87
  <zeroOrMore>
@@ -690,6 +740,7 @@
690
740
  <ref name="terms"/>
691
741
  <ref name="term-clause"/>
692
742
  <ref name="definitions"/>
743
+ <ref name="floating-title"/>
693
744
  </choice>
694
745
  </oneOrMore>
695
746
  </element>
@@ -1013,6 +1064,26 @@
1013
1064
  </zeroOrMore>
1014
1065
  </element>
1015
1066
  </define>
1067
+ <define name="sub">
1068
+ <element name="sub">
1069
+ <zeroOrMore>
1070
+ <choice>
1071
+ <ref name="PureTextElement"/>
1072
+ <ref name="stem"/>
1073
+ </choice>
1074
+ </zeroOrMore>
1075
+ </element>
1076
+ </define>
1077
+ <define name="sup">
1078
+ <element name="sup">
1079
+ <zeroOrMore>
1080
+ <choice>
1081
+ <ref name="PureTextElement"/>
1082
+ <ref name="stem"/>
1083
+ </choice>
1084
+ </zeroOrMore>
1085
+ </element>
1086
+ </define>
1016
1087
  <define name="pagebreak">
1017
1088
  <element name="pagebreak">
1018
1089
  <optional>
@@ -1680,6 +1751,7 @@
1680
1751
  <ref name="clause-subsection"/>
1681
1752
  <ref name="terms"/>
1682
1753
  <ref name="definitions"/>
1754
+ <ref name="floating-title"/>
1683
1755
  </choice>
1684
1756
  </oneOrMore>
1685
1757
  </choice>
@@ -1722,6 +1794,7 @@
1722
1794
  <ref name="terms"/>
1723
1795
  <ref name="definitions"/>
1724
1796
  <ref name="references"/>
1797
+ <ref name="floating-title"/>
1725
1798
  </choice>
1726
1799
  </zeroOrMore>
1727
1800
  </group>
@@ -1973,7 +2046,11 @@
1973
2046
  </optional>
1974
2047
  <element name="name">
1975
2048
  <zeroOrMore>
1976
- <ref name="PureTextElement"/>
2049
+ <choice>
2050
+ <ref name="PureTextElement"/>
2051
+ <ref name="stem"/>
2052
+ <ref name="index"/>
2053
+ </choice>
1977
2054
  </zeroOrMore>
1978
2055
  </element>
1979
2056
  <optional>
@@ -1987,7 +2064,7 @@
1987
2064
  </element>
1988
2065
  </optional>
1989
2066
  <optional>
1990
- <element name="grammar-info">
2067
+ <element name="grammar">
1991
2068
  <ref name="Grammar"/>
1992
2069
  </element>
1993
2070
  </optional>
@@ -2196,7 +2273,18 @@
2196
2273
  <ref name="MultilingualRenderingType"/>
2197
2274
  </attribute>
2198
2275
  </optional>
2199
- <ref name="paragraph"/>
2276
+ <oneOrMore>
2277
+ <choice>
2278
+ <ref name="formula"/>
2279
+ <ref name="ul"/>
2280
+ <ref name="ol"/>
2281
+ <ref name="dl"/>
2282
+ <ref name="quote"/>
2283
+ <ref name="sourcecode"/>
2284
+ <ref name="paragraph"/>
2285
+ <ref name="figure"/>
2286
+ </choice>
2287
+ </oneOrMore>
2200
2288
  </element>
2201
2289
  </define>
2202
2290
  <define name="termsource">
@@ -2530,4 +2618,17 @@
2530
2618
  </oneOrMore>
2531
2619
  </element>
2532
2620
  </define>
2621
+ <define name="floating-title">
2622
+ <element name="floating-title">
2623
+ <attribute name="id">
2624
+ <data type="ID"/>
2625
+ </attribute>
2626
+ <attribute name="depth">
2627
+ <data type="int"/>
2628
+ </attribute>
2629
+ <zeroOrMore>
2630
+ <ref name="TextElement"/>
2631
+ </zeroOrMore>
2632
+ </element>
2633
+ </define>
2533
2634
  </grammar>