metanorma-standoc 1.11.0 → 1.11.3

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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/lib/asciidoctor/standoc/base.rb +4 -100
  4. data/lib/asciidoctor/standoc/blocks.rb +1 -1
  5. data/lib/asciidoctor/standoc/cleanup.rb +2 -1
  6. data/lib/asciidoctor/standoc/cleanup_block.rb +1 -2
  7. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +28 -20
  8. data/lib/asciidoctor/standoc/cleanup_inline.rb +14 -4
  9. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +25 -15
  10. data/lib/asciidoctor/standoc/cleanup_reqt.rb +3 -3
  11. data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -2
  12. data/lib/asciidoctor/standoc/cleanup_terms.rb +58 -21
  13. data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +50 -19
  14. data/lib/asciidoctor/standoc/cleanup_text.rb +23 -0
  15. data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +6 -6
  16. data/lib/asciidoctor/standoc/front.rb +1 -1
  17. data/lib/asciidoctor/standoc/inline.rb +13 -11
  18. data/lib/asciidoctor/standoc/isodoc.rng +68 -18
  19. data/lib/asciidoctor/standoc/lists.rb +1 -3
  20. data/lib/asciidoctor/standoc/ref.rb +101 -75
  21. data/lib/asciidoctor/standoc/ref_date_id.rb +30 -1
  22. data/lib/asciidoctor/standoc/ref_sect.rb +18 -7
  23. data/lib/asciidoctor/standoc/render.rb +117 -0
  24. data/lib/asciidoctor/standoc/reqt.rb +1 -1
  25. data/lib/asciidoctor/standoc/section.rb +20 -15
  26. data/lib/asciidoctor/standoc/utils.rb +0 -16
  27. data/lib/asciidoctor/standoc/validate.rb +1 -1
  28. data/lib/isodoc/html/htmlstyle.css +1 -1
  29. data/lib/isodoc/html/htmlstyle.scss +1 -1
  30. data/lib/metanorma/standoc/version.rb +1 -1
  31. data/metanorma-standoc.gemspec +3 -3
  32. data/spec/asciidoctor/blocks_spec.rb +99 -17
  33. data/spec/asciidoctor/cleanup_blocks_spec.rb +24 -0
  34. data/spec/asciidoctor/cleanup_sections_spec.rb +1 -1
  35. data/spec/asciidoctor/cleanup_spec.rb +6 -6
  36. data/spec/asciidoctor/cleanup_terms_spec.rb +448 -89
  37. data/spec/asciidoctor/datamodel/attributes_table_preprocessor_spec.rb +21 -21
  38. data/spec/asciidoctor/datamodel/diagram_preprocessor_spec.rb +16 -16
  39. data/spec/asciidoctor/inline_spec.rb +5 -5
  40. data/spec/asciidoctor/isobib_cache_spec.rb +4 -8
  41. data/spec/asciidoctor/macros_spec.rb +2 -2
  42. data/spec/asciidoctor/refs_dl_spec.rb +4 -4
  43. data/spec/asciidoctor/refs_spec.rb +858 -498
  44. data/spec/asciidoctor/section_spec.rb +32 -3
  45. data/spec/spec_helper.rb +2 -2
  46. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +179 -179
  47. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +14 -14
  48. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  49. data/spec/vcr_cassettes/isobib_get_123_1.yml +96 -96
  50. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +108 -108
  51. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
  52. data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
  53. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +18 -18
  54. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  55. metadata +9 -8
@@ -3,16 +3,27 @@ module Asciidoctor
3
3
  module Cleanup
4
4
  def termdef_stem_cleanup(xmldoc)
5
5
  xmldoc.xpath("//term/p/stem").each do |a|
6
- if a.parent.elements.size == 1 # para contains just a stem expression
6
+ if initial_formula(a.parent)
7
7
  parent = a.parent
8
8
  parent.replace("<admitted>#{term_expr(a.to_xml)}</admitted>")
9
9
  end
10
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
11
16
  xmldoc.xpath("//term//expression/name[stem]").each do |n|
12
17
  n.parent.name = "letter-symbol"
13
18
  end
14
19
  end
