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
@@ -1,48 +1,3 @@
1
- module Asciidoctor
2
- module Standoc
3
- module Cleanup
4
- # Indices sort after letter but before any following
5
- # letter (x, x_m, x_1, xa); we use colon to force that sort order.
6
- # Numbers sort *after* letters; we use thorn to force that sort order.
7
- def symbol_key(sym)
8
- key = sym.dup
9
- key.traverse do |n|
10
- n.name == "math" and
11
- n.replace(grkletters(MathML2AsciiMath.m2a(n.to_xml)))
12
- end
13
- ret = Nokogiri::XML(key.to_xml)
14
- HTMLEntities.new.decode(ret.text.downcase)
15
- .gsub(/[\[\]{}<>()]/, "").gsub(/\s/m, "")
16
- .gsub(/[[:punct:]]|[_^]/, ":\\0").gsub(/`/, "")
17
- .gsub(/[0-9]+/, "þ\\0")
18
- end
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/cleanup_symbols"
19
3
 
20
- def grkletters(text)
21
- text.gsub(/\b(alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|
22
- lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|
23
- psi|omega)\b/xi, "&\\1;")
24
- end
25
-
26
- def extract_symbols_list(dlist)
27
- dl_out = []
28
- dlist.xpath("./dt | ./dd").each do |dtd|
29
- if dtd.name == "dt"
30
- dl_out << { dt: dtd.remove, key: symbol_key(dtd) }
31
- else
32
- dl_out.last[:dd] = dtd.remove
33
- end
34
- end
35
- dl_out
36
- end
37
-
38
- def symbols_cleanup(docxml)
39
- docxml.xpath("//definitions/dl").each do |dl|
40
- dl_out = extract_symbols_list(dl)
41
- dl_out.sort! { |a, b| a[:key] <=> b[:key] || a[:dt] <=> b[:dt] }
42
- dl.children = dl_out.map { |d| d[:dt].to_s + d[:dd].to_s }.join("\n")
43
- end
44
- docxml
45
- end
46
- end
47
- end
48
- end
@@ -1,68 +1,3 @@
1
- module Asciidoctor
2
- module Standoc
3
- module Cleanup
4
- def dl1_table_cleanup(xmldoc)
5
- q = "//table/following-sibling::*[1][self::dl]"
6
- xmldoc.xpath(q).each do |s|
7
- s["key"] == "true" and s.previous_element << s.remove
8
- end
9
- end
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/cleanup_table"
10
3
 
11
- # move Key dl after table footer
12
- def dl2_table_cleanup(xmldoc)
13
- q = "//table/following-sibling::*[1][self::p]"
14
- xmldoc.xpath(q).each do |s|
15
- if s.text =~ /^\s*key[^a-z]*$/i && s&.next_element&.name == "dl"
16
- s.next_element["key"] = "true"
17
- s.previous_element << s.next_element.remove
18
- s.remove
19
- end
20
- end
21
- end
22
-
23
- def insert_thead(table)
24
- thead = table.at("./thead")
25
- return thead unless thead.nil?
26
-
27
- if tname = table.at("./name")
28
- thead = tname.add_next_sibling("<thead/>").first
29
- return thead
30
- end
31
- table.children.first.add_previous_sibling("<thead/>").first
32
- end
33
-
34
- def header_rows_cleanup(xmldoc)
35
- xmldoc.xpath("//table[@headerrows]").each do |s|
36
- thead = insert_thead(s)
37
- (thead.xpath("./tr").size...s["headerrows"].to_i).each do
38
- row = s.at("./tbody/tr")
39
- row.parent = thead
40
- end
41
- thead.xpath(".//td").each { |n| n.name = "th" }
42
- s.delete("headerrows")
43
- end
44
- end
45
-
46
- def table_cleanup(xmldoc)
47
- dl1_table_cleanup(xmldoc)
48
- dl2_table_cleanup(xmldoc)
49
- notes_table_cleanup(xmldoc)
50
- header_rows_cleanup(xmldoc)
51
- end
52
-
53
- # move notes into table
54
- def notes_table_cleanup(xmldoc)
55
- nomatches = false
56
- until nomatches
57
- nomatches = true
58
- xmldoc.xpath("//table/following-sibling::*[1]"\
59
- "[self::note[not(@keep-separate = 'true')]]").each do |n|
60
- n.delete("keep-separate")
61
- n.previous_element << n.remove
62
- nomatches = false
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,140 +1,3 @@
1
- require_relative "term_lookup_cleanup"
2
- require_relative "cleanup_terms_designations"
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/cleanup_terms"
3
3
 
4
- module Asciidoctor
5
- module Standoc
6
- module Cleanup
7
- def termdomain_cleanup(xmldoc)
8
- xmldoc.xpath("//p/domain").each do |a|
9
- parent = a.parent
10
- prev = parent.previous
11
- prev.next = a.remove
12
- parent.text.strip.empty? and parent.remove
13
- end
14
- end
15
-
16
- def termdomain1_cleanup(xmldoc)
17
- xmldoc.xpath("//term").each do |t|
18
- d = t.xpath("./domain | ./subject").last or next
19
- defn = d.at("../definition") and defn.previous = d.remove
20
- end
21
- end
22
-
23
- def termdefinition_cleanup(xmldoc)
24
- generate_termdefinitions(xmldoc)
25
- split_termdefinitions(xmldoc)
26
- alternate_termdefinitions(xmldoc)
27
- end
28
-
29
- TERMDEF_BLOCKS =
30
- "./p | ./ol | ./dl[not(@metadata = 'true')] | ./ul | ./figure | "\
31
- "./formula | ./table".freeze
32
-
33
- def generate_termdefinitions(xmldoc)
34
- xmldoc.xpath("//term[not(definition)]").each do |d|
35
- first_child = d.at(TERMDEF_BLOCKS) || next
36
- t = Nokogiri::XML::Element.new("definition", xmldoc)
37
- first_child.replace(t)
38
- t << first_child.remove
39
- d.xpath(TERMDEF_BLOCKS).each do |n|
40
- t << n.remove
41
- end
42
- end
43
- end
44
-
45
- def split_termdefinitions(xmldoc)
46
- xmldoc.xpath("//definition").each do |d|
47
- if d.at("./p | ./ol | ./dl | ./ul")
48
- d.children = "<verbal-definition>#{d.children}</verbal-definition>"
49
- else
50
- d.children = "<non-verbal-representation>"\
51
- "#{d.children}</non-verbal-representation>"
52
- end
53
- end
54
- end
55
-
56
- def alternate_termdefinitions(xmldoc)
57
- xmldoc.xpath("//term").each do |t|
58
- t.xpath("./definition").each do |d|
59
- d1 = d.next_element or next
60
- if (v = d.at("./verbal-definition")) &&
61
- !d.at("./non-verbal-representation") &&
62
- !d1.at("./verbal-definition") &&
63
- nv = d1.at("./non-verbal-representation")
64
- v.next = nv.remove
65
- d1.remove
66
- end
67
- end
68
- end
69
- end
70
-
71
- def termdocsource_cleanup(xmldoc)
72
- f = xmldoc.at("//preface | //sections")
73
- xmldoc.xpath("//termdocsource").each { |s| f.previous = s.remove }
74
- end
75
-
76
- def term_children_cleanup(xmldoc)
77
- xmldoc.xpath("//terms[terms]").each { |t| t.name = "clause" }
78
- xmldoc.xpath("//term").each do |t|
79
- %w(termnote termexample termsource term).each do |w|
80
- t.xpath("./#{w}").each { |n| t << n.remove }
81
- end
82
- end
83
- end
84
-
85
- def termdef_from_termbase(xmldoc)
86
- xmldoc.xpath("//term").each do |x|
87
- if (c = x.at("./origin/termref")) && !x.at("./definition")
88
- x.at("./origin").previous = fetch_termbase(c["base"], c.text)
89
- end
90
- end
91
- end
92
-
93
- def termnote_example_cleanup(xmldoc)
94
- %w(note example).each do |w|
95
- xmldoc.xpath("//term#{w}[not(ancestor::term)]").each do |x|
96
- x.name = w
97
- end
98
- end
99
- end
100
-
101
- def termdef_cleanup(xmldoc)
102
- termdef_unnest_cleanup(xmldoc)
103
- Asciidoctor::Standoc::TermLookupCleanup.new(xmldoc, @log).call
104
- term_nonverbal_designations(xmldoc)
105
- term_dl_to_metadata(xmldoc)
106
- term_termsource_to_designation(xmldoc)
107
- term_designation_reorder(xmldoc)
108
- termdef_from_termbase(xmldoc)
109
- termdomain_cleanup(xmldoc)
110
- termdef_stem_cleanup(xmldoc)
111
- termdefinition_cleanup(xmldoc)
112
- termdomain1_cleanup(xmldoc)
113
- termnote_example_cleanup(xmldoc)
114
- term_children_cleanup(xmldoc)
115
- termdocsource_cleanup(xmldoc)
116
- end
117
-
118
- def index_cleanup(xmldoc)
119
- return unless @index_terms
120
-
121
- xmldoc.xpath("//preferred").each do |p|
122
- index_cleanup1(p.at("./expression/name | ./letter-symbol/name"),
123
- p.xpath("./field-of-application | ./usage-info")
124
- &.map(&:text)&.join(", "))
125
- end
126
- xmldoc.xpath("//definitions/dl/dt").each do |p|
127
- index_cleanup1(p, "")
128
- end
129
- end
130
-
131
- def index_cleanup1(term, fieldofappl)
132
- return unless term
133
-
134
- idx = term.children.dup
135
- fieldofappl.empty? or idx << ", &#x3c;#{fieldofappl}&#x3e;"
136
- term << "<index><primary>#{idx.to_xml}</primary></index>"
137
- end
138
- end
139
- end
140
- end
@@ -1,193 +1,3 @@
1
- module Asciidoctor
2
- module Standoc
3
- module Cleanup
4
- def termdef_stem_cleanup(xmldoc)
5
- xmldoc.xpath("//term/p/stem").each do |a|
6
- if initial_formula(a.parent)
7
- parent = a.parent
8
- parent.replace("<admitted>#{term_expr(a.to_xml)}</admitted>")
9
- end
10
- end
11
- xmldoc.xpath("//term/formula").each do |a|
12
- if initial_formula(a)
13
- a.replace("<admitted>#{term_expr(a.children.to_xml)}</admitted>")
14
- end
15
- end
16
- xmldoc.xpath("//term//expression/name[stem]").each do |n|
17
- n.parent.name = "letter-symbol"
18
- end
19
- end
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/cleanup_terms_designations"
20
3
 
21
- def initial_formula(elem)
22
- elem.elements.size == 1 && # para contains just stem expression
23
- !elem.at("./preceding-sibling::p | ./preceding-sibling::dl | "\
24
- "./preceding-sibling::ol | ./preceding-sibling::ul")
25
- end
26
-
27
- # release termdef tags from surrounding paras
28
- def termdef_unnest_cleanup(xmldoc)
29
- desgn = "//p/admitted | //p/deprecates | //p/preferred | //p//related"
30
- nodes = xmldoc.xpath(desgn)
31
- while !nodes.empty?
32
- nodes[0].parent.replace(nodes[0].parent.children)
33
- nodes = xmldoc.xpath(desgn)
34
- end
35
- end
36
-
37
- def term_dl_to_metadata(xmldoc)
38
- xmldoc.xpath("//term[dl[@metadata = 'true']]").each do |t|
39
- t.xpath("./dl[@metadata = 'true']").each do |dl|
40
- prev = related2pref(dl_to_designation(dl)) or next
41
- #require "debug"; binding.b if prev.parent.name == "related"
42
- term_dl_to_designation_metadata(prev, dl)
43
- term_dl_to_term_metadata(prev, dl)
44
- term_dl_to_expression_metadata(prev, dl)
45
- dl.remove
46
- end
47
- end
48
- end
49
-
50
- def term_dl_to_term_metadata(prev, dlist)
51
- return unless prev.name == "preferred" &&
52
- prev.at("./preceding-sibling::preferred").nil?
53
-
54
- ins = term_element_insert_point(prev)
55
- %w(domain subject).each do |a|
56
- ins = dl_to_elems(ins, prev.parent, dlist, a)
57
- end
58
- end
59
-
60
- def term_dl_to_designation_metadata(prev, dlist)
61
- %w(absent geographic-area).each do |a|
62
- dl_to_attrs(prev, dlist, a)
63
- end
64
- %w(field-of-application usage-info).reverse.each do |a|
65
- dl_to_elems(prev.at("./expression"), prev, dlist, a)
66
- end
67
- end
68
-
69
- def term_element_insert_point(prev)
70
- ins = prev
71
- while %w(preferred admitted deprecates related domain dl)
72
- .include? ins&.next_element&.name
73
- ins = ins.next_element
74
- end
75
- ins
76
- end
77
-
78
- def term_dl_to_expression_metadata(prev, dlist)
79
- term_dl_to_expression_root_metadata(prev, dlist)
80
- term_dl_to_expression_name_metadata(prev, dlist)
81
- term_to_letter_symbol(prev, dlist)
82
- end
83
-
84
- def term_dl_to_expression_root_metadata(prev, dlist)
85
- %w(isInternational).each do |a|
86
- p = prev.at("./expression | ./letter-symbol | ./graphical-symbol")
87
- dl_to_attrs(p, dlist, a)
88
- end
89
- %w(language script type).each do |a|
90
- p = prev.at("./expression") or next
91
- dl_to_attrs(p, dlist, a)
92
- end
93
- end
94
-
95
- def term_dl_to_expression_name_metadata(prev, dlist)
96
- %w(abbreviation-type pronunciation).reverse.each do |a|
97
- dl_to_elems(prev.at("./expression/name"), prev, dlist, a)
98
- end
99
- g = dlist.at("./dt[text()='grammar']/following::dd//dl") and
100
- term_dl_to_expression_grammar(prev, g)
101
- end
102
-
103
- def term_dl_to_expression_grammar(prev, dlist)
104
- prev.at(".//expression") or return
105
- prev.at(".//expression") << "<grammar><sentinel/></grammar>"
106
- %w(gender number isPreposition isParticiple isAdjective isAdverb isNoun
107
- grammar-value).reverse.each do |a|
108
- dl_to_elems(prev.at(".//expression/grammar/*"), prev.elements.last,
109
- dlist, a)
110
- end
111
- term_dl_to_designation_category(prev, "gender")
112
- term_dl_to_designation_category(prev, "number")
113
- prev.at(".//expression/grammar/sentinel").remove
114
- end
115
-
116
- def term_dl_to_designation_category(prev, category)
117
- cat = prev.at(".//expression/grammar/#{category}")
118
- /,/.match?(cat&.text) and
119
- cat.replace(cat.text.split(/,\s*/)
120
- .map { |x| "<#{category}>#{x}</#{category}>" }.join)
121
- end
122
-
123
- def term_to_letter_symbol(prev, dlist)
124
- ls = dlist.at("./dt[text()='letter-symbol']/following::dd/p")
125
- return unless ls&.text == "true"
126
-
127
- prev.at(".//expression").name = "letter-symbol"
128
- end
129
-
130
- def dl_to_designation(dlist)
131
- prev = dlist.previous_element
132
- unless %w(preferred admitted deprecates related).include? prev&.name
133
- @log.add("AsciiDoc Input", dlist, "Metadata definition list does "\
134
- "not follow a term designation")
135
- return nil
136
- end
137
- prev
138
- end
139
-
140
- def term_nonverbal_designations(xmldoc)
141
- xmldoc.xpath("//term/preferred | //term/admitted | //term/deprecates")
142
- .each do |d|
143
- d.text.strip.empty? or next
144
- n = d.next_element
145
- if %w(formula figure).include?(n&.name)
146
- term_nonverbal_designations1(d, n)
147
- else d.at("./expression/name") or
148
- d.children = term_expr("")
149
- end
150
- end
151
- end
152
-
153
- def term_nonverbal_designations1(desgn, elem)
154
- desgn = related2pref(desgn)
155
- if elem.name == "figure"
156
- elem.at("./name").remove
157
- desgn.children =
158
- "<graphical-symbol>#{elem.remove.to_xml}</graphical-symbol>"
159
- else
160
- desgn.children = term_expr(elem.at("./stem").to_xml)
161
- elem.remove
162
- end
163
- end
164
-
165
- def term_termsource_to_designation(xmldoc)
166
- xmldoc.xpath("//term/termsource").each do |t|
167
- p = t.previous_element
168
- while %w(domain subject).include? p&.name
169
- p = p.previous_element
170
- end
171
- %w(preferred admitted deprecates related).include?(p&.name) or
172
- next
173
- related2pref(p) << t.remove
174
- end
175
- end
176
-
177
- def term_designation_reorder(xmldoc)
178
- xmldoc.xpath("//term").each do |t|
179
- %w(preferred admitted deprecates related)
180
- .each_with_object([]) do |tag, m|
181
- t.xpath("./#{tag}").each { |x| m << x.remove }
182
- end.reverse.each do |x|
183
- t.children.first.previous = x
184
- end
185
- end
186
- end
187
-
188
- def related2pref(elem)
189
- elem&.name == "related" ? elem = elem.at("./preferred") : elem
190
- end
191
- end
192
- end
193
- end
@@ -1,96 +1,3 @@
1
- module Asciidoctor
2
- module Standoc
3
- module Cleanup
4
- def textcleanup(result)
5
- text = result.flatten.map { |l| l.sub(/\s*$/, "") } * "\n"
6
- !@keepasciimath and text = asciimath2mathml(text)
7
- text = text.gsub(/\s+<fn /, "<fn ")
8
- text.gsub(%r{<passthrough\s+formats="metanorma">([^<]*)
9
- </passthrough>}mx) { HTMLEntities.new.decode($1) }
10
- end
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/cleanup_text"
11
3
 
12
- IGNORE_DUMBQUOTES =
13
- "//pre | //pre//* | //tt | //tt//* | "\
14
- "//sourcecode | //sourcecode//* | //bibdata//* | //stem | "\
15
- "//stem//* | //figure[@class = 'pseudocode'] | "\
16
- "//figure[@class = 'pseudocode']//*".freeze
17
-
18
- def smartquotes_cleanup(xmldoc)
19
- xmldoc.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
20
- if @smartquotes then smartquotes_cleanup1(xmldoc)
21
- else dumbquote_cleanup(xmldoc)
22
- end
23
- end
24
-
25
- def smartquotes_cleanup1(xmldoc)
26
- uninterrupt_quotes_around_xml(xmldoc)
27
- dumb2smart_quotes(xmldoc)
28
- end
29
-
30
- # "abc<tag/>", def => "abc",<tag/> def
31
- =begin
32
- def uninterrupt_quotes_around_xml(xmldoc)
33
- xmldoc.xpath("//*[following::text()[1]"\
34
- "[starts-with(., '\"') or starts-with(., \"'\")]]")
35
- .each do |x|
36
- next if !x.ancestors("pre, tt, sourcecode, stem, figure").empty?
37
-
38
- uninterrupt_quotes_around_xml1(x)
39
- end
40
- end
41
- =end
42
- =begin
43
- def uninterrupt_quotes_around_xml(xmldoc)
44
- xmldoc.traverse do |n|
45
- next unless n.element? && n&.next&.text? &&
46
- n.ancestors("pre, tt, sourcecode, stem, figure").empty?
47
- next unless /^['"]/.match?(n.next.text)
48
-
49
- uninterrupt_quotes_around_xml1(n)
50
- end
51
- end
52
- =end
53
- def uninterrupt_quotes_around_xml(xmldoc)
54
- xmldoc.traverse do |n|
55
- next unless n.text? && n&.previous&.element?
56
- next unless /^['"]/.match?(n.text)
57
- next unless n.previous.ancestors("pre, tt, sourcecode, stem, figure")
58
- .empty?
59
-
60
- uninterrupt_quotes_around_xml1(n.previous)
61
- end
62
- end
63
-
64
- def uninterrupt_quotes_around_xml1(elem)
65
- prev = elem.at(".//preceding::text()[1]") or return
66
- /\S$/.match?(prev.text) or return
67
- foll = elem.at(".//following::text()[1]")
68
- m = /^(["'][[:punct:]]*)(\s|$)/
69
- .match(HTMLEntities.new.decode(foll&.text)) or return
70
- foll.content = foll.text.sub(/^(["'][[:punct:]]*)/, "")
71
- prev.content = "#{prev.text}#{m[1]}"
72
- end
73
-
74
- def dumb2smart_quotes(xmldoc)
75
- (xmldoc.xpath("//*[child::text()]") - xmldoc.xpath(IGNORE_DUMBQUOTES))
76
- .each do |x|
77
- x.children.each do |n|
78
- next unless n.text?
79
-
80
- /[-'"(<>]|\.\.|\dx/.match(n) or next
81
-
82
- n.replace(Metanorma::Utils::smartformat(n.text))
83
- end
84
- end
85
- end
86
-
87
- def dumbquote_cleanup(xmldoc)
88
- xmldoc.traverse do |n|
89
- next unless n.text?
90
-
91
- n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'")) # .
92
- end
93
- end
94
- end
95
- end
96
- end
@@ -0,0 +1,3 @@
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/cleanup_toc"
3
+
@@ -1,107 +1,3 @@
1
- module Asciidoctor
2
- module Standoc
3
- module Cleanup
4
- # extending localities to cover ISO referencing
5
- LOCALITY_REGEX_STR = <<~REGEXP.freeze
6
- ^((?<locality>section|clause|part|paragraph|chapter|page|
7
- table|annex|figure|example|note|formula|list|time|anchor|
8
- locality:[^ \\t\\n\\r:,;=]+)(\\s+|=)
9
- (?<ref>[^"][^ \\t\\n,:-]*|"[^"]+")
10
- (-(?<to>[^"][^ \\t\\n,:-]*|"[^"]"))?|
11
- (?<locality2>whole|locality:[^ \\t\\n\\r:,;=]+))(?<punct>[,:;]?)\\s*
12
- (?<text>.*)$
13
- REGEXP
14
- LOCALITY_RE = Regexp.new(LOCALITY_REGEX_STR.gsub(/\s/, ""),
15
- Regexp::IGNORECASE | Regexp::MULTILINE)
1
+ require "asciidoctor/standoc/deprecated"
2
+ require "metanorma/standoc/cleanup_xref"
16
3
 
17
- def tq(text)
18
- text.sub(/^"/, "").sub(/"$/, "")
19
- end
20
-
21
- def extract_localities(elem)
22
- f = elem&.children&.first or return
23
- f.text? or return
24
- head = f.remove.text
25
- tail = elem&.children&.remove
26
- extract_localities1(elem, head)
27
- tail and elem << tail
28
- end
29
-
30
- def extract_localities1(elem, text)
31
- b = elem.add_child("<localityStack/>").first if LOCALITY_RE.match text
32
- while (m = LOCALITY_RE.match text)
33
- ref = m[:ref] ? "<referenceFrom>#{tq m[:ref]}</referenceFrom>" : ""
34
- refto = m[:to] ? "<referenceTo>#{tq m[:to]}</referenceTo>" : ""
35
- b.add_child("<locality type='#{locality_label(m)}'>#{ref}#{refto}"\
36
- "</locality>")
37
- text = m[:text]
38
- b = elem.add_child("<localityStack/>").first if m[:punct] == ";"
39
- end
40
- elem.add_child(text) if text
41
- end
42
-
43
- def locality_label(match)
44
- loc = match[:locality] || match[:locality2]
45
- /^locality:/.match?(loc) ? loc : loc&.downcase
46
- end
47
-
48
- def xref_to_eref(elem)
49
- elem["bibitemid"] = elem["target"]
50
- unless elem["citeas"] = @anchors&.dig(elem["target"], :xref)
51
- @internal_eref_namespaces.include?(elem["type"]) or
52
- @log.add("Crossreferences", elem,
53
- "#{elem['target']} does not have a corresponding "\
54
- "anchor ID in the bibliography!")
55
- end
56
- elem.delete("target")
57
- extract_localities(elem) unless elem.children.empty?
58
- end
59
-
60
- def xref_cleanup(xmldoc)
61
- xmldoc.xpath("//xref").each do |x|
62
- /:/.match(x["target"]) and xref_to_internal_eref(x)
63
- next unless x.name == "xref"
64
-
65
- if refid? x["target"]
66
- x.name = "eref"
67
- xref_to_eref(x)
68
- else x.delete("type")
69
- end
70
- end
71
- end
72
-
73
- def xref_to_internal_eref(elem)
74
- a = elem["target"].split(":", 3)
75
- unless a.size < 2 || a[0].empty? || a[1].empty?
76
- elem["target"] = "#{a[0]}_#{a[1]}"
77
- a.size > 2 and
78
- elem.children = %{anchor="#{a[2..-1].join}",#{elem&.children&.text}}
79
- elem["type"] = a[0]
80
- @internal_eref_namespaces << a[0]
81
- elem.name = "eref"
82
- xref_to_eref(elem)
83
- end
84
- end
85
-
86
- def quotesource_cleanup(xmldoc)
87
- xmldoc.xpath("//quote/source | //terms/source").each do |x|
88
- xref_to_eref(x)
89
- end
90
- end
91
-
92
- def origin_cleanup(xmldoc)
93
- xmldoc.xpath("//origin/concept[termref]").each do |x|
94
- t = x.at("./termref")
95
- x.replace(t)
96
- end
97
- xmldoc.xpath("//origin").each do |x|
98
- x["citeas"] = @anchors&.dig(x["bibitemid"], :xref) or
99
- @log.add("Crossreferences", x,
100
- "#{x['bibitemid']} does not have a corresponding anchor "\
101
- "ID in the bibliography!")
102
- extract_localities(x) unless x.children.empty?
103
- end
104
- end
105
- end
106
- end
107
- end