metanorma-standoc 1.3.16 → 1.3.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cbc909f073c18439ea897d38577eab4e82753ca6aae23092d48d02afc8175c2
4
- data.tar.gz: e2378d286cec5648f244435d00a65030d7ab4127637da2192cfd78928c353aee
3
+ metadata.gz: 4647d414467e7326fb0d0d30ee3ac79ad4f3f4a8a2e7d4ffa0948db689781db3
4
+ data.tar.gz: ca6d428a27678a89ff8188162046216a7f4f0efe450488d36b158319a91e45a0
5
5
  SHA512:
6
- metadata.gz: f72a292b68b1f6399ff21317e15d5008acba3bd4a42023b120c14682697c22935fff14a98fbc385ef4d18ec0dbb56834e9bcfadb3e640911963a13ad4bb0a769
7
- data.tar.gz: c818e921411293cca9d6727c80d7f2a4397c20f483d44076665d42f02d6c700408fd446a36977335b348e563beb05c73b70add8751afefc706cf03e91b8848a4
6
+ metadata.gz: 97847d11b89413d948324766bda68e416defdb35fd6fed828d6e3bcda8e67fe626a3d14054edce3d580af83c465c786b1a1c11e24585d15054d0cb01d9952bc2
7
+ data.tar.gz: 30e844b147945676fa516f98955f878d6b9442c3875f3edcea6ef27a6908a15bc15fedcd26a76619c3068f9f534820db419704abdcb7d2e5562a68dc4a77f9e8
@@ -4,7 +4,6 @@ require "htmlentities"
4
4
  require "json"
5
5
  require "pathname"
6
6
  require "open-uri"
7
- require "pp"
8
7
  require "isodoc"
9
8
  require "relaton"
10
9
  require "fileutils"
@@ -12,6 +11,9 @@ require "fileutils"
12
11
  module Asciidoctor
13
12
  module Standoc
14
13
  module Base
14
+ XML_ROOT_TAG = "standard-document".freeze
15
+ XML_NAMESPACE = "https://www.metanorma.com/ns/standoc".freeze
16
+
15
17
  Asciidoctor::Extensions.register do
16
18
  inline_macro Asciidoctor::Standoc::AltTermInlineMacro
17
19
  inline_macro Asciidoctor::Standoc::DeprecatedTermInlineMacro
@@ -159,17 +161,18 @@ module Asciidoctor
159
161
  end
160
162
 
161
163
  def makexml1(node)
162
- result = ["<?xml version='1.0' encoding='UTF-8'?>\n<standard-document>"]
164
+ result = ["<?xml version='1.0' encoding='UTF-8'?>",
165
+ "<#{self.class::XML_ROOT_TAG}>"]
163
166
  result << noko { |ixml| front node, ixml }
164
167
  result << noko { |ixml| middle node, ixml }
165
- result << "</standard-document>"
168
+ result << "</#{self.class::XML_ROOT_TAG}>"
166
169
  textcleanup(result)
167
170
  end
168
171
 
169
172
  def makexml(node)
170
173
  result = makexml1(node)
171
174
  ret1 = cleanup(Nokogiri::XML(result))
172
- ret1.root.add_namespace(nil, "http://riboseinc.com/isoxml")
175
+ ret1.root.add_namespace(nil, self.class::XML_NAMESPACE)
173
176
  validate(ret1) unless @novalid
174
177
  ret1
175
178
  end
@@ -219,9 +222,8 @@ module Asciidoctor
219
222
 
220
223
  def extract_termsource_refs(text, node)
221
224
  matched = TERM_REFERENCE_RE.match text
222
- if matched.nil?
225
+ matched.nil? and
223
226
  Utils::warning(node, "term reference not in expected format", text)
224
- end
225
227
  matched
226
228
  end
227
229
 
@@ -89,7 +89,10 @@ module Asciidoctor
89
89
  end
90
90
 
91
91
  def page_break(node)
92
- noko { |xml| xml.pagebreak }.join
92
+ attrs = {}
93
+ node.option?("landscape") and attrs[:orientation] = "landscape"
94
+ node.option?("portrait") and attrs[:orientation] = "portrait"
95
+ noko { |xml| xml.pagebreak **attr_code(attrs)}.join
93
96
  end
94
97
 
95
98
  def thematic_break(_node)
@@ -17,7 +17,7 @@
17
17
  these elements; we just want one namespace for any child grammars
18
18
  of this.
19
19
  -->
20
- <grammar ns="http://riboseinc.com/isoxml" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
20
+ <grammar ns="https://www.metanorma.com/ns/standoc" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
21
21
  <include href="reqt.rng"/>
22
22
  <!-- include "biblio.rnc" { } -->
