stepmod-utils 0.3.5 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -1
- data/.github/workflows/release.yml +4 -3
- data/.rubocop.yml +1 -1
- data/Gemfile +3 -3
- data/Rakefile +1 -1
- data/exe/stepmod-annotate-all +17 -11
- data/exe/stepmod-build-resource-docs-cache +8 -7
- data/exe/stepmod-convert-express-description +6 -4
- data/exe/stepmod-convert-express-resource +6 -4
- data/exe/stepmod-extract-terms +99 -28
- data/exe/stepmod-find-express-files +8 -7
- data/lib/stepmod/utils/bibdata.rb +31 -35
- data/lib/stepmod/utils/cleaner.rb +3 -3
- data/lib/stepmod/utils/concept.rb +54 -36
- data/lib/stepmod/utils/converters/a.rb +6 -13
- data/lib/stepmod/utils/converters/blockquote.rb +4 -4
- data/lib/stepmod/utils/converters/br.rb +1 -1
- data/lib/stepmod/utils/converters/bypass.rb +33 -33
- data/lib/stepmod/utils/converters/clause_ref.rb +3 -3
- data/lib/stepmod/utils/converters/code.rb +1 -1
- data/lib/stepmod/utils/converters/comment.rb +5 -3
- data/lib/stepmod/utils/converters/dd.rb +2 -2
- data/lib/stepmod/utils/converters/def.rb +19 -19
- data/lib/stepmod/utils/converters/drop.rb +2 -2
- data/lib/stepmod/utils/converters/dt.rb +2 -2
- data/lib/stepmod/utils/converters/em.rb +1 -1
- data/lib/stepmod/utils/converters/em_express_description.rb +1 -1
- data/lib/stepmod/utils/converters/eqn.rb +28 -26
- data/lib/stepmod/utils/converters/example.rb +5 -6
- data/lib/stepmod/utils/converters/express_g.rb +10 -9
- data/lib/stepmod/utils/converters/express_ref.rb +2 -2
- data/lib/stepmod/utils/converters/express_ref_express_description.rb +3 -2
- data/lib/stepmod/utils/converters/ext_description.rb +1 -1
- data/lib/stepmod/utils/converters/figure.rb +3 -3
- data/lib/stepmod/utils/converters/fund_cons.rb +1 -1
- data/lib/stepmod/utils/converters/head.rb +3 -2
- data/lib/stepmod/utils/converters/hr.rb +2 -2
- data/lib/stepmod/utils/converters/ignore.rb +3 -3
- data/lib/stepmod/utils/converters/introduction.rb +1 -1
- data/lib/stepmod/utils/converters/module_ref.rb +7 -7
- data/lib/stepmod/utils/converters/note.rb +5 -6
- data/lib/stepmod/utils/converters/ol.rb +7 -5
- data/lib/stepmod/utils/converters/p.rb +2 -2
- data/lib/stepmod/utils/converters/pass_through.rb +2 -2
- data/lib/stepmod/utils/converters/q.rb +1 -1
- data/lib/stepmod/utils/converters/schema.rb +1 -1
- data/lib/stepmod/utils/converters/stem.rb +1 -1
- data/lib/stepmod/utils/converters/stepmod_ext_description.rb +20 -6
- data/lib/stepmod/utils/converters/strong.rb +7 -4
- data/lib/stepmod/utils/converters/sub.rb +2 -2
- data/lib/stepmod/utils/converters/sup.rb +2 -2
- data/lib/stepmod/utils/converters/synonym.rb +2 -2
- data/lib/stepmod/utils/converters/table.rb +7 -9
- data/lib/stepmod/utils/converters/term.rb +27 -9
- data/lib/stepmod/utils/converters/text.rb +11 -13
- data/lib/stepmod/utils/converters/uof.rb +3 -4
- data/lib/stepmod/utils/html_to_asciimath.rb +91 -90
- data/lib/stepmod/utils/smrl_description_converter.rb +34 -33
- data/lib/stepmod/utils/smrl_resource_converter.rb +50 -49
- data/lib/stepmod/utils/stepmod_definition_converter.rb +39 -38
- data/lib/stepmod/utils/stepmod_file_annotator.rb +26 -19
- data/lib/stepmod/utils/terms_extractor.rb +138 -86
- data/lib/stepmod/utils/version.rb +1 -1
- data/stepmod-utils.gemspec +11 -6
- metadata +62 -20
@@ -1,39 +1,29 @@
|
|
1
|
+
require "glossarist"
|
2
|
+
|
1
3
|
module Stepmod
|
2
4
|
module Utils
|
3
|
-
|
4
|
-
class Concept
|
5
|
+
class Concept < Glossarist::LocalizedConcept
|
5
6
|
attr_accessor *%w(
|
6
|
-
designation
|
7
|
-
definition
|
8
|
-
reference_anchor
|
9
7
|
reference_clause
|
10
|
-
|
11
|
-
notes
|
12
|
-
synonym
|
8
|
+
reference_anchor
|
13
9
|
converted_definition
|
14
10
|
file_path
|
15
11
|
)
|
16
12
|
|
17
|
-
def initialize(options)
|
18
|
-
options.each_pair do |k, v|
|
19
|
-
send("#{k}=", v)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
13
|
class << self
|
24
|
-
def parse(definition_xml, reference_anchor:, reference_clause:, file_path:)
|
14
|
+
def parse(definition_xml, reference_anchor:, reference_clause:, file_path:, language_code: "en")
|
25
15
|
converted_definition = Stepmod::Utils::StepmodDefinitionConverter.convert(
|
26
16
|
definition_xml,
|
27
17
|
{
|
28
18
|
# We don't want examples and notes
|
29
19
|
no_notes_examples: true,
|
30
|
-
reference_anchor: reference_anchor
|
31
|
-
}
|
20
|
+
reference_anchor: reference_anchor,
|
21
|
+
},
|
32
22
|
)
|
33
23
|
|
34
24
|
return nil if converted_definition.nil? || converted_definition.strip.empty?
|
35
25
|
|
36
|
-
if definition_xml.name ==
|
26
|
+
if definition_xml.name == "ext_description"
|
37
27
|
converted_definition = <<~TEXT
|
38
28
|
#{converted_definition}
|
39
29
|
|
@@ -41,37 +31,62 @@ module Stepmod
|
|
41
31
|
Reference <<#{reference_anchor}>> for the complete definition.
|
42
32
|
TEXT
|
43
33
|
end
|
34
|
+
|
44
35
|
# https://github.com/metanorma/stepmod-utils/issues/86
|
45
|
-
|
36
|
+
|
37
|
+
# TODO: This portion DOES NOT HANDLE the <synonym> element. WTF??
|
38
|
+
if definition_xml.name == "definition"
|
46
39
|
designation = definition_designation(definition_xml)
|
47
|
-
definition = definition_xml_definition(definition_xml,
|
48
|
-
|
40
|
+
definition = definition_xml_definition(definition_xml,
|
41
|
+
reference_anchor)
|
42
|
+
converted_definition = definition_xml_converted_definition(
|
43
|
+
designation, definition
|
44
|
+
).strip
|
49
45
|
end
|
46
|
+
|
50
47
|
new(
|
51
|
-
|
48
|
+
designations: [designation],
|
52
49
|
definition: definition,
|
53
50
|
converted_definition: converted_definition,
|
51
|
+
id: "#{reference_anchor}.#{reference_clause}",
|
54
52
|
reference_anchor: reference_anchor,
|
55
53
|
reference_clause: reference_clause,
|
56
|
-
file_path: file_path
|
54
|
+
file_path: file_path,
|
55
|
+
language_code: language_code,
|
57
56
|
)
|
58
57
|
end
|
59
58
|
|
60
59
|
def definition_designation(definition_xml)
|
61
|
-
|
60
|
+
# We take the <p> that is an alternative term (length<=20).
|
61
|
+
# Add in the <synonym> elements.
|
62
|
+
alts = definition_xml.xpath(".//synonym").map(&:text) +
|
63
|
+
definition_xml.xpath(".//def/p").map(&:text).reject do |text|
|
64
|
+
text.length > 20
|
65
|
+
end
|
66
|
+
|
67
|
+
term = Stepmod::Utils::Converters::Term
|
68
|
+
.new
|
69
|
+
.convert(
|
70
|
+
definition_xml.xpath(".//term").first
|
71
|
+
)
|
72
|
+
|
62
73
|
{
|
63
|
-
|
64
|
-
|
74
|
+
# [4..-1] because we want to skip the initial `=== {title}`
|
75
|
+
accepted: term[4..-1],
|
76
|
+
alt: alts,
|
65
77
|
}
|
66
78
|
end
|
67
79
|
|
68
80
|
def definition_xml_definition(definition_xml, reference_anchor)
|
81
|
+
# We reject the <p> that was considered an alternative term (length<=20)
|
69
82
|
text_nodes = definition_xml
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
83
|
+
.xpath(".//def")
|
84
|
+
.first
|
85
|
+
.children
|
86
|
+
.reject { |n| n.name == "p" && n.text.length <= 20 }
|
87
|
+
|
74
88
|
wrapper = "<def>#{text_nodes.map(&:to_s).join}</def>"
|
89
|
+
|
75
90
|
Stepmod::Utils::Converters::Def
|
76
91
|
.new
|
77
92
|
.convert(
|
@@ -79,23 +94,27 @@ module Stepmod
|
|
79
94
|
{
|
80
95
|
# We don't want examples and notes
|
81
96
|
no_notes_examples: true,
|
82
|
-
reference_anchor: reference_anchor
|
83
|
-
}
|
97
|
+
reference_anchor: reference_anchor,
|
98
|
+
},
|
99
|
+
)
|
84
100
|
end
|
85
101
|
|
86
102
|
def definition_xml_converted_definition(designation, definition)
|
87
103
|
if designation[:alt].length.positive?
|
88
104
|
alt_notation = "alt:[#{designation[:alt].map(&:strip).join(',')}]"
|
89
105
|
end
|
106
|
+
|
90
107
|
result = <<~TEXT
|
91
|
-
=== #{designation[:accepted]}
|
108
|
+
=== #{designation[:accepted].strip}
|
92
109
|
TEXT
|
110
|
+
|
93
111
|
if alt_notation
|
94
112
|
result += <<~TEXT
|
95
113
|
|
96
114
|
#{alt_notation}
|
97
115
|
TEXT
|
98
116
|
end
|
117
|
+
|
99
118
|
<<~TEXT
|
100
119
|
#{result}
|
101
120
|
#{definition}
|
@@ -105,15 +124,14 @@ module Stepmod
|
|
105
124
|
|
106
125
|
def to_mn_adoc
|
107
126
|
<<~TEXT
|
108
|
-
// STEPmod path:#{!file_path.empty? ? " #{file_path}" :
|
127
|
+
// STEPmod path:#{!file_path.empty? ? " #{file_path}" : ''}
|
109
128
|
#{converted_definition}
|
110
129
|
|
111
130
|
[.source]
|
112
|
-
<<#{reference_anchor}#{reference_clause ? ",clause
|
131
|
+
<<#{reference_anchor}#{reference_clause ? ",clause=#{reference_clause}" : ''}>>
|
113
132
|
|
114
133
|
TEXT
|
115
134
|
end
|
116
|
-
|
117
135
|
end
|
118
136
|
end
|
119
137
|
end
|
@@ -1,24 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "uri"
|
4
|
-
|
5
3
|
module Stepmod
|
6
4
|
module Utils
|
7
5
|
module Converters
|
8
6
|
class A < ReverseAdoc::Converters::Base
|
9
7
|
def convert(node, state = {})
|
10
8
|
name = treat_children(node, state)
|
11
|
-
href = node[
|
9
|
+
href = node["href"]
|
12
10
|
title = extract_title(node)
|
13
|
-
id = node[
|
11
|
+
id = node["id"] || node["name"]
|
14
12
|
|
15
13
|
id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")
|
16
14
|
|
17
|
-
if /^_Toc\d+$|^_GoBack$/.match id
|
15
|
+
if /^_Toc\d+$|^_GoBack$/.match? id
|
18
16
|
""
|
19
17
|
elsif !id.nil? && !id.empty?
|
20
18
|
"[[#{id}]]"
|
21
|
-
elsif href.to_s.start_with?(
|
19
|
+
elsif href.to_s.start_with?("#")
|
22
20
|
href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
|
23
21
|
if name.empty?
|
24
22
|
"<<#{href}>>"
|
@@ -29,16 +27,11 @@ module Stepmod
|
|
29
27
|
name
|
30
28
|
else
|
31
29
|
name = title if name.empty?
|
32
|
-
href = "link:#{href}" unless href.to_s
|
30
|
+
href = "link:#{href}" unless href.to_s&.match?(URI::DEFAULT_PARSER.make_regexp)
|
33
31
|
link = "#{href}[#{name}]"
|
34
|
-
#
|
35
|
-
link = " #{link}"
|
36
|
-
link
|
32
|
+
" #{link}"
|
37
33
|
end
|
38
34
|
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
35
|
end
|
43
36
|
|
44
37
|
ReverseAdoc::Converters.register :a, A.new
|
@@ -5,14 +5,14 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class Blockquote < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
|
-
id = node[
|
8
|
+
id = node["id"]
|
9
9
|
anchor = id ? "[[#{id}]]\n" : ""
|
10
|
-
cite = node[
|
10
|
+
cite = node["cite"]
|
11
11
|
attrs = cite ? "[quote, #{cite}]\n" : ""
|
12
12
|
content = treat_children(node, state).strip
|
13
13
|
content = ReverseAdoc.cleaner.remove_newlines(content)
|
14
|
-
#"\n\n> " << content.lines.to_a.join('> ') << "\n\n"
|
15
|
-
"\n\n#{attrs}____\n" << content.lines.to_a.join(
|
14
|
+
# "\n\n> " << content.lines.to_a.join('> ') << "\n\n"
|
15
|
+
"\n\n#{attrs}____\n" << content.lines.to_a.join("") << "\n____\n\n"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -16,66 +16,66 @@ module Stepmod
|
|
16
16
|
ReverseAdoc::Converters.register :thead, Bypass.new
|
17
17
|
ReverseAdoc::Converters.register :tbody, Bypass.new
|
18
18
|
ReverseAdoc::Converters.register :tfoot, Bypass.new
|
19
|
-
ReverseAdoc::Converters.register :abbr,
|
19
|
+
ReverseAdoc::Converters.register :abbr, Bypass.new
|
20
20
|
ReverseAdoc::Converters.register :acronym, Bypass.new
|
21
21
|
ReverseAdoc::Converters.register :address, Bypass.new
|
22
|
-
ReverseAdoc::Converters.register :applet,
|
23
|
-
ReverseAdoc::Converters.register :map,
|
24
|
-
ReverseAdoc::Converters.register :area,
|
22
|
+
ReverseAdoc::Converters.register :applet, Bypass.new
|
23
|
+
ReverseAdoc::Converters.register :map, Bypass.new
|
24
|
+
ReverseAdoc::Converters.register :area, Bypass.new
|
25
25
|
ReverseAdoc::Converters.register :bdi, Bypass.new
|
26
26
|
ReverseAdoc::Converters.register :bdo, Bypass.new
|
27
27
|
ReverseAdoc::Converters.register :big, Bypass.new
|
28
28
|
ReverseAdoc::Converters.register :button, Bypass.new
|
29
29
|
ReverseAdoc::Converters.register :canvas, Bypass.new
|
30
|
-
ReverseAdoc::Converters.register :data,
|
31
|
-
ReverseAdoc::Converters.register :datalist,
|
30
|
+
ReverseAdoc::Converters.register :data, Bypass.new
|
31
|
+
ReverseAdoc::Converters.register :datalist, Bypass.new
|
32
32
|
ReverseAdoc::Converters.register :del, Bypass.new
|
33
33
|
ReverseAdoc::Converters.register :ins, Bypass.new
|
34
34
|
ReverseAdoc::Converters.register :dfn, Bypass.new
|
35
|
-
ReverseAdoc::Converters.register :dialog,
|
36
|
-
ReverseAdoc::Converters.register :embed,
|
37
|
-
ReverseAdoc::Converters.register :fieldset,
|
38
|
-
ReverseAdoc::Converters.register :font,
|
39
|
-
ReverseAdoc::Converters.register :footer,
|
40
|
-
ReverseAdoc::Converters.register :form,
|
41
|
-
ReverseAdoc::Converters.register :frame,
|
42
|
-
ReverseAdoc::Converters.register :frameset,
|
35
|
+
ReverseAdoc::Converters.register :dialog, Bypass.new
|
36
|
+
ReverseAdoc::Converters.register :embed, Bypass.new
|
37
|
+
ReverseAdoc::Converters.register :fieldset, Bypass.new
|
38
|
+
ReverseAdoc::Converters.register :font, Bypass.new
|
39
|
+
ReverseAdoc::Converters.register :footer, Bypass.new
|
40
|
+
ReverseAdoc::Converters.register :form, Bypass.new
|
41
|
+
ReverseAdoc::Converters.register :frame, Bypass.new
|
42
|
+
ReverseAdoc::Converters.register :frameset, Bypass.new
|
43
43
|
ReverseAdoc::Converters.register :header, Bypass.new
|
44
44
|
ReverseAdoc::Converters.register :iframe, Bypass.new
|
45
45
|
ReverseAdoc::Converters.register :input, Bypass.new
|
46
46
|
ReverseAdoc::Converters.register :label, Bypass.new
|
47
|
-
ReverseAdoc::Converters.register :legend,
|
47
|
+
ReverseAdoc::Converters.register :legend, Bypass.new
|
48
48
|
ReverseAdoc::Converters.register :main, Bypass.new
|
49
49
|
ReverseAdoc::Converters.register :menu, Bypass.new
|
50
|
-
ReverseAdoc::Converters.register :menulist,
|
51
|
-
ReverseAdoc::Converters.register :meter,
|
52
|
-
ReverseAdoc::Converters.register :nav,
|
50
|
+
ReverseAdoc::Converters.register :menulist, Bypass.new
|
51
|
+
ReverseAdoc::Converters.register :meter, Bypass.new
|
52
|
+
ReverseAdoc::Converters.register :nav, Bypass.new
|
53
53
|
ReverseAdoc::Converters.register :noframes, Bypass.new
|
54
54
|
ReverseAdoc::Converters.register :noscript, Bypass.new
|
55
|
-
ReverseAdoc::Converters.register :object,
|
56
|
-
ReverseAdoc::Converters.register :optgroup,
|
55
|
+
ReverseAdoc::Converters.register :object, Bypass.new
|
56
|
+
ReverseAdoc::Converters.register :optgroup, Bypass.new
|
57
57
|
ReverseAdoc::Converters.register :option, Bypass.new
|
58
58
|
ReverseAdoc::Converters.register :output, Bypass.new
|
59
|
-
ReverseAdoc::Converters.register :param,
|
60
|
-
ReverseAdoc::Converters.register :picture,
|
61
|
-
ReverseAdoc::Converters.register :progress,
|
62
|
-
ReverseAdoc::Converters.register :ruby,
|
59
|
+
ReverseAdoc::Converters.register :param, Bypass.new
|
60
|
+
ReverseAdoc::Converters.register :picture, Bypass.new
|
61
|
+
ReverseAdoc::Converters.register :progress, Bypass.new
|
62
|
+
ReverseAdoc::Converters.register :ruby, Bypass.new
|
63
63
|
ReverseAdoc::Converters.register :rt, Bypass.new
|
64
64
|
ReverseAdoc::Converters.register :rp, Bypass.new
|
65
|
-
ReverseAdoc::Converters.register :s,
|
66
|
-
ReverseAdoc::Converters.register :select,
|
67
|
-
ReverseAdoc::Converters.register :small,
|
68
|
-
ReverseAdoc::Converters.register :span,
|
69
|
-
ReverseAdoc::Converters.register :strike,
|
65
|
+
ReverseAdoc::Converters.register :s, Bypass.new
|
66
|
+
ReverseAdoc::Converters.register :select, Bypass.new
|
67
|
+
ReverseAdoc::Converters.register :small, Bypass.new
|
68
|
+
ReverseAdoc::Converters.register :span, Bypass.new
|
69
|
+
ReverseAdoc::Converters.register :strike, Bypass.new
|
70
70
|
ReverseAdoc::Converters.register :details, Bypass.new
|
71
71
|
ReverseAdoc::Converters.register :section, Bypass.new
|
72
72
|
ReverseAdoc::Converters.register :summary, Bypass.new
|
73
|
-
ReverseAdoc::Converters.register :svg,
|
73
|
+
ReverseAdoc::Converters.register :svg, Bypass.new
|
74
74
|
ReverseAdoc::Converters.register :template, Bypass.new
|
75
75
|
ReverseAdoc::Converters.register :textarea, Bypass.new
|
76
|
-
ReverseAdoc::Converters.register :track,
|
77
|
-
ReverseAdoc::Converters.register :u,
|
78
|
-
ReverseAdoc::Converters.register :wbr,
|
76
|
+
ReverseAdoc::Converters.register :track, Bypass.new
|
77
|
+
ReverseAdoc::Converters.register :u, Bypass.new
|
78
|
+
ReverseAdoc::Converters.register :wbr, Bypass.new
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -5,7 +5,7 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class ClauseRef < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, _state = {})
|
8
|
-
"
|
8
|
+
" {{#{normalized_ref(node['linkend'])}}} "
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
@@ -13,10 +13,10 @@ module Stepmod
|
|
13
13
|
def normalized_ref(ref)
|
14
14
|
return unless ref || ref.empty?
|
15
15
|
|
16
|
-
ref.to_s.split(
|
16
|
+
ref.to_s.split(":").last.squeeze(" ").strip
|
17
17
|
end
|
18
18
|
end
|
19
19
|
ReverseAdoc::Converters.register :clause_ref, ClauseRef.new
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
@@ -4,8 +4,10 @@ module Stepmod
|
|
4
4
|
module Utils
|
5
5
|
module Converters
|
6
6
|
class Comment < ReverseAdoc::Converters::Base
|
7
|
-
def convert(node,
|
8
|
-
comment = node.text.strip.split("\n").map
|
7
|
+
def convert(node, _state = {})
|
8
|
+
comment = node.text.strip.split("\n").map do |line|
|
9
|
+
"\n// #{line}"
|
10
|
+
end.join("\n")
|
9
11
|
"#{comment}\n"
|
10
12
|
end
|
11
13
|
end
|
@@ -13,4 +15,4 @@ module Stepmod
|
|
13
15
|
ReverseAdoc::Converters.register :comment, Comment.new
|
14
16
|
end
|
15
17
|
end
|
16
|
-
end
|
18
|
+
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module Stepmod
|
3
2
|
module Utils
|
4
3
|
module Converters
|
@@ -12,30 +11,29 @@ module Stepmod
|
|
12
11
|
|
13
12
|
def treat_children(node, state)
|
14
13
|
converted = node.children.each_with_object({}) do |child, res|
|
15
|
-
|
16
14
|
content = treat(child, state)
|
17
15
|
next if content.strip.empty?
|
18
16
|
|
19
17
|
res[child] = content
|
20
18
|
end
|
21
19
|
previous = nil
|
22
|
-
result =
|
23
|
-
|
24
|
-
converted.each.with_index do |(child, content),
|
25
|
-
if block_tag?(child, previous)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
result = ""
|
21
|
+
|
22
|
+
converted.each.with_index do |(child, content), _i|
|
23
|
+
result += if block_tag?(child, previous)
|
24
|
+
"\n\n"
|
25
|
+
elsif comment_tag?(child, previous)
|
26
|
+
"\n"
|
27
|
+
else
|
28
|
+
" "
|
29
|
+
end
|
32
30
|
result += content
|
33
31
|
previous = child
|
34
32
|
end
|
35
33
|
|
36
34
|
# Remove double newlines for every line
|
37
35
|
result = result.gsub(/\n\n+/, "\n\n")
|
38
|
-
result = result.squeeze(
|
36
|
+
result = result.squeeze(" ")
|
39
37
|
|
40
38
|
result.strip
|
41
39
|
end
|
@@ -46,14 +44,14 @@ module Stepmod
|
|
46
44
|
end
|
47
45
|
|
48
46
|
def comment_tag?(child, previous)
|
49
|
-
child.name ==
|
47
|
+
child.name == "comment" || (previous && previous.name === "comment")
|
50
48
|
end
|
51
49
|
|
52
50
|
def additional_block(node)
|
53
51
|
# Treat first `p` tag as an `alt` block, metanorma/stepmod-utils#9
|
54
52
|
first_child_tag = node
|
55
|
-
|
56
|
-
|
53
|
+
.children
|
54
|
+
.find { |n| n.is_a?(Nokogiri::XML::Element) }
|
57
55
|
return unless can_transform_to_alt?(first_child_tag)
|
58
56
|
|
59
57
|
result = Stepmod::Utils::Converters::Synonym
|
@@ -66,12 +64,14 @@ module Stepmod
|
|
66
64
|
|
67
65
|
# metanorma/stepmod-utils#18 when para is the only text doe snot transform it
|
68
66
|
def can_transform_to_alt?(first_child_tag)
|
69
|
-
return false unless first_child_tag&.name ==
|
70
|
-
|
67
|
+
return false unless first_child_tag&.name == "p" &&
|
68
|
+
defined?(Stepmod::Utils::Converters::Synonym)
|
71
69
|
|
72
70
|
next_sibling = first_child_tag.next
|
73
71
|
while next_sibling
|
74
|
-
return true if !next_sibling.text.to_s.strip.empty? && %w[p
|
72
|
+
return true if !next_sibling.text.to_s.strip.empty? && %w[p
|
73
|
+
text].include?(next_sibling.name)
|
74
|
+
|
75
75
|
next_sibling = next_sibling.next
|
76
76
|
end
|
77
77
|
false
|
@@ -4,7 +4,7 @@ module Stepmod
|
|
4
4
|
module Utils
|
5
5
|
module Converters
|
6
6
|
class Dt < ReverseAdoc::Converters::Base
|
7
|
-
def convert(node,
|
7
|
+
def convert(node, _state = {})
|
8
8
|
return "\n\n{blank}::" if node.text.strip.length.zero?
|
9
9
|
|
10
10
|
"\n\n#{node.text}:: "
|
@@ -14,4 +14,4 @@ module Stepmod
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "stepmod/utils/html_to_asciimath"
|
4
4
|
|
5
5
|
module Stepmod
|
6
6
|
module Utils
|
@@ -21,30 +21,32 @@ module Stepmod
|
|
21
21
|
|
22
22
|
def definition_node?(node)
|
23
23
|
first_strong_node = node
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
first_strong_node &&
|
31
|
-
first_strong_node.next &&
|
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&.next &&
|
32
31
|
first_strong_node.next.text? &&
|
33
32
|
first_strong_node.next.content =~ /\s+:/
|
34
33
|
end
|
35
34
|
|
36
35
|
def definition_converted(cloned_node, state)
|
37
36
|
first_strong_node = cloned_node
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
.children
|
38
|
+
.find do |n|
|
39
|
+
return false if !n.text? && n.name != "b"
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
first_strong_node.next.content = first_strong_node.next.content.gsub(
|
41
|
+
n.name == "b"
|
42
|
+
end
|
43
|
+
first_strong_node.next.content = first_strong_node.next.content.gsub(
|
44
|
+
/\s?:/, ""
|
45
|
+
)
|
45
46
|
term = first_strong_node.text.strip
|
46
47
|
first_strong_node.remove
|
47
|
-
"\n\n#{term}:: #{remove_trash_symbols(treat_children(cloned_node,
|
48
|
+
"\n\n#{term}:: #{remove_trash_symbols(treat_children(cloned_node,
|
49
|
+
state))}\n"
|
48
50
|
end
|
49
51
|
|
50
52
|
def stem_converted(cloned_node, state)
|
@@ -53,22 +55,22 @@ module Stepmod
|
|
53
55
|
content = Stepmod::Utils::HtmlToAsciimath.new.call(internal_content)
|
54
56
|
res = <<~TEMPLATE
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
[stem]
|
59
|
+
++++
|
60
|
+
#{remove_trash_symbols(content.strip)}
|
61
|
+
++++
|
60
62
|
|
61
|
-
|
62
|
-
res = "[[#{cloned_node['id']}]]\n#{res}" if cloned_node[
|
63
|
+
TEMPLATE
|
64
|
+
res = "[[#{cloned_node['id']}]]\n#{res}" if cloned_node["id"]&.length&.positive?
|
63
65
|
res
|
64
66
|
end
|
65
67
|
|
66
68
|
def remove_trash_symbols(content)
|
67
69
|
content
|
68
|
-
.gsub(/ /,
|
70
|
+
.gsub(/ /, "")
|
69
71
|
.strip
|
70
|
-
.gsub(/\(\d\)$/,
|
71
|
-
.gsub(/\b(\w*?
|
72
|
+
.gsub(/\(\d\)$/, "")
|
73
|
+
.gsub(/\b(\w*?_+\w+)\b/, '"\1"')
|
72
74
|
.gsub(/([^\s])\s+_{/, '\1_{')
|
73
75
|
.strip
|
74
76
|
end
|
@@ -81,7 +83,7 @@ module Stepmod
|
|
81
83
|
node
|
82
84
|
.children
|
83
85
|
.each do |n|
|
84
|
-
remove_tags_not_in_context(n) if n.children.length
|
86
|
+
remove_tags_not_in_context(n) if n.children.length.positive?
|
85
87
|
next if n.name != tag_name
|
86
88
|
|
87
89
|
n.add_previous_sibling(n.children)
|