15
20
 
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
+
16
27
  # release termdef tags from surrounding paras
17
28
  def termdef_unnest_cleanup(xmldoc)
18
29
  desgn = "//p/admitted | //p/deprecates | //p/preferred | //p//related"
@@ -26,7 +37,8 @@ module Asciidoctor
26
37
  def term_dl_to_metadata(xmldoc)
27
38
  xmldoc.xpath("//term[dl[@metadata = 'true']]").each do |t|
28
39
  t.xpath("./dl[@metadata = 'true']").each do |dl|
29
- prev = dl_to_designation(dl) or next
40
+ prev = related2pref(dl_to_designation(dl)) or next
41
+ #require "debug"; binding.b if prev.parent.name == "related"
30
42
  term_dl_to_designation_metadata(prev, dl)
31
43
  term_dl_to_term_metadata(prev, dl)
32
44
  term_dl_to_expression_metadata(prev, dl)
@@ -40,13 +52,18 @@ module Asciidoctor
40
52
  prev.at("./preceding-sibling::preferred").nil?
41
53
 
42
54
  ins = term_element_insert_point(prev)
43
- %w(domain subject usageinfo).each do |a|
55
+ %w(domain subject).each do |a|
44
56
  ins = dl_to_elems(ins, prev.parent, dlist, a)
45
57
  end
46
58
  end
47
59
 
48
60
  def term_dl_to_designation_metadata(prev, dlist)
49
- %w(absent geographicArea).each { |a| dl_to_attrs(related2pref(prev), dlist, a) }
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
50
67
  end
51
68
 
52
69
  def term_element_insert_point(prev)
@@ -59,34 +76,48 @@ module Asciidoctor
59
76
  end
60
77
 
61
78
  def term_dl_to_expression_metadata(prev, dlist)
62
- %w(language script type isInternational).each do |a|
63
- dl_to_attrs(prev, dlist, a)
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)
64
88
  end
65
- %w(abbreviationType pronunciation).reverse.each do |a|
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|
66
97
  dl_to_elems(prev.at("./expression/name"), prev, dlist, a)
67
98
  end
68
99
  g = dlist.at("./dt[text()='grammar']/following::dd//dl") and
69
100
  term_dl_to_expression_grammar(prev, g)
70
- term_to_letter_symbol(prev, dlist)
71
101
  end
72
102
 
73
103
  def term_dl_to_expression_grammar(prev, dlist)
74
104
  prev.at(".//expression") or return
75
105
  prev.at(".//expression") << "<grammar><sentinel/></grammar>"
76
- %w(gender isPreposition isParticiple isAdjective isAdverb isNoun
77
- grammarValue).reverse.each do |a|
106
+ %w(gender number isPreposition isParticiple isAdjective isAdverb isNoun
107
+ grammar-value).reverse.each do |a|
78
108
  dl_to_elems(prev.at(".//expression/grammar/*"), prev.elements.last,
79
109
  dlist, a)
80
110
  end
81
- term_dl_to_designation_gender(prev)
111
+ term_dl_to_designation_category(prev, "gender")
112
+ term_dl_to_designation_category(prev, "number")
113
+ prev.at(".//expression/grammar/sentinel").remove
82
114
  end
83
115
 
84
- def term_dl_to_designation_gender(prev)
85
- gender = prev.at(".//expression/grammar/gender")
86
- /,/.match?(gender&.text) and
87
- gender.replace(gender.text.split(/,\s*/)
88
- .map { |x| "<gender>#{x}</gender>" }.join)
89
- prev.at(".//expression/grammar/sentinel").remove
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)
90
121
  end
91
122
 
92
123
  def term_to_letter_symbol(prev, dlist)
@@ -134,7 +165,7 @@ module Asciidoctor
134
165
  def term_termsource_to_designation(xmldoc)
135
166
  xmldoc.xpath("//term/termsource").each do |t|
136
167
  p = t.previous_element
137
- while %w(domain subject usageinfo).include? p&.name
168
+ while %w(domain subject).include? p&.name
138
169
  p = p.previous_element
139
170
  end
140
171
  %w(preferred admitted deprecates related).include?(p&.name) or