23
23
  <include href="basicdoc.rng">
@@ -182,19 +182,35 @@ module Asciidoctor
182
182
  end
183
183
 
184
184
  # if no :imagesdir: leave image file in plantuml
185
- # sleep need for windows because dot works in separate process and
186
- # plantuml process may finish earlier then dot, as result png file
185
+ # sleep need for windows because dot works in separate process and
186
+ # plantuml process may finish earlier then dot, as result png file
187
187
  # maybe not created yet after plantuml finish
188
188
  def self.generate_file parent, reader
189
189
  localdir = Utils::localdir(parent.document)
190
+
191
+ imagesdir = parent.document.attr('imagesdir')
190
192
  umlfile, outfile = save_plantuml parent, reader, localdir
193
+
194
+ # TODO: this should raise failure if there is no image output!!
191
195
  run(umlfile, outfile) or return
192
- path = Pathname.new(localdir) + "plantuml"
193
- path.mkpath()
194
- File.exist?(path) && File.writable?(path) or return
195
- FileUtils.cp outfile, path
196
196
  umlfile.unlink
197
- File.join(path,File.basename(outfile))
197
+
198
+ path = Pathname.new(localdir) + (imagesdir || "plantuml")
199
+ path.mkpath
200
+
201
+ # TODO: this should raise failure if the destination path already exists!
202
+ File.exist?(path) or return
203
+
204
+ # TODO: this should raise failure if the destination path is not writable!
205
+ File.writable?(path) or return
206
+
207
+ # Warning for Heisenbug: metanorma/metanorma-standoc#187
208
+ # Windows Ruby 2.4 will crash if a Tempfile is "mv"ed.
209
+ # This is why we need to copy and then unlink.
210
+ filename = File.basename(outfile.to_s)
211
+ FileUtils.cp(outfile, path) && outfile.unlink
212
+
213
+ imagesdir ? filename : File.join(path, filename)
198
214
  end
199
215
 
200
216
  def self.save_plantuml parent, reader, localdir
@@ -225,6 +241,7 @@ module Asciidoctor
225
241
  parse_content_as :raw
226
242
 
227
243
  def abort(parent, reader, attrs, msg)
244
+ # TODO: Abort should really raise an error
228
245
  warn msg
229
246
  attrs["language"] = "plantuml"
230
247
  create_listing_block parent, reader.source, attrs.reject { |k, v| k == 1 }
@@ -20,15 +20,34 @@ module Asciidoctor
20
20
  @norm_ref
21
21
  end
22
22
 
23
- def sectiontype(node)
23
+ def sectiontype(node, level = true)
24
24
  ret = node&.attr("heading")&.downcase ||
25
25
  node.title.gsub(/<[^>]+>/, "").downcase
26
- return ret if ["symbols and abbreviated terms", "abbreviations",
27
- "abbreviated terms", "symbols"].include? ret
28
- return nil unless node.level == 1
26
+ ret1 = sectiontype_streamline(ret)
27
+ return ret1 if "symbols and abbreviated terms" == ret1
28
+ return nil unless !level || node.level == 1
29
29
  return nil if @seen_headers.include? ret
30
30
  @seen_headers << ret
31
- ret
31
+ ret1
32
+ end
33
+
34
+ def sectiontype_streamline(ret)
35
+ case ret
36
+ when "terms and definitions",
37
+ "terms, definitions, symbols and abbreviated terms",
38
+ "terms, definitions, symbols and abbreviations",
39
+ "terms, definitions and symbols",
40
+ "terms, definitions and abbreviations",
41
+ "terms, definitions and abbreviated terms"
42
+ "terms and definitions"
43
+ when "symbols and abbreviated terms",
44
+ "symbols",
45
+ "abbreviated terms",
46
+ "abbreviations"
47
+ "symbols and abbreviated terms"
48
+ else
49
+ ret
50
+ end
32
51
  end
33
52
 
34
53
  def section_attributes(node)
@@ -43,19 +62,11 @@ module Asciidoctor
43
62
  case sectiontype(node)
44
63
  when "introduction" then introduction_parse(a, xml, node)
45
64
  when "normative references" then norm_ref_parse(a, xml, node)
46
- when "terms and definitions",
47
- "terms, definitions, symbols and abbreviated terms",
48
- "terms, definitions, symbols and abbreviations",
49
- "terms, definitions and symbols",
50
- "terms, definitions and abbreviations",
51
- "terms, definitions and abbreviated terms"
65
+ when "terms and definitions"
52
66
  @term_def = true
53
67
  term_def_parse(a, xml, node, true)
54
68
  @term_def = false
