metanorma-standoc 2.0.1 → 2.0.2

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: a5ab9cbdae658ec4088c0670d2ce1a117799a9325dbb8b8aa24e59b44e94e24c
4
- data.tar.gz: da30d4d7b276b67e2363643e8ae1296a352bc4acee0ef9f2727da00ad276b3cc
3
+ metadata.gz: d9031c28646f9cd9a481ad67911f2f0f7e5bd058368f80888a788753e5f63fa3
4
+ data.tar.gz: 25b16459f351f266f19b2f00d70b5bf7f6f5c95325a0d61d43fbe5f3fa518802
5
5
  SHA512:
6
- metadata.gz: e8600c60d56d27820da72dbc7259db4e3a91a3e362a4cefa0a5497b545076dab93277e87c5a0368f3037249ed79b5421e92300a8847bcf7c5bdcaca2392a3eab
7
- data.tar.gz: 216bdaa7621b5b722f65a7d86eabbeaf65788df7f135927d04044838c6db31d50999155de829df6e57f5563a4f201121f36cde9c9c023a9af546019ab65d848e
6
+ metadata.gz: 885e62405f3198482ffd7e152b25bef8ab09fc227a8107984297e8fa15b64552b2e745f4ce5e1d60dd37df6dc5cf5c505fb9acfeedd1bdc4ef77954e01218893
7
+ data.tar.gz: 69cac251a0696b46dd25f37fb23828780e1945e57464e829c91ab5d88ac481311d130c4ff0e670ee89d56fd998eff4ea48e3c5a0c4b24c514021431fb785d852
@@ -401,9 +401,9 @@
401
401
  <choice>
402
402
  <!-- iso191606 TODO -->
403
403
  <group>
404
- <oneOrMore>
404
+ <zeroOrMore>
405
405
  <ref name="street"/>
406
- </oneOrMore>
406
+ </zeroOrMore>
407
407
  <ref name="city"/>
408
408
  <optional>
409
409
  <ref name="state"/>
@@ -28,28 +28,6 @@ module Metanorma
28
28
  end
29
29
 
30
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
31
  def uninterrupt_quotes_around_xml(xmldoc)
54
32
  xmldoc.traverse do |n|
55
33
  next unless n.text? && n&.previous&.element?
@@ -61,6 +61,7 @@ module Metanorma
61
61
  block Metanorma::Standoc::PlantUMLBlockMacro
62
62
  block Metanorma::Plugin::Lutaml::LutamlDiagramBlock
63
63
  block Metanorma::Standoc::PseudocodeBlockMacro
64
+ preprocessor Metanorma::Standoc::EmbedIncludeProcessor
64
65
  end
65
66
 
66
67
  include ::Asciidoctor::Converter
@@ -32,6 +32,43 @@
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>
35
72
  <define name="bibitem">
36
73
  <element name="bibitem">
37
74
  <attribute name="id">
@@ -1027,6 +1064,26 @@
1027
1064
  </zeroOrMore>
1028
1065
  </element>
1029
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>
1030
1087
  <define name="pagebreak">
1031
1088
  <element name="pagebreak">
1032
1089
  <optional>
@@ -2216,7 +2273,18 @@
2216
2273
  <ref name="MultilingualRenderingType"/>
2217
2274
  </attribute>
2218
2275
  </optional>
2219
- <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>
2220
2288
  </element>
2221
2289
  </define>
2222
2290
  <define name="termsource">
@@ -7,6 +7,7 @@ require_relative "./macros_plantuml"
7
7
  require_relative "./macros_terms"
8
8
  require_relative "./macros_form"
9
9
  require_relative "./macros_note"
10
+ require_relative "./macros_embed"
10
11
  require_relative "./datamodel/attributes_table_preprocessor"
11
12
  require_relative "./datamodel/diagram_preprocessor"
12
13
  require "metanorma-plugin-datastruct"