@@ -155,7 +186,7 @@ module Asciidoctor
155
186
  end
156
187
 
157
188
  def related2pref(elem)
158
- elem.name == "related" ? elem = elem.at("./preferred") : elem
189
+ elem&.name == "related" ? elem = elem.at("./preferred") : elem
159
190
  end
160
191
  end
161
192
  end
@@ -28,6 +28,7 @@ module Asciidoctor
28
28
  end
29
29
 
30
30
  # "abc<tag/>", def => "abc",<tag/> def
31
+ =begin
31
32
  def uninterrupt_quotes_around_xml(xmldoc)
32
33
  xmldoc.xpath("//*[following::text()[1]"\
33
34
  "[starts-with(., '\"') or starts-with(., \"'\")]]")
@@ -37,6 +38,28 @@ module Asciidoctor
37
38
  uninterrupt_quotes_around_xml1(x)
38
39
  end
39
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
40
63
 
41
64
  def uninterrupt_quotes_around_xml1(elem)
42
65
  prev = elem.at(".//preceding::text()[1]") or return
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'erb'
3
+ require "erb"
4
4
 
5
5
  module Asciidoctor
6
6
  module Standoc
@@ -9,7 +9,7 @@ module Asciidoctor
9
9
  BLOCK_START_REGEXP = /\{(.+?)\.\*,(.+),(.+)\}/
10
10
  BLOCK_END_REGEXP = /\A\{[A-Z]+\}\z/
11
11
  MARCO_REGEXP = /\[datamodel_attributes_table,([^,]+),?(.+)?\]/
12
- TEMPLATES_PATH = File.expand_path('../views/datamodel', __dir__).freeze
12
+ TEMPLATES_PATH = File.expand_path("../views/datamodel", __dir__).freeze
13
13
  # search document for block `datamodel_attributes_table`
14
14
  # read include derectives that goes after that in block and transform
15
15
  # into yaml2text blocks
@@ -39,16 +39,16 @@ module Asciidoctor
39
39
  def model_representation(model_path)
40
40
  template = File.read(File.join(
41
41
  TEMPLATES_PATH,
42
- 'model_representation.adoc.erb'
43
- ))
44
- file_name = File.basename(model_path).gsub(/\.ya?ml/, '')
42
+ "model_representation.adoc.erb",
43
+ ))
44
+ file_name = File.basename(model_path).gsub(/\.ya?ml/, "")
45
45
  ERB
46
46
  .new(template)
47
47
  .result(binding)
48
48
  end
49
49
 
50
50
  def yaml_relative_path(file_path, document)
51
- directory = File.dirname(document.attributes['docfile'] || '.')
51
+ directory = File.dirname(document.attributes["docfile"] || ".")
52
52
  document.path_resolver.system_path(file_path, directory)
53
53
  end
54
54
  end
@@ -94,7 +94,7 @@ module Asciidoctor
94
94
 
95
95
  def metadata_script(node, xml)
96
96
  xml.script (node.attr("script") ||
97
- default_script(node.attr("language")))
97
+ Metanorma::Utils.default_script(node.attr("language")))
98
98
  end
99
99
 
100
100
  def relaton_relations
@@ -15,14 +15,10 @@ module Asciidoctor
15
15
 
16
16
  def inline_anchor(node)
17
17
  case node.type
18
- when :ref
19
- inline_anchor_ref node
20
- when :xref
21
- inline_anchor_xref node
22
- when :link
23
- inline_anchor_link node
24
- when :bibref
25
- inline_anchor_bibref node
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
26
22
  end
27
23
  end
28
24
 
@@ -50,7 +46,12 @@ module Asciidoctor
50
46
  m.nil? and return { target: t, type: "inline", text: node.text }
51
47
  droploc = m[:drop].nil? && m[:drop2].nil? ? nil : true
52
48
  f = m[:fn].nil? ? "inline" : "footnote"
53
- c = %i[case fn drop drop2].any? { |x| !m[x].nil? } ? m[:text] : node.text
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
54
55
  { target: t, type: f, case: m[:case]&.sub(/%$/, ""), droploc: droploc,
55
56
  text: c }