55
- when "symbols and abbreviated terms",
56
- "symbols",
57
- "abbreviated terms",
58
- "abbreviations"
69
+ when "symbols and abbreviated terms"
59
70
  symbols_parse(a, xml, node)
60
71
  when "bibliography" then bibliography_parse(a, xml, node)
61
72
  else
@@ -139,9 +150,9 @@ module Asciidoctor
139
150
  @definitions = true
140
151
  end
141
152
 
142
- def symbols_parse(attrs, xml, node)
143
- node.role == "nonterm" and return nonterm_symbols_parse(attrs, xml, node)
144
- xml.definitions **attr_code(attrs) do |xml_section|
153
+ def symbols_parse(attr, xml, node)
154
+ node.role == "nonterm" and return nonterm_symbols_parse(attr, xml, node)
155
+ xml.definitions **attr_code(attr) do |xml_section|
145
156
  xml_section.title { |t| t << node.title }
146
157
  defs = @definitions
147
158
  termdefs = @term_def
@@ -164,13 +175,18 @@ module Asciidoctor
164
175
 
165
176
  # subclause contains subclauses
166
177
  def term_def_subclause_parse(attrs, xml, node)
167
- node.role == "nonterm" and
178
+ node.role == "nonterm" ||
179
+ sectiontype(node, false) == "terms and definitions" and
168
180
  return nonterm_term_def_subclause_parse(attrs, xml, node)
169
181
  return symbols_parse(attrs, xml, node) if @definitions
170
182
  sub = node.find_by(context: :section) { |s| s.level == node.level + 1 }
171
183
  sub.empty? || (return term_def_parse(attrs, xml, node, false))
172
- SYMBOLS_TITLES.include?(node.title.downcase) and
184
+ sectiontype(node, false) == "symbols and abbreviated terms" and
173
185
  (return symbols_parse(attrs, xml, node))
186
+ term_def_subclause_parse1(attrs, xml, node)
187
+ end
188
+
189
+ def term_def_subclause_parse1(attrs, xml, node)
174
190
  xml.term **attr_code(attrs) do |xml_section|
175
191
  xml_section.preferred { |name| name << node.title }
176
192
  xml_section << node.content
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Standoc
3
- VERSION = "1.3.16".freeze
3
+ VERSION = "1.3.17".freeze
4
4
  end
5
5
  end
@@ -106,7 +106,7 @@ RSpec.describe Asciidoctor::Standoc do
106
106
  :keywords: a, b, c
107
107
  INPUT
108
108
  <?xml version="1.0" encoding="UTF-8"?>
109
- <standard-document xmlns="http://riboseinc.com/isoxml">
109
+ <standard-document xmlns="https://www.metanorma.com/ns/standoc">
110
110
  <bibdata type="standard">
111
111
  <title language="en" format="text/plain">Main Title — Title</title>
112
112
  <docidentifier>1000-1</docidentifier>
@@ -315,7 +315,7 @@ RSpec.describe Asciidoctor::Standoc do
315
315
  == Clause 1
316
316
  INPUT
317
317
  <?xml version="1.0" encoding="UTF-8"?>
318
- <standard-document xmlns="http://riboseinc.com/isoxml">
318
+ <standard-document xmlns="https://www.metanorma.com/ns/standoc">
319
319
  <bibdata type="standard">
320
320
  <title language="en" format="text/plain">Document title</title>
321
321
  <title language="eo" format="text/plain">Dokumenttitolo</title>
@@ -273,7 +273,7 @@ RSpec.describe Asciidoctor::Standoc do
273
273
  For further information on the Foreword, see *ISO/IEC Directives, Part 2, 2016, Clause 12.*
274
274
  ****
275
275
  INPUT
276
- <standard-document xmlns="http://riboseinc.com/isoxml">
276
+ <standard-document xmlns="https://www.metanorma.com/ns/standoc">
277
277
  <bibdata type="standard">
278
278
  <title language="en" format="text/plain">Document title</title>
279
279
 
@@ -1402,7 +1402,7 @@ it "removes bibdata bibitem IDs" do
1402
1402
 
1403
1403
  INPUT
1404
1404
  <?xml version='1.0' encoding='UTF-8'?>
1405
- <standard-document xmlns='http://riboseinc.com/isoxml'>
1405
+ <standard-document xmlns='https://www.metanorma.com/ns/standoc'>
1406
1406
  <bibdata type='standard'>
1407
1407
  <title language='en' format='text/plain'>Document title</title>
1408
1408
  <language>en</language>
@@ -1448,7 +1448,7 @@ it "imports boilerplate file" do
1448
1448
  == Clause 1
1449
1449
 
1450
1450
  INPUT
1451
- <standard-document xmlns='http://riboseinc.com/isoxml'>
1451
+ <standard-document xmlns='https://www.metanorma.com/ns/standoc'>
1452
1452
  <bibdata type='standard'>