@@ -0,0 +1,72 @@
1
+ module Metanorma
2
+ module Standoc
3
+ class EmbedIncludeProcessor < Asciidoctor::Extensions::Preprocessor
4
+ def process(doc, reader)
5
+ return reader if reader.eof?
6
+
7
+ lines = reader.readlines
8
+ while !lines.grep(/^embed::/).empty?
9
+ headings = lines.grep(/^== /).map(&:strip)
10
+ lines = lines.map do |line|
11
+ /^embed::/.match?(line) ? embed(line, doc, reader, headings) : line
12
+ end.flatten
13
+ end
14
+ ::Asciidoctor::Reader.new lines
15
+ end
16
+
17
+ def filename(line, doc, reader)
18
+ m = /^embed::([^\[]+)\[/.match(line)
19
+ f = doc.normalize_system_path m[1], reader.dir, nil,
20
+ target_name: "include file"
21
+ File.exist?(f) ? f : nil
22
+ end
23
+
24
+ def readlines_safe(file)
25
+ if file.eof? then []
26
+ else file.readlines
27
+ end
28
+ end
29
+
30
+ def embed(line, doc, reader, headings)
31
+ inc_path = filename(line, doc, reader) or return line
32
+ lines = filter_sections(read(inc_path), headings)
33
+ doc = Asciidoctor::Document.new [], { safe: :safe }
34
+ reader = ::Asciidoctor::PreprocessorReader.new doc, lines
35
+ strip_header(reader.read_lines)
36
+ end
37
+
38
+ def read(inc_path)
39
+ ::File.open inc_path, "r" do |fd|
40
+ readlines_safe(fd).map(&:chomp)
41
+ end
42
+ end
43
+
44
+ def strip_header(lines)
45
+ return lines unless !lines.empty? && lines.first.start_with?("= ")
46
+
47
+ skip = true
48
+ lines.each_with_object([]) do |l, m|
49
+ m << l unless skip
50
+ skip = false if !/\S/.match?(l)
51
+ end
52
+ end
53
+
54
+ def filter_sections(lines, headings)
55
+ skip = false
56
+ lines.each_with_index.with_object([]) do |(l, i), m|
57
+ if headings.include?(l.strip)
58
+ skip = true
59
+ m.unshift while !m.empty? && /^\S/.match?(m[-1])
60
+ elsif skip && /^== |^embed::|^include::/.match?(l)
61
+ skip = false
62
+ j = i
63
+ j -= 1 while j >= 0 && /^\S/.match?(m[j])
64
+ lines[j..i].each { |n| m << n }
65
+ else
66
+ skip or m << l
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.0.1".freeze
22
+ VERSION = "2.0.2".freeze
23
23
  end
24
24
  end
@@ -0,0 +1,8 @@
1
+ = X
2
+ A
3
+
4
+ == Clause 1
5
+
6
+ X
7
+
8
+ embed::spec/assets/a2.adoc[]
@@ -0,0 +1,8 @@
1
+ = X
2
+ A
3
+
4
+ == Clause 2
5
+
6
+ X
7
+
8
+ embed::spec/assets/a3.adoc[]
@@ -0,0 +1,9 @@
1
+ = X
2
+ A
3
+
4
+ == Clause 3
5
+
6
+ X
7
+
8
+ include::spec/assets/a4.adoc[]
9
+
@@ -0,0 +1,4 @@
1
+ == Clause 4
2
+
3
+ X
4
+
@@ -1304,6 +1304,95 @@ RSpec.describe Metanorma::Standoc do
1304
1304
  .to be_equivalent_to xmlpp(output)
1305
1305
  end
1306
1306
 
1307
+ it "processes embed macro" do
1308
+ input = <<~INPUT
1309
+ #{ASCIIDOC_BLANK_HDR}
1310
+
1311
+ [[clause1]]
1312
+ == Clause 1
1313
+
1314
+ embed::spec/assets/xref_error.adoc[]
1315
+ INPUT
1316
+ output = <<~OUTPUT
1317
+ #{BLANK_HDR}
1318
+ <sections>
1319
+ <clause id='clause1' inline-header='false' obligation='normative'>
1320
+ <title>Clause 1</title>
1321
+ </clause>
1322
+ <clause id='_' inline-header='false' obligation='normative'>
1323
+ <title>Clause</title>
1324
+ <p id='_'>
1325
+ <xref target='a'>b</xref>
1326
+ </p>
1327
+ </clause>
1328
+ </sections>
1329
+ </standard-document>
1330
+ OUTPUT
1331
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
1332
+ .to be_equivalent_to xmlpp(output)
1333
+ end
1334
+
1335
+ it "processes embed macro with overwriting" do
1336
+ input = <<~INPUT
1337
+ #{ASCIIDOC_BLANK_HDR}
1338
+
1339
+ [[clause1]]
1340
+ == Clause
1341
+
1342
+ embed::spec/assets/xref_error.adoc[]
1343
+ INPUT
1344
+ output = <<~OUTPUT
1345
+ #{BLANK_HDR}
1346
+ <sections>
1347
+ <clause id='clause1' inline-header='false' obligation='normative'>
1348
+ <title>Clause</title>
1349
+ </clause>
1350
+ </sections>
1351
+ </standard-document>
1352
+ OUTPUT
1353
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
1354
+ .to be_equivalent_to xmlpp(output)
1355
+ end
1356
+
1357
+ it "processes recursive embed macro with includes" do
1358
+ input = <<~INPUT
1359
+ #{ASCIIDOC_BLANK_HDR}
1360
+
1361
+ [[clause1]]
1362
+ == Clause
1363
+
1364
+ embed::spec/assets/a1.adoc[]
1365
+ INPUT
1366
+ output = <<~OUTPUT
1367
+ #{BLANK_HDR}
1368
+ <sections>
1369
+ <clause id='clause1' inline-header='false' obligation='normative'>
1370
+ <title>Clause</title>
1371
+ </clause>
1372
+ <clause id='_' inline-header='false' obligation='normative'>
1373
+ <title>Clause 1</title>
1374
+ <p id='_'>X</p>
1375
+ </clause>
1376
+ <clause id='_' inline-header='false' obligation='normative'>
1377
+ <title>Clause 2</title>
1378
+ <p id='_'>X</p>
1379
+ </clause>
1380
+ <clause id='_' inline-header='false' obligation='normative'>
1381
+ <title>Clause 3</title>
1382
+ <p id='_'>X</p>
1383
+ </clause>
1384
+ <clause id='_' inline-header='false' obligation='normative'>
1385
+ <title>Clause 4</title>
1386
+ <p id='_'>X</p>
1387
+ </clause>
1388
+ </sections>
1389
+ </standard-document>
1390
+ OUTPUT
1391
+ expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
1392
+ .to be_equivalent_to xmlpp(output)
1393
+ end
1394
+
1395
+
1307
1396
  describe "term inline macros" do
1308
1397
  subject(:convert) do
1309
1398
  xmlpp(
@@ -1625,7 +1625,7 @@ RSpec.describe Metanorma::Standoc do
1625
1625
 
1626
1626
  * [[[iso124,BSI BS EN ISO 19011:2018]]] _Standard_
1627
1627
  * [[[iso123,BSI BS EN 16341]]] _Standard_
1628
- * [[[ref_2,BSI BS EN ISO 14044:2006+A1:2020]]], _Environmental management – Life cycle assessment – Requirements and guidelines_
1628
+ * [[[ref_2,BSI BS EN ISO 14044:2006+A2:2020]]], _Environmental management – Life cycle assessment – Requirements and guidelines_
1629
1629
  INPUT
1630
1630
  output = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS))
1631
1631
  .xpath("//xmlns:docidentifier[@type = 'BSI']").map(&:text)
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: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -492,6 +492,7 @@ files:
492
492
  - lib/metanorma/standoc/isodoc.rng
493
493
  - lib/metanorma/standoc/lists.rb
494
494
  - lib/metanorma/standoc/macros.rb
495
+ - lib/metanorma/standoc/macros_embed.rb
495
496
  - lib/metanorma/standoc/macros_form.rb
496
497
  - lib/metanorma/standoc/macros_note.rb
497
498
  - lib/metanorma/standoc/macros_plantuml.rb
@@ -514,6 +515,10 @@ files:
514
515
  - lib/metanorma/standoc/views/datamodel/model_representation.adoc.erb
515
516
  - lib/metanorma/standoc/views/datamodel/plantuml_representation.adoc.erb
516
517
  - metanorma-standoc.gemspec
518
+ - spec/assets/a1.adoc
519
+ - spec/assets/a2.adoc
520
+ - spec/assets/a3.adoc
521
+ - spec/assets/a4.adoc
517
522
  - spec/assets/boilerplate.xml
518
523
  - spec/assets/codes.yml
519
524
  - spec/assets/header.html