56
57
  end
@@ -58,8 +59,9 @@ module Asciidoctor
58
59
  def inline_anchor_link(node)
59
60
  contents = node.text
60
61
  contents = "" if node.target.gsub(%r{^mailto:}, "") == node.text
61
- attributes = { "target": node.target, "alt": node.attr("title"),
62
- "updatetype": node.attr("updatetype") }
62
+ attributes = { target: node.target, alt: node.attr("title"),
63
+ "update-type": node.attr("updatetype") ||
64
+ node.attr("update-type") }
63
65
  noko do |xml|
64
66
  xml.link **attr_code(attributes) do |l|
65
67
  l << contents
@@ -58,7 +58,7 @@
58
58
  <attribute name="alt"/>
59
59
  </optional>
60
60
  <optional>
61
- <attribute name="updatetype">
61
+ <attribute name="update-type">
62
62
  <data type="boolean"/>
63
63
  </attribute>
64
64
  </optional>
@@ -1796,6 +1796,20 @@
1796
1796
  <data type="ID"/>
1797
1797
  </attribute>
1798
1798
  </optional>
1799
+ <optional>
1800
+ <attribute name="language"/>
1801
+ </optional>
1802
+ <optional>
1803
+ <attribute name="script"/>
1804
+ </optional>
1805
+ <optional>
1806
+ <attribute name="tag"/>
1807
+ </optional>
1808
+ <optional>
1809
+ <attribute name="multilingual-rendering">
1810
+ <ref name="MultilingualRenderingType"/>
1811
+ </attribute>
1812
+ </optional>
1799
1813
  <oneOrMore>
1800
1814
  <ref name="preferred"/>
1801
1815
  </oneOrMore>
@@ -1814,9 +1828,6 @@
1814
1828
  <optional>
1815
1829
  <ref name="termsubject"/>
1816
1830
  </optional>
1817
- <optional>
1818
- <ref name="termusage"/>
1819
- </optional>
1820
1831
  <oneOrMore>
1821
1832
  <ref name="termdefinition"/>
1822
1833
  </oneOrMore>
@@ -1880,17 +1891,37 @@
1880
1891
  </attribute>
1881
1892
  </optional>
1882
1893
  <optional>
1883
- <attribute name="geographicArea"/>
1894
+ <attribute name="geographic-area"/>
1884
1895
  </optional>
1885
1896
  <choice>
1886
1897
  <ref name="expression_designation"/>
1887
1898
  <ref name="letter_symbol_designation"/>
1888
1899
  <ref name="graphical_symbol_designation"/>
1889
1900
  </choice>
1901
+ <optional>
1902
+ <ref name="fieldofapplication"/>
1903
+ </optional>
1904
+ <optional>
1905
+ <ref name="usageinfo"/>
1906
+ </optional>
1890
1907
  <zeroOrMore>
1891
1908
  <ref name="termsource"/>
1892
1909
  </zeroOrMore>
1893
1910
  </define>
1911
+ <define name="fieldofapplication">
1912
+ <element name="field-of-application">
1913
+ <oneOrMore>
1914
+ <ref name="PureTextElement"/>
1915
+ </oneOrMore>
1916
+ </element>
1917
+ </define>
1918
+ <define name="usageinfo">
1919
+ <element name="usage-info">
1920
+ <oneOrMore>
1921
+ <ref name="PureTextElement"/>
1922
+ </oneOrMore>
1923
+ </element>
1924
+ </define>
1894
1925
  <define name="letter_symbol_designation">
1895
1926
  <element name="letter-symbol">
1896
1927
  <optional>
@@ -1946,7 +1977,7 @@
1946
1977
  </zeroOrMore>
1947
1978
  </element>
1948
1979
  <optional>
1949
- <element name="abbreviationType">
1980
+ <element name="abbreviation-type">
1950
1981
  <ref name="AbbreviationType"/>
1951
1982
  </element>
1952
1983
  </optional>
@@ -1956,7 +1987,7 @@
1956
1987
  </element>
1957
1988
  </optional>
1958
1989
  <optional>
1959
- <element name="grammarInfo">
1990
+ <element name="grammar-info">
1960
1991
  <ref name="Grammar"/>
1961
1992
  </element>
1962
1993
  </optional>
@@ -1983,6 +2014,11 @@
1983
2014
  <ref name="GrammarGender"/>
1984
2015
  </element>
1985
2016
  </zeroOrMore>
2017
+ <zeroOrMore>
2018
+ <element name="number">
2019
+ <ref name="GrammarNumber"/>
2020
+ </element>
2021
+ </zeroOrMore>
1986
2022
  <optional>
1987
2023
  <element name="isPreposition">
1988
2024
  <data type="boolean"/>
@@ -2014,7 +2050,7 @@
2014
2050
  </element>
2015
2051
  </optional>
2016
2052
  <zeroOrMore>
2017
- <element name="grammarvalue">
2053
+ <element name="grammar-value">
2018
2054
  <text/>
2019
2055
  </element>
2020
2056
  </zeroOrMore>
@@ -2027,6 +2063,13 @@
2027
2063
  <value>common</value>
2028
2064
  </choice>
2029
2065
  </define>
2066
+ <define name="GrammarNumber">
2067
+ <choice>
2068
+ <value>singular</value>
2069
+ <value>dual</value>
2070
+ <value>plural</value>
2071
+ </choice>
2072
+ </define>
2030
2073
  <define name="termdomain">
2031
2074
  <element name="domain">
2032
2075
  <oneOrMore>
@@ -2041,13 +2084,6 @@
2041
2084
  </oneOrMore>
2042
2085
  </element>
2043
2086
  </define>
2044
- <define name="termusage">
2045
- <element name="usageinfo">
2046
- <oneOrMore>
2047
- <ref name="BasicBlock"/>
2048
- </oneOrMore>
2049
- </element>
2050
- </define>
2051
2087
  <define name="termdefinition">
2052
2088
  <element name="definition">
2053
2089
  <choice>
@@ -2061,9 +2097,17 @@
2061
2097
  </element>
2062
2098
  </define>
2063
2099
  <define name="verbaldefinition">
2064
- <element name="verbaldefinition">
2100
+ <element name="verbal-definition">
2065
2101
  <oneOrMore>
2066
- <ref name="paragraph"/>
2102
+ <choice>
2103
+ <ref name="paragraph"/>
2104
+ <ref name="dl"/>
2105
+ <ref name="ol"/>
2106
+ <ref name="ul"/>
2107
+ <ref name="table"/>
2108
+ <ref name="figure"/>
2109
+ <ref name="formula"/>
2110
+ </choice>
2067
2111
  </oneOrMore>
2068
2112
  <zeroOrMore>
2069
2113
  <ref name="termsource"/>
@@ -2071,7 +2115,7 @@
2071
2115
  </element>
2072
2116
  </define>
2073
2117
  <define name="nonverbalrep">
2074
- <element name="nonverbalrepresentation">
2118
+ <element name="non-verbal-representation">
2075
2119
  <oneOrMore>
2076
2120
  <choice>
2077
2121
  <ref name="table"/>
@@ -2163,6 +2207,12 @@
2163
2207
  <value>modified</value>
2164
2208
  </choice>
2165
2209
  </attribute>
2210
+ <attribute name="type">
2211
+ <choice>
2212
+ <value>authoritative</value>
2213
+ <value>lineage</value>
2214
+ </choice>
2215
+ </attribute>
2166
2216
  <ref name="origin"/>
2167
2217
  <optional>
2168
2218
  <ref name="modification"/>
@@ -14,11 +14,9 @@ module Asciidoctor
14
14
 
15
15
  def ul_li(xml_ul, item)
16
16
  xml_ul.li **ul_li_attrs(item) do |xml_li|
17
+ xml_li.p(**attr_code(id_attr(item))) { |t| t << item.text }
17
18
  if item.blocks?
18
- xml_li.p(**attr_code(id_attr(item))) { |t| t << item.text }
19
19
  xml_li << item.content
20
- else
21
- xml_li.p(**attr_code(id_attr(item))) { |p| p << item.text }
22
20
  end
23
21
  end
24
22
  end