stepmod-utils 0.1.6 → 0.2.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 +4 -4
- data/.github/workflows/rake.yml +51 -0
- data/.github/workflows/release.yml +20 -22
- data/Gemfile +2 -0
- data/Makefile +2 -0
- data/README.adoc +136 -2
- data/exe/stepmod-annotate +44 -0
- data/exe/stepmod-annotate-all +39 -0
- data/exe/stepmod-build-resource-docs-cache +19 -0
- data/exe/stepmod-convert-express-description +33 -0
- data/exe/stepmod-convert-express-resource +33 -0
- data/exe/stepmod-extract-terms +61 -12
- data/exe/stepmod-find-express-files +23 -0
- data/lib/stepmod/utils/cleaner.rb +11 -0
- data/lib/stepmod/utils/concept.rb +16 -3
- data/lib/stepmod/utils/converters/a.rb +47 -0
- data/lib/stepmod/utils/converters/blockquote.rb +22 -0
- data/lib/stepmod/utils/converters/br.rb +15 -0
- data/lib/stepmod/utils/converters/bypass.rb +81 -0
- data/lib/stepmod/utils/converters/code.rb +19 -0
- data/lib/stepmod/utils/converters/comment.rb +16 -0
- data/lib/stepmod/utils/converters/dd.rb +15 -0
- data/lib/stepmod/utils/converters/def.rb +11 -4
- data/lib/stepmod/utils/converters/dl.rb +31 -0
- data/lib/stepmod/utils/converters/drop.rb +22 -0
- data/lib/stepmod/utils/converters/dt.rb +17 -0
- data/lib/stepmod/utils/converters/em_express_description.rb +22 -0
- data/lib/stepmod/utils/converters/eqn.rb +96 -0
- data/lib/stepmod/utils/converters/example.rb +1 -6
- data/lib/stepmod/utils/converters/express_g.rb +46 -0
- data/lib/stepmod/utils/converters/express_ref_express_description.rb +13 -0
- data/lib/stepmod/utils/converters/ext_description.rb +16 -0
- data/lib/stepmod/utils/converters/ext_descriptions.rb +14 -0
- data/lib/stepmod/utils/converters/fund_cons.rb +15 -0
- data/lib/stepmod/utils/converters/head.rb +22 -0
- data/lib/stepmod/utils/converters/hr.rb +15 -0
- data/lib/stepmod/utils/converters/ignore.rb +16 -0
- data/lib/stepmod/utils/converters/introduction.rb +15 -0
- data/lib/stepmod/utils/converters/note.rb +1 -6
- data/lib/stepmod/utils/converters/ol.rb +3 -2
- data/lib/stepmod/utils/converters/p.rb +21 -0
- data/lib/stepmod/utils/converters/pass_through.rb +13 -0
- data/lib/stepmod/utils/converters/q.rb +16 -0
- data/lib/stepmod/utils/converters/resource.rb +14 -0
- data/lib/stepmod/utils/converters/schema.rb +18 -0
- data/lib/stepmod/utils/converters/schema_diag.rb +14 -0
- data/lib/stepmod/utils/converters/strong.rb +21 -0
- data/lib/stepmod/utils/converters/sub.rb +16 -0
- data/lib/stepmod/utils/converters/sup.rb +16 -0
- data/lib/stepmod/utils/converters/text.rb +68 -0
- data/lib/stepmod/utils/html_to_asciimath.rb +157 -0
- data/lib/stepmod/utils/smrl_description_converter.rb +49 -0
- data/lib/stepmod/utils/smrl_resource_converter.rb +67 -0
- data/lib/stepmod/utils/stepmod_file_annotator.rb +54 -0
- data/lib/stepmod/utils/version.rb +1 -1
- data/migrating_from_cvs.adoc +190 -0
- data/stepmod-utils.gemspec +2 -0
- metadata +82 -6
- data/.github/workflows/macos.yml +0 -39
- data/.github/workflows/ubuntu.yml +0 -53
- data/.github/workflows/windows.yml +0 -41
|
@@ -20,11 +20,14 @@ module Stepmod
|
|
|
20
20
|
previous = nil
|
|
21
21
|
result = ''
|
|
22
22
|
converted.each.with_index do |(child, content), i|
|
|
23
|
-
if
|
|
24
|
-
result += "
|
|
23
|
+
if block_tag?(child, previous)
|
|
24
|
+
result += "\n\n"
|
|
25
|
+
elsif comment_tag?(child, previous)
|
|
26
|
+
result += "\n"
|
|
25
27
|
else
|
|
26
|
-
result +=
|
|
28
|
+
result += ' '
|
|
27
29
|
end
|
|
30
|
+
result += content
|
|
28
31
|
previous = child
|
|
29
32
|
end
|
|
30
33
|
result.strip
|
|
@@ -32,7 +35,11 @@ module Stepmod
|
|
|
32
35
|
|
|
33
36
|
def block_tag?(child, previous)
|
|
34
37
|
%w[ul example note alt p].include?(child.name) ||
|
|
35
|
-
(
|
|
38
|
+
(previous && %w[ul example note alt p].include?(previous.name))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def comment_tag?(child, previous)
|
|
42
|
+
child.name == 'comment' || (previous && previous.name === 'comment')
|
|
36
43
|
end
|
|
37
44
|
|
|
38
45
|
def additional_block(node)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class Dl < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
cleaned_node = cleanup_trash_tags(node.clone)
|
|
9
|
+
treat_children(cleaned_node, state)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
# https://github.com/metanorma/stepmod-utils/issues/48#issuecomment-784000377
|
|
15
|
+
# For simplicity reasons and so that we don't depend on the CVS repository's updates, we directly converting:
|
|
16
|
+
# <dt></dt><dd>a3ma   :   annotated 3d model assembly</dd> into a3ma:: annotated 3d model assembly
|
|
17
|
+
def cleanup_trash_tags(node)
|
|
18
|
+
inner_content = node.inner_html
|
|
19
|
+
inner_content
|
|
20
|
+
.gsub!(/<dt><\/dt>\s*?<dd>(.+?)   :   (.+?)<\/dd>/) do
|
|
21
|
+
"<dt>#{$1}</dt><dd>#{$2}</dd>"
|
|
22
|
+
end
|
|
23
|
+
node.inner_html = inner_content
|
|
24
|
+
node
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
ReverseAdoc::Converters.register :dl, Dl.new
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class Drop < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
''
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
ReverseAdoc::Converters.register :caption, Drop.new
|
|
13
|
+
ReverseAdoc::Converters.register :figcaption, Drop.new
|
|
14
|
+
ReverseAdoc::Converters.register :title, Drop.new
|
|
15
|
+
ReverseAdoc::Converters.register :link, Drop.new
|
|
16
|
+
ReverseAdoc::Converters.register :style, Drop.new
|
|
17
|
+
ReverseAdoc::Converters.register :meta, Drop.new
|
|
18
|
+
ReverseAdoc::Converters.register :script, Drop.new
|
|
19
|
+
ReverseAdoc::Converters.register :comment, Drop.new
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class Dt < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
return "\n\n{blank}::" if node.text.strip.length.zero?
|
|
9
|
+
|
|
10
|
+
"\n\n#{node.text}:: "
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
ReverseAdoc::Converters.register :dt, Dt.new
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class Em < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
content = treat_children(node, state.merge(already_italic: true))
|
|
9
|
+
if content.strip.empty? || state[:already_italic]
|
|
10
|
+
content
|
|
11
|
+
else
|
|
12
|
+
"#{content[/^\s*/]}_#{content.strip}_#{content[/\s*$/]}"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
ReverseAdoc::Converters.register :em, Em.new
|
|
18
|
+
ReverseAdoc::Converters.register :i, Em.new
|
|
19
|
+
ReverseAdoc::Converters.register :cite, Em.new
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'stepmod/utils/html_to_asciimath'
|
|
4
|
+
|
|
5
|
+
module Stepmod
|
|
6
|
+
module Utils
|
|
7
|
+
module Converters
|
|
8
|
+
class Eqn < ReverseAdoc::Converters::Base
|
|
9
|
+
TAGS_NOT_IN_CONTEXT = %w[b i].freeze
|
|
10
|
+
|
|
11
|
+
def convert(node, state = {})
|
|
12
|
+
cloned_node = node.clone
|
|
13
|
+
if definition_node?(cloned_node)
|
|
14
|
+
return definition_converted(cloned_node, state)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
stem_converted(cloned_node, state)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def definition_node?(node)
|
|
23
|
+
first_strong_node = node
|
|
24
|
+
.children
|
|
25
|
+
.find do |n|
|
|
26
|
+
return false if !n.text? && n.name != 'b'
|
|
27
|
+
|
|
28
|
+
n.name == 'b'
|
|
29
|
+
end
|
|
30
|
+
first_strong_node &&
|
|
31
|
+
first_strong_node.next &&
|
|
32
|
+
first_strong_node.next.text? &&
|
|
33
|
+
first_strong_node.next.content =~ /\s+:/
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def definition_converted(cloned_node, state)
|
|
37
|
+
first_strong_node = cloned_node
|
|
38
|
+
.children
|
|
39
|
+
.find do |n|
|
|
40
|
+
return false if !n.text? && n.name != 'b'
|
|
41
|
+
|
|
42
|
+
n.name == 'b'
|
|
43
|
+
end
|
|
44
|
+
first_strong_node.next.content = first_strong_node.next.content.gsub(/\s?:/, '')
|
|
45
|
+
term = first_strong_node.text.strip
|
|
46
|
+
first_strong_node.remove
|
|
47
|
+
"#{term}:: #{treat_children(cloned_node, state)}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def stem_converted(cloned_node, state)
|
|
51
|
+
remove_tags_not_in_context(cloned_node)
|
|
52
|
+
internal_content = treat_children(cloned_node, state)
|
|
53
|
+
content = Stepmod::Utils::HtmlToAsciimath.new.call(internal_content)
|
|
54
|
+
res = <<~TEMPLATE
|
|
55
|
+
|
|
56
|
+
[stem]
|
|
57
|
+
++++
|
|
58
|
+
#{remove_trash_symbols(content.strip)}
|
|
59
|
+
++++
|
|
60
|
+
|
|
61
|
+
TEMPLATE
|
|
62
|
+
res = "[[#{cloned_node['id']}]]\n#{res}" if cloned_node['id'] && cloned_node['id'].length > 0
|
|
63
|
+
res
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def remove_trash_symbols(content)
|
|
67
|
+
content
|
|
68
|
+
.gsub(/ /, '')
|
|
69
|
+
.strip
|
|
70
|
+
.gsub(/\(\d\)$/, '')
|
|
71
|
+
.gsub(/\b(\w*?[_]+\w+)\b/, '"\1"')
|
|
72
|
+
.strip
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Remove all tags that make no sense in equations, eg: strong, italic
|
|
76
|
+
# Search for such tags, move their children into the root
|
|
77
|
+
# context and remove them
|
|
78
|
+
def remove_tags_not_in_context(node)
|
|
79
|
+
TAGS_NOT_IN_CONTEXT.each do |tag_name|
|
|
80
|
+
node
|
|
81
|
+
.children
|
|
82
|
+
.xpath("./#{tag_name}")
|
|
83
|
+
.map do |n|
|
|
84
|
+
n.tap{ |n| n.add_previous_sibling(n.children) }.remove
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
node.traverse do |descendant|
|
|
88
|
+
descendant.content = descendant.content.gsub('#8195;', '')
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
ReverseAdoc::Converters.register :eqn, Eqn.new
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -5,12 +5,7 @@ module Stepmod
|
|
|
5
5
|
module Converters
|
|
6
6
|
class Example < ReverseAdoc::Converters::Base
|
|
7
7
|
def convert(node, state = {})
|
|
8
|
-
|
|
9
|
-
[example]
|
|
10
|
-
====
|
|
11
|
-
#{treat_children(node, state).strip}
|
|
12
|
-
====
|
|
13
|
-
TEMPLATE
|
|
8
|
+
"\n\n[example]\n====\n#{treat_children(node, state).strip}\n====\n\n"
|
|
14
9
|
end
|
|
15
10
|
end
|
|
16
11
|
ReverseAdoc::Converters.register :example, Example.new
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class ExpressG < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
node.children.map do |child|
|
|
9
|
+
next unless child.name == 'imgfile'
|
|
10
|
+
|
|
11
|
+
parse_to_svg_reference(child['file'])
|
|
12
|
+
end.join("\n")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def parse_to_svg_reference(file)
|
|
18
|
+
return '' unless File.file?(file)
|
|
19
|
+
|
|
20
|
+
image_document = Nokogiri::XML(File.read(file))
|
|
21
|
+
svg_path = File.basename(image_document.xpath('//img').first['src'], '.*')
|
|
22
|
+
<<~SVGMAP
|
|
23
|
+
[.svgmap]
|
|
24
|
+
====
|
|
25
|
+
image::#{svg_path}.svg[]
|
|
26
|
+
|
|
27
|
+
#{image_document.xpath('//img.area').map.with_index(1) {|n, i| schema_reference(n['href'], i) }.join("\n")}
|
|
28
|
+
====
|
|
29
|
+
SVGMAP
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def schema_reference(xml_path, index)
|
|
33
|
+
if xml_path =~ /#/
|
|
34
|
+
_,express_path_part = xml_path.split('#')
|
|
35
|
+
"* <<express:#{express_path_part.strip}>>; #{index}"
|
|
36
|
+
else
|
|
37
|
+
schema_name = File.basename(xml_path, '.*')
|
|
38
|
+
"* <<express:#{schema_name.strip}>>; #{index}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
ReverseAdoc::Converters.register 'express-g', ExpressG.new
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Stepmod
|
|
2
|
+
module Utils
|
|
3
|
+
module Converters
|
|
4
|
+
class ExpressRefExpressDescription < ReverseAdoc::Converters::Base
|
|
5
|
+
def convert(node, _state = {})
|
|
6
|
+
parts = node['linkend'].to_s.split(':').last.split('.')
|
|
7
|
+
"<<express:#{parts.join('.').strip},#{parts.last.strip}>>"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
ReverseAdoc::Converters.register :express_ref, ExpressRefExpressDescription.new
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Stepmod
|
|
2
|
+
module Utils
|
|
3
|
+
module Converters
|
|
4
|
+
class ExtDescription < ReverseAdoc::Converters::Base
|
|
5
|
+
def convert(node, state = {})
|
|
6
|
+
<<~TEMPLATE
|
|
7
|
+
(*"#{node['linkend']}"
|
|
8
|
+
#{treat_children(node, state).strip}
|
|
9
|
+
*)
|
|
10
|
+
TEMPLATE
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
ReverseAdoc::Converters.register :ext_description, ExtDescription.new
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class ExtDescriptions < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
treat_children(node, state)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
ReverseAdoc::Converters.register :ext_descriptions, ExtDescriptions.new
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class FundCons < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
"\n\n== Fundamental concerns\n\n#{treat_children(node, state).strip}\n\n"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
ReverseAdoc::Converters.register :fund_cons, FundCons.new
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class Head < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
title = extract_title(node)
|
|
9
|
+
"= #{title}\n:stem:\n\n"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def extract_title(node)
|
|
13
|
+
title = node.at("./title")
|
|
14
|
+
return "(???)" if title.nil?
|
|
15
|
+
title.text
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
ReverseAdoc::Converters.register :head, Head.new
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class Hr < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
"\n* * *\n"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
ReverseAdoc::Converters.register :hr, Hr.new
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class Ignore < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
'' # noop
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
ReverseAdoc::Converters.register :colgroup, Ignore.new
|
|
13
|
+
ReverseAdoc::Converters.register :col, Ignore.new
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Stepmod
|
|
4
|
+
module Utils
|
|
5
|
+
module Converters
|
|
6
|
+
class Introduction < ReverseAdoc::Converters::Base
|
|
7
|
+
def convert(node, state = {})
|
|
8
|
+
"\n\n== Introduction\n\n#{treat_children(node, state).strip}\n\n"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
ReverseAdoc::Converters.register :introduction, Introduction.new
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -5,12 +5,7 @@ module Stepmod
|
|
|
5
5
|
module Converters
|
|
6
6
|
class Note < ReverseAdoc::Converters::Base
|
|
7
7
|
def convert(node, state = {})
|
|
8
|
-
|
|
9
|
-
[NOTE]
|
|
10
|
-
--
|
|
11
|
-
#{treat_children(node, state).strip}
|
|
12
|
-
--
|
|
13
|
-
TEMPLATE
|
|
8
|
+
"\n\n[NOTE]\n--\n#{treat_children(node, state).strip}\n--\n\n"
|
|
14
9
|
end
|
|
15
10
|
end
|
|
16
11
|
ReverseAdoc::Converters.register :note, Note.new
|