stepmod-utils 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 149a4297bcddd8785d88f316feb899f711c8ce731d91562f37b63cfa128fd686
4
- data.tar.gz: 6449d7bc7071a15066e7fe24697814c3b570c0df648fba1d4fb44e1a91ec9bdf
3
+ metadata.gz: 4d9d95bf89fc69ea44d7924a14274ab5c82361da39fb40e795c14fea8cc87eaf
4
+ data.tar.gz: 6e2240c2d977787e40183bb988b4ba8db188be9e5c71da1815cc6748e503517b
5
5
  SHA512:
6
- metadata.gz: e8c6c7b93e0fb7351d2c02b193221fa59d438056170b61262d662888bafddd3b4f3833e99d34188512125ab5b447c2bd999a15bcb09aa81d58443e1f48d962b7
7
- data.tar.gz: 123c2187ce5f431e0e0ecbd530e5152289674f85bde2237ab0c76bb04e1d72dad52e4751bbf1a8e8d51e01c5120b9f569fa8c4605009d775a108cbd6787a8226
6
+ metadata.gz: ca1a8cdacd5c6798944103d428bf98b2ca7caa8e964bcfd339d1f54c5342e87d20bffe72c7e3995ffb69a1e5b10b1144f29e7ee2b8f63822e982b5058c649a03
7
+ data.tar.gz: de99be754e8690fa61623767a83da8704cae6e94bd089bd2acf22c89fab61b10b54d41d3d5acc790f62b7424c7398740d06c92a2e6cfc5b2ba787156e09461fc
@@ -104,14 +104,14 @@ module Stepmod
104
104
  end
105
105
 
106
106
  def anchor
107
- docid.gsub('/', '-').gsub(' ', '_')
107
+ docid.gsub('/', '-').gsub(' ', '_').gsub(':', '_')
108
108
  end
109
109
 
110
110
  def to_mn_adoc
111
111
  if title_en
112
- "* [[[ISO#{DOCNUMBER}-#{part},#{docid}]]], _#{full_title}_"
112
+ "* [[[#{anchor},#{docid}]]], _#{full_title}_"
113
113
  else
114
- "* [[[ISO#{DOCNUMBER}-#{part},#{docid}]]]"
114
+ "* [[[#{anchor},#{docid}]]]"
115
115
  end
116
116
  end
117
117
 
@@ -12,12 +12,7 @@ module Stepmod
12
12
 
13
13
  def treat_children(node, state)
14
14
  converted = node.children.each_with_object({}) do |child, res|
15
- content = treat(child, state)
16
- .split("\n")
17
- .map(&:strip)
18
- .reject(&:empty?)
19
- .join("\n")
20
- .strip
15
+ content = treat(child, state).strip
21
16
  next if content.empty?
22
17
 
23
18
  res[child] = content
@@ -25,7 +20,7 @@ module Stepmod
25
20
  previous = nil
26
21
  result = ''
27
22
  converted.each.with_index do |(child, content), i|
28
- if i == 0 || inlinde_tag?(child, previous)
23
+ if i == 0 || !block_tag?(child, previous)
29
24
  result += " #{content}"
30
25
  else
31
26
  result += "\n\n#{content}"
@@ -35,8 +30,9 @@ module Stepmod
35
30
  result.strip
36
31
  end
37
32
 
38
- def inlinde_tag?(child, previous)
39
- %w[text sub i clause_ref].include?(child.name) && previous && %w[i sub text clause_ref].include?(previous.name)
33
+ def block_tag?(child, previous)
34
+ %w[ul example note alt p].include?(child.name) ||
35
+ (child.previous && %w[ul example note alt p].include?(child.previous.name))
40
36
  end
41
37
 
42
38
  def additional_block(node)
@@ -44,8 +40,7 @@ module Stepmod
44
40
  first_child_tag = node
45
41
  .children
46
42
  .find { |n| n.is_a?(Nokogiri::XML::Element) }
47
- return unless first_child_tag&.name == 'p' &&
48
- defined?(Stepmod::Utils::Converters::Synonym)
43
+ return unless can_transform_to_alt?(first_child_tag)
49
44
 
50
45
  result = Stepmod::Utils::Converters::Synonym
51
46
  .new
@@ -53,6 +48,19 @@ module Stepmod
53
48
  first_child_tag.remove
54
49
  "#{result}\n\n"
55
50
  end
51
+
52
+ # metanorma/stepmod-utils#18 when para is the only text doe snot transform it
53
+ def can_transform_to_alt?(first_child_tag)
54
+ return false unless first_child_tag&.name == 'p' &&
55
+ defined?(Stepmod::Utils::Converters::Synonym)
56
+
57
+ next_sibling = first_child_tag.next
58
+ while next_sibling
59
+ return true if !next_sibling.text.to_s.strip.empty? && %w[p text].include?(next_sibling.name)
60
+ next_sibling = next_sibling.next
61
+ end
62
+ false
63
+ end
56
64
  end
57
65
 
58
66
  ReverseAsciidoctor::Converters.register :def, Def.new
@@ -5,7 +5,26 @@ module Stepmod
5
5
  module Converters
6
6
  class ModuleRef < ReverseAsciidoctor::Converters::Base
7
7
  def convert(node, _state = {})
8
- " term:[#{node['linkend']}] "
8
+ ref = node['linkend']
9
+ # #23:
10
+ # In this case when we see this:
11
+
12
+ # <module_ref linkend="product_as_individual:3_definition">individual products</module_ref>
13
+ # We take the text value of the element and convert to this:
14
+
15
+ # term:[individual products]
16
+ if node['linkend'].split(':').length > 1
17
+ ref = node.text
18
+ end
19
+ " term:[#{normalized_ref(ref)}] "
20
+ end
21
+
22
+ private
23
+
24
+ def normalized_ref(ref)
25
+ return unless ref || ref.empty?
26
+
27
+ ref.squeeze(' ').strip
9
28
  end
10
29
  end
11
30
  ReverseAsciidoctor::Converters.register :module_ref, ModuleRef.new
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Ol < ReverseAsciidoctor::Converters::Base
7
+ def convert(node, state = {})
8
+ id = node['id']
9
+ anchor = id ? "[[#{id}]]\n" : ""
10
+ ol_count = state.fetch(:ol_count, 0) + 1
11
+ attrs = ol_attrs(node)
12
+ res = "\n#{anchor}#{attrs}#{treat_children(node, state.merge(ol_count: ol_count))}"
13
+ res = "\n" + res if node.parent && node.parent.name == 'note'
14
+ res
15
+ end
16
+
17
+ def number_style(node)
18
+ style = case node["style"]
19
+ when "1" then "arabic"
20
+ when "A" then "upperalpha"
21
+ when "a" then "loweralpha"
22
+ when "I" then "upperroman"
23
+ when "i" then "lowerroman"
24
+ else
25
+ nil
26
+ end
27
+ end
28
+
29
+ def ol_attrs(node)
30
+ style = number_style(node)
31
+ reversed = "%reversed" if node["reversed"]
32
+ start = "start=#{node['start']}" if node["start"]
33
+ type = "type=#{node['type']}" if node["type"]
34
+ attrs = []
35
+ attrs << style if style
36
+ attrs << reversed if reversed
37
+ attrs << start if start
38
+ attrs << type if type
39
+ if attrs.empty?
40
+ ""
41
+ else
42
+ "[#{attrs.join(',')}]\n"
43
+ end
44
+ end
45
+ end
46
+
47
+ ReverseAsciidoctor::Converters.register :ol, Ol.new
48
+ ReverseAsciidoctor::Converters.register :ul, Ol.new
49
+ ReverseAsciidoctor::Converters.register :dir, Ol.new
50
+ end
51
+ end
52
+ end
@@ -1,11 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'stepmod/utils/converters/synonym'
4
+
3
5
  module Stepmod
4
6
  module Utils
5
7
  module Converters
6
8
  class Term < ReverseAsciidoctor::Converters::Base
7
9
  def convert(node, state = {})
8
- "=== #{treat_children(node, state).strip}"
10
+ first_child = node.children.find do |child|
11
+ child.name == 'text' && !child.text.to_s.strip.empty?
12
+ end
13
+ unless first_child &&
14
+ node.text.split(';').length == 2 &&
15
+ defined?(Stepmod::Utils::Converters::Synonym)
16
+ return "=== #{treat_children(node, state).strip}"
17
+ end
18
+
19
+ term_def, alt = node.text.split(';')
20
+ alt_xml = Nokogiri::XML::Text.new(alt, Nokogiri::XML::Document.new)
21
+ converted_alt = Stepmod::Utils::Converters::Synonym.new.convert(alt_xml)
22
+ "=== #{term_def}\n\n#{converted_alt}"
9
23
  end
10
24
  end
11
25
 
@@ -9,6 +9,7 @@ require 'stepmod/utils/converters/definition'
9
9
  require 'stepmod/utils/converters/em'
10
10
  require 'stepmod/utils/converters/example'
11
11
  require 'stepmod/utils/converters/note'
12
+ require 'stepmod/utils/converters/ol'
12
13
  require 'stepmod/utils/converters/stem'
13
14
  require 'stepmod/utils/converters/term'
14
15
  require 'stepmod/utils/converters/synonym'
@@ -23,7 +24,6 @@ require 'reverse_asciidoctor/converters/head'
23
24
  require 'reverse_asciidoctor/converters/hr'
24
25
  require 'reverse_asciidoctor/converters/ignore'
25
26
  require 'reverse_asciidoctor/converters/li'
26
- require 'reverse_asciidoctor/converters/ol'
27
27
  require 'reverse_asciidoctor/converters/p'
28
28
  require 'reverse_asciidoctor/converters/pass_through'
29
29
  require 'reverse_asciidoctor/converters/q'
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepmod-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -86,6 +86,7 @@ files:
86
86
  - lib/stepmod/utils/converters/express_ref.rb
87
87
  - lib/stepmod/utils/converters/module_ref.rb
88
88
  - lib/stepmod/utils/converters/note.rb
89
+ - lib/stepmod/utils/converters/ol.rb
89
90
  - lib/stepmod/utils/converters/stem.rb
90
91
  - lib/stepmod/utils/converters/synonym.rb
91
92
  - lib/stepmod/utils/converters/term.rb