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
@@ -5,16 +5,15 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class Example < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
|
-
|
9
8
|
# If we want to skip this node
|
10
|
-
return
|
9
|
+
return "" if state[:no_notes_examples]
|
11
10
|
|
12
11
|
<<~TEMPLATE
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
[example]
|
14
|
+
====
|
15
|
+
#{treat_children(node, state).strip}
|
16
|
+
====
|
18
17
|
|
19
18
|
TEMPLATE
|
20
19
|
end
|
@@ -6,19 +6,20 @@ module Stepmod
|
|
6
6
|
class ExpressG < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
8
|
node.children.map do |child|
|
9
|
-
next unless child.name ==
|
9
|
+
next unless child.name == "imgfile"
|
10
10
|
|
11
|
-
parse_to_svg_reference(child[
|
11
|
+
parse_to_svg_reference(child["file"], state)
|
12
12
|
end.join("\n")
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def parse_to_svg_reference(file, state)
|
18
|
-
return
|
18
|
+
return "" unless File.file?(file)
|
19
19
|
|
20
20
|
image_document = Nokogiri::XML(File.read(file))
|
21
|
-
svg_path = File.basename(image_document.xpath(
|
21
|
+
svg_path = File.basename(image_document.xpath("//img").first["src"],
|
22
|
+
".*")
|
22
23
|
<<~SVGMAP
|
23
24
|
|
24
25
|
*)
|
@@ -27,23 +28,23 @@ module Stepmod
|
|
27
28
|
====
|
28
29
|
image::#{svg_path}.svg[]
|
29
30
|
|
30
|
-
#{image_document.xpath('//img.area').map.with_index(1) {|n, i| schema_reference(n['href'], i) }.join("\n")}
|
31
|
+
#{image_document.xpath('//img.area').map.with_index(1) { |n, i| schema_reference(n['href'], i) }.join("\n")}
|
31
32
|
====
|
32
33
|
SVGMAP
|
33
34
|
end
|
34
35
|
|
35
36
|
def schema_reference(xml_path, index)
|
36
|
-
if xml_path
|
37
|
-
_,express_path_part = xml_path.split(
|
37
|
+
if /#/.match?(xml_path)
|
38
|
+
_, express_path_part = xml_path.split("#")
|
38
39
|
"* <<express:#{express_path_part.strip}>>; #{index}"
|
39
40
|
else
|
40
|
-
schema_name = File.basename(xml_path,
|
41
|
+
schema_name = File.basename(xml_path, ".*")
|
41
42
|
"* <<express:#{schema_name.strip}>>; #{index}"
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
|
-
ReverseAdoc::Converters.register
|
47
|
+
ReverseAdoc::Converters.register "express-g", ExpressG.new
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
@@ -5,10 +5,10 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class ExpressRef < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, _state = {})
|
8
|
-
"*#{node['linkend'].to_s.split('.').last}*"
|
8
|
+
" *#{node['linkend'].to_s.split('.').last}* "
|
9
9
|
end
|
10
10
|
end
|
11
11
|
ReverseAdoc::Converters.register :express_ref, ExpressRef.new
|
12
12
|
end
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end
|
@@ -3,11 +3,12 @@ module Stepmod
|
|
3
3
|
module Converters
|
4
4
|
class ExpressRefExpressDescription < ReverseAdoc::Converters::Base
|
5
5
|
def convert(node, _state = {})
|
6
|
-
parts = node[
|
6
|
+
parts = node["linkend"].to_s.split(":").last.split(".")
|
7
7
|
"<<express:#{parts.join('.').strip},#{parts.last.strip}>>"
|
8
8
|
end
|
9
9
|
end
|
10
|
-
ReverseAdoc::Converters.register :express_ref,
|
10
|
+
ReverseAdoc::Converters.register :express_ref,
|
11
|
+
ExpressRefExpressDescription.new
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -3,7 +3,7 @@ module Stepmod
|
|
3
3
|
module Converters
|
4
4
|
class ExtDescription < ReverseAdoc::Converters::Base
|
5
5
|
def convert(node, state = {})
|
6
|
-
state = state.merge(schema_name: node[
|
6
|
+
state = state.merge(schema_name: node["linkend"])
|
7
7
|
child_text = treat_children(node, state).strip
|
8
8
|
|
9
9
|
<<~TEMPLATE
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "reverse_adoc/converters/figure"
|
3
4
|
|
4
5
|
module Stepmod
|
5
6
|
module Utils
|
@@ -7,7 +8,7 @@ module Stepmod
|
|
7
8
|
class Figure < ReverseAdoc::Converters::Figure
|
8
9
|
def convert(node, state = {})
|
9
10
|
# If we want to skip this node
|
10
|
-
return
|
11
|
+
return "" if state[:no_notes_examples]
|
11
12
|
|
12
13
|
super
|
13
14
|
end
|
@@ -17,4 +18,3 @@ module Stepmod
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
20
|
-
|
@@ -4,7 +4,7 @@ module Stepmod
|
|
4
4
|
module Utils
|
5
5
|
module Converters
|
6
6
|
class Head < ReverseAdoc::Converters::Base
|
7
|
-
def convert(node,
|
7
|
+
def convert(node, _state = {})
|
8
8
|
title = extract_title(node)
|
9
9
|
"= #{title}\n:stem:\n\n"
|
10
10
|
end
|
@@ -12,6 +12,7 @@ module Stepmod
|
|
12
12
|
def extract_title(node)
|
13
13
|
title = node.at("./title")
|
14
14
|
return "(???)" if title.nil?
|
15
|
+
|
15
16
|
title.text
|
16
17
|
end
|
17
18
|
end
|
@@ -19,4 +20,4 @@ module Stepmod
|
|
19
20
|
ReverseAdoc::Converters.register :head, Head.new
|
20
21
|
end
|
21
22
|
end
|
22
|
-
end
|
23
|
+
end
|
@@ -4,7 +4,7 @@ module Stepmod
|
|
4
4
|
module Utils
|
5
5
|
module Converters
|
6
6
|
class Hr < ReverseAdoc::Converters::Base
|
7
|
-
def convert(
|
7
|
+
def convert(_node, _state = {})
|
8
8
|
"\n* * *\n"
|
9
9
|
end
|
10
10
|
end
|
@@ -12,4 +12,4 @@ module Stepmod
|
|
12
12
|
ReverseAdoc::Converters.register :hr, Hr.new
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -4,8 +4,8 @@ module Stepmod
|
|
4
4
|
module Utils
|
5
5
|
module Converters
|
6
6
|
class Ignore < ReverseAdoc::Converters::Base
|
7
|
-
def convert(
|
8
|
-
|
7
|
+
def convert(_node, _state = {})
|
8
|
+
"" # noop
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -13,4 +13,4 @@ module Stepmod
|
|
13
13
|
ReverseAdoc::Converters.register :col, Ignore.new
|
14
14
|
end
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
@@ -5,21 +5,21 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class ModuleRef < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, _state = {})
|
8
|
-
ref = node[
|
8
|
+
ref = node["linkend"]
|
9
9
|
# #23:
|
10
10
|
# In this case when we see this:
|
11
11
|
|
12
12
|
# <module_ref linkend="product_as_individual:3_definition">individual products</module_ref>
|
13
13
|
# We take the text value of the element and convert to this:
|
14
14
|
|
15
|
-
#
|
15
|
+
# {{individual products}}
|
16
16
|
|
17
17
|
ref = node.text.strip
|
18
18
|
if !ref.empty?
|
19
|
-
"
|
19
|
+
" {{#{normalized_ref(ref)}}} "
|
20
20
|
elsif
|
21
|
-
ref = node[
|
22
|
-
" *#{ref}*"
|
21
|
+
ref = node["linkend"].split(":").first
|
22
|
+
" *#{ref}* "
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -28,10 +28,10 @@ module Stepmod
|
|
28
28
|
def normalized_ref(ref)
|
29
29
|
return unless ref || ref.empty?
|
30
30
|
|
31
|
-
ref.squeeze(
|
31
|
+
ref.squeeze(" ").strip
|
32
32
|
end
|
33
33
|
end
|
34
34
|
ReverseAdoc::Converters.register :module_ref, ModuleRef.new
|
35
35
|
end
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
@@ -5,16 +5,15 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class Note < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
|
-
|
9
8
|
# If we want to skip this node
|
10
|
-
return
|
9
|
+
return "" if state[:no_notes_examples]
|
11
10
|
|
12
11
|
<<~TEMPLATE
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
[NOTE]
|
14
|
+
--
|
15
|
+
#{treat_children(node, state).strip}
|
16
|
+
--
|
18
17
|
|
19
18
|
TEMPLATE
|
20
19
|
end
|
@@ -5,14 +5,18 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class Ol < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
|
-
id = node[
|
8
|
+
id = node["id"]
|
9
9
|
anchor = id ? "[[#{id}]]\n" : ""
|
10
10
|
ol_count = state.fetch(:ol_count, 0) + 1
|
11
11
|
attrs = ol_attrs(node)
|
12
|
-
|
12
|
+
children_s = treat_children(node, state.merge(
|
13
|
+
ol_count: ol_count,
|
14
|
+
tdsinglepara: true,
|
15
|
+
))
|
16
|
+
|
17
|
+
"\n\n#{anchor}#{attrs}#{children_s}\n"
|
13
18
|
# Why do we add this?
|
14
19
|
# res = "\n" + res if node.parent && node.parent.name == 'note'
|
15
|
-
res
|
16
20
|
end
|
17
21
|
|
18
22
|
def number_style(node)
|
@@ -22,8 +26,6 @@ module Stepmod
|
|
22
26
|
when "a" then "loweralpha"
|
23
27
|
when "I" then "upperroman"
|
24
28
|
when "i" then "lowerroman"
|
25
|
-
else
|
26
|
-
nil
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -5,7 +5,7 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class P < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
|
-
id = node[
|
8
|
+
id = node["id"]
|
9
9
|
anchor = id ? "[[#{id}]]\n" : ""
|
10
10
|
if state[:tdsinglepara]
|
11
11
|
"#{anchor}#{treat_children(node, state).strip}"
|
@@ -18,4 +18,4 @@ module Stepmod
|
|
18
18
|
ReverseAdoc::Converters.register :p, P.new
|
19
19
|
end
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
@@ -5,7 +5,7 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class Schema < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
|
-
state = state.merge(schema_name: node[
|
8
|
+
state = state.merge(schema_name: node["name"])
|
9
9
|
<<~TEMPLATE
|
10
10
|
(*"#{node['name']}"
|
11
11
|
#{treat_children(node, state).strip}
|
@@ -3,8 +3,8 @@ module Stepmod
|
|
3
3
|
module Converters
|
4
4
|
class StepmodExtDescription < ReverseAdoc::Converters::Base
|
5
5
|
def convert(node, state = {})
|
6
|
-
state = state.merge(schema_name: node[
|
7
|
-
linkend = node[
|
6
|
+
state = state.merge(schema_name: node["linkend"])
|
7
|
+
linkend = node["linkend"].split(".")
|
8
8
|
|
9
9
|
# We only want ENTITY entries, not their attributes
|
10
10
|
# https://github.com/metanorma/iso-10303-2/issues/36#issuecomment-841300092
|
@@ -13,8 +13,21 @@ module Stepmod
|
|
13
13
|
child_text = treat_children(node, state).strip
|
14
14
|
return nil if child_text.empty?
|
15
15
|
|
16
|
-
#
|
17
|
-
|
16
|
+
# Unless the first paragraph ends with "between" and is followed by a
|
17
|
+
# list, don't split
|
18
|
+
first_child = child_text.split("\n").first
|
19
|
+
|
20
|
+
unless (
|
21
|
+
first_child =~ /between:?\s*\Z/ ||
|
22
|
+
first_child =~ /include:?\s*\Z/ ||
|
23
|
+
first_child =~ /of:?\s*\Z/ ||
|
24
|
+
first_child =~ /[:;]\s*\Z/
|
25
|
+
) &&
|
26
|
+
child_text =~ /\n\n\*/
|
27
|
+
|
28
|
+
# Only taking the first paragraph of the definition
|
29
|
+
child_text = first_child
|
30
|
+
end
|
18
31
|
|
19
32
|
# # Only taking the first sentence
|
20
33
|
# if child_text.contains?(".")
|
@@ -32,13 +45,14 @@ module Stepmod
|
|
32
45
|
<<~TEMPLATE
|
33
46
|
=== #{linkend.last}
|
34
47
|
|
35
|
-
#{domain ? "domain:[
|
48
|
+
#{domain ? "domain:[#{domain}]" : ''}
|
36
49
|
|
37
50
|
#{child_text}
|
38
51
|
TEMPLATE
|
39
52
|
end
|
40
53
|
end
|
41
|
-
ReverseAdoc::Converters.register :ext_description,
|
54
|
+
ReverseAdoc::Converters.register :ext_description,
|
55
|
+
StepmodExtDescription.new
|
42
56
|
end
|
43
57
|
end
|
44
58
|
end
|
@@ -4,14 +4,17 @@ module Stepmod
|
|
4
4
|
module Utils
|
5
5
|
module Converters
|
6
6
|
class Strong < ReverseAdoc::Converters::Base
|
7
|
-
BLANK_CHARS = "{blank}"
|
7
|
+
BLANK_CHARS = "{blank}"
|
8
8
|
|
9
9
|
def convert(node, state = {})
|
10
10
|
content = treat_children(node, state.merge(already_strong: true))
|
11
11
|
if content.strip.empty? || state[:already_strong]
|
12
12
|
content
|
13
13
|
else
|
14
|
-
handle_express_escape_seq(
|
14
|
+
handle_express_escape_seq(
|
15
|
+
node,
|
16
|
+
"#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}"
|
17
|
+
)
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
@@ -30,7 +33,7 @@ module Stepmod
|
|
30
33
|
|
31
34
|
def braces_sibling?(sibling, end_of_text = false)
|
32
35
|
match = end_of_text ? /\($/ : /^\)/
|
33
|
-
sibling
|
36
|
+
sibling&.text? && sibling.text =~ match
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
@@ -38,4 +41,4 @@ module Stepmod
|
|
38
41
|
ReverseAdoc::Converters.register :b, Strong.new
|
39
42
|
end
|
40
43
|
end
|
41
|
-
end
|
44
|
+
end
|
@@ -6,7 +6,7 @@ module Stepmod
|
|
6
6
|
class Sub < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
8
|
content = treat_children(node, state)
|
9
|
-
return stem_notation(content) if node.parent.name ==
|
9
|
+
return stem_notation(content) if node.parent.name == "eqn"
|
10
10
|
|
11
11
|
"#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}"
|
12
12
|
end
|
@@ -21,4 +21,4 @@ module Stepmod
|
|
21
21
|
ReverseAdoc::Converters.register :sub, Sub.new
|
22
22
|
end
|
23
23
|
end
|
24
|
-
end
|
24
|
+
end
|
@@ -6,7 +6,7 @@ module Stepmod
|
|
6
6
|
class Sup < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
8
|
content = treat_children(node, state)
|
9
|
-
return stem_notation(content) if node.parent.name ==
|
9
|
+
return stem_notation(content) if node.parent.name == "eqn"
|
10
10
|
|
11
11
|
"#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}"
|
12
12
|
end
|
@@ -19,4 +19,4 @@ module Stepmod
|
|
19
19
|
ReverseAdoc::Converters.register :sup, Sup.new
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
@@ -4,7 +4,7 @@ module Stepmod
|
|
4
4
|
module Utils
|
5
5
|
module Converters
|
6
6
|
class Synonym < ReverseAdoc::Converters::Base
|
7
|
-
def convert(node,
|
7
|
+
def convert(node, _state = {})
|
8
8
|
"alt:[#{node.text.strip}]"
|
9
9
|
end
|
10
10
|
end
|
@@ -12,4 +12,4 @@ module Stepmod
|
|
12
12
|
ReverseAdoc::Converters.register :synonym, Synonym.new
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -5,12 +5,13 @@ module Stepmod
|
|
5
5
|
module Converters
|
6
6
|
class Table < ReverseAdoc::Converters::Base
|
7
7
|
def convert(node, state = {})
|
8
|
-
id = node[
|
8
|
+
id = node["id"]
|
9
9
|
anchor = id ? "[[#{id}]]\n" : ""
|
10
|
-
title = node[
|
10
|
+
title = node["caption"].to_s
|
11
11
|
title = ".#{title}\n" unless title.empty?
|
12
12
|
attrs = style(node)
|
13
|
-
"\n\n#{anchor}#{attrs}#{title}|===\n#{treat_children(node,
|
13
|
+
"\n\n#{anchor}#{attrs}#{title}|===\n#{treat_children(node,
|
14
|
+
state)}\n|===\n"
|
14
15
|
end
|
15
16
|
|
16
17
|
def frame(node)
|
@@ -23,8 +24,6 @@ module Stepmod
|
|
23
24
|
"frame=sides"
|
24
25
|
when "box", "border"
|
25
26
|
"frame=all"
|
26
|
-
else
|
27
|
-
nil
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
@@ -38,13 +37,11 @@ module Stepmod
|
|
38
37
|
"rules=cols"
|
39
38
|
when "none"
|
40
39
|
"rules=none"
|
41
|
-
else
|
42
|
-
nil
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
46
43
|
def style(node)
|
47
|
-
width = "width=#{node['width']}" if node[
|
44
|
+
width = "width=#{node['width']}" if node["width"]
|
48
45
|
attrs = []
|
49
46
|
frame_attr = frame(node)
|
50
47
|
rules_attr = rules(node)
|
@@ -52,6 +49,7 @@ module Stepmod
|
|
52
49
|
attrs += frame_attr if frame_attr
|
53
50
|
attrs += rules_attr if rules_attr
|
54
51
|
return "" if attrs.empty?
|
52
|
+
|
55
53
|
"[#{attrs.join(',')}]\n"
|
56
54
|
end
|
57
55
|
end
|
@@ -59,4 +57,4 @@ module Stepmod
|
|
59
57
|
ReverseAdoc::Converters.register :table, Table.new
|
60
58
|
end
|
61
59
|
end
|
62
|
-
end
|
60
|
+
end
|
@@ -1,29 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "stepmod/utils/converters/synonym"
|
4
4
|
|
5
5
|
module Stepmod
|
6
6
|
module Utils
|
7
7
|
module Converters
|
8
8
|
class Term < ReverseAdoc::Converters::Base
|
9
|
+
|
10
|
+
# We strip all the children in the case for "stem:[d]-manifold"
|
11
|
+
# vs "stem:[d] -manifold"
|
12
|
+
def treat_children(node, state)
|
13
|
+
res = node.children.map { |child| treat(child, state) }
|
14
|
+
res.map(&:strip).reject(&:empty?).join("")
|
15
|
+
end
|
16
|
+
|
9
17
|
def convert(node, state = {})
|
10
18
|
first_child = node.children.find do |child|
|
11
|
-
|
12
|
-
|
19
|
+
child.name == "text" && !child.text.to_s.strip.empty?
|
20
|
+
end
|
21
|
+
|
13
22
|
unless first_child &&
|
14
|
-
|
15
|
-
|
16
|
-
return "=== #{treat_children(node, state).strip}"
|
23
|
+
node.text.split(";").length == 2 &&
|
24
|
+
defined?(Stepmod::Utils::Converters::Synonym)
|
25
|
+
return "=== #{treat_acronym(treat_children(node, state).strip)}"
|
17
26
|
end
|
18
27
|
|
19
|
-
term_def, alt = node.text.split(
|
28
|
+
term_def, alt = node.text.split(";")
|
20
29
|
alt_xml = Nokogiri::XML::Text.new(alt, Nokogiri::XML::Document.new)
|
21
30
|
converted_alt = Stepmod::Utils::Converters::Synonym.new.convert(alt_xml)
|
22
|
-
"=== #{term_def}\n\n#{converted_alt}"
|
31
|
+
"=== #{treat_acronym(term_def)}\n\n#{converted_alt}"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def treat_acronym(term_def)
|
37
|
+
return term_def.strip if term_def !~ /.+\(.+?\)$/
|
38
|
+
|
39
|
+
_, term_text, term_acronym = term_def.match(/(.+?)(\(.+\))$/).to_a
|
40
|
+
"#{term_text.strip}\nalt:[#{term_acronym.gsub(/\(|\)/, '')}]"
|
23
41
|
end
|
24
42
|
end
|
25
43
|
|
26
44
|
ReverseAdoc::Converters.register :term, Term.new
|
27
45
|
end
|
28
46
|
end
|
29
|
-
end
|
47
|
+
end
|
@@ -16,14 +16,14 @@ module Stepmod
|
|
16
16
|
|
17
17
|
def treat_empty(node, state)
|
18
18
|
parent = node.parent.name.to_sym
|
19
|
-
if [
|
20
|
-
|
19
|
+
if %i[ol ul].include?(parent) # Otherwise the identation is broken
|
20
|
+
""
|
21
21
|
elsif state[:tdsinglepara]
|
22
|
-
|
23
|
-
elsif node.text ==
|
24
|
-
|
22
|
+
""
|
23
|
+
elsif node.text == " " # Regular whitespace text node
|
24
|
+
" "
|
25
25
|
else
|
26
|
-
|
26
|
+
""
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -34,9 +34,7 @@ module Stepmod
|
|
34
34
|
text = remove_border_newlines(text)
|
35
35
|
|
36
36
|
text = preserve_keychars_within_backticks(text)
|
37
|
-
|
38
|
-
|
39
|
-
text
|
37
|
+
preserve_tags(text)
|
40
38
|
end
|
41
39
|
|
42
40
|
def preserve_nbsp(text)
|
@@ -44,20 +42,20 @@ module Stepmod
|
|
44
42
|
end
|
45
43
|
|
46
44
|
def preserve_tags(text)
|
47
|
-
text.gsub(/[<>]/,
|
45
|
+
text.gsub(/[<>]/, ">" => '\>', "<" => '\<')
|
48
46
|
end
|
49
47
|
|
50
48
|
def remove_border_newlines(text)
|
51
|
-
text.gsub(/\A\n+/,
|
49
|
+
text.gsub(/\A\n+/, "").gsub(/\n+\z/, "")
|
52
50
|
end
|
53
51
|
|
54
52
|
def remove_inner_newlines(text)
|
55
|
-
text.tr("\n\t",
|
53
|
+
text.tr("\n\t", " ").squeeze(" ")
|
56
54
|
end
|
57
55
|
|
58
56
|
def preserve_keychars_within_backticks(text)
|
59
57
|
text.gsub(/`.*?`/) do |match|
|
60
|
-
match.gsub('\_',
|
58
|
+
match.gsub('\_', "_").gsub('\*', "*")
|
61
59
|
end
|
62
60
|
end
|
63
61
|
end
|