1453
1453
  <title language='en' format='text/plain'>Document title</title>
1454
1454
  <language>en</language>
@@ -10,7 +10,7 @@ RSpec.describe Asciidoctor::Standoc do
10
10
  text, including **__nest__**ed markup.
11
11
  INPUT
12
12
  <?xml version="1.0" encoding="UTF-8"?>
13
- <standard-document xmlns="http://riboseinc.com/isoxml">
13
+ <standard-document xmlns="https://www.metanorma.com/ns/standoc">
14
14
  <bibdata type="standard">
15
15
  <title language="en" format="text/plain">Document title</title>
16
16
  <language>en</language>
@@ -136,12 +136,21 @@ text, including <strong><em>nest</em></strong>ed markup.</p>
136
136
  '''
137
137
 
138
138
  <<<
139
+
140
+ [%landscape]
141
+ <<<
142
+
143
+ [%portrait]
144
+ <<<
139
145
  INPUT
140
146
  #{BLANK_HDR}
141
147
  <sections><p id="_">Line break<br/>
142
148
  line break</p>
143
149
  <hr/>
144
- <pagebreak/></sections>
150
+ <pagebreak/>
151
+ <pagebreak orientation="landscape"/>
152
+ <pagebreak orientation="portrait"/>
153
+ </sections>
145
154
  </standard-document>
146
155
  OUTPUT
147
156
  end
@@ -254,7 +254,7 @@ OUTPUT
254
254
  end
255
255
 
256
256
  it "processes the PlantUML macro" do
257
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{plantuml/plantuml[^.]+\.}, "plantuml/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
257
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{plantuml/plantuml[^./]+\.}, "plantuml/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
258
258
  #{ASCIIDOC_BLANK_HDR}
259
259
 
260
260
  [plantuml]
@@ -305,7 +305,7 @@ OUTPUT
305
305
  end
306
306
 
307
307
  it "processes the PlantUML macro with imagesdir" do
308
- expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{spec/assets/[^.]+\.}, "spec/assets/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
308
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{spec/assets/[^./]+\.}, "spec/assets/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
309
309
  = Document title
310
310
  Author
311
311
  :docfile: test.adoc
@@ -1085,7 +1085,7 @@ OUTPUT
1085
1085
  * [[[iso124,(1)ISO 123]]] _Standard_
1086
1086
  INPUT
1087
1087
  <?xml version="1.0" encoding="UTF-8"?>
1088
- <standard-document xmlns="http://riboseinc.com/isoxml">
1088
+ <standard-document xmlns="https://www.metanorma.com/ns/standoc">
1089
1089
  <bibdata type="standard">
1090
1090
  <title language="en" format="text/plain">Document title</title>
1091
1091
  <language>en</language>
@@ -561,6 +561,35 @@ RSpec.describe Asciidoctor::Standoc do
561
561
  OUTPUT
562
562
  end
563
563
 
564
+ it "processes terminal nodes in terms with term subsection names" do
565
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
566
+ #{ASCIIDOC_BLANK_HDR}
567
+
568
+ == Terms, definitions, symbols and abbreviated terms
569
+
570
+ === Terms and definitions
571
+
572
+ === Symbols
573
+
574
+ INPUT
575
+ #{BLANK_HDR}
576
+ <sections>
577
+ <terms id='_' obligation='normative'>
578
+ <title>Terms, definitions, symbols and abbreviated terms</title>
579
+ <p id='_'>No terms and definitions are listed in this document.</p>
580
+ <clause id='_' inline-header='false' obligation='normative'>
581
+ <title>Terms and definitions</title>
582
+ </clause>
583
+ <definitions id='_'>
584
+ <title>Symbols</title>
585
+ </definitions>
586
+ </terms>
587
+ </sections>
588
+ </standard-document>
589
+ OUTPUT
590
+ end
591
+
592
+
564
593
  it "processes terms & definitions with external source" do
565
594
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
566
595
  #{ASCIIDOC_BLANK_HDR}
data/spec/spec_helper.rb CHANGED
@@ -128,7 +128,7 @@ HDR
128
128
 
129
129
  BLANK_HDR = <<~"HDR"
130
130
  <?xml version="1.0" encoding="UTF-8"?>
131
- <standard-document xmlns="http://riboseinc.com/isoxml">
131
+ <standard-document xmlns="https://www.metanorma.com/ns/standoc">
132
132
  <bibdata type="standard">
133
133
  <title language="en" format="text/plain">Document title</title>
134
134
  <language>en</language>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-standoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.16
4
+ version: 1.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-30 00:00:00.000000000 Z
11
+ date: 2020-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor