stepmod-utils 0.3.34 → 0.3.36

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: 5d4cd3a24127e1903a040a5edaa734ccef3adb17b65cce4c213fdcbf3d13ea5a
4
- data.tar.gz: fe17db00fa97f748853ed5c0de867222a5d5ba16b3c2256a498abe20814d7694
3
+ metadata.gz: 0f1ebcec660e6d354c1b84750a92e0232c2428e0dd926f2aeb943f0ca3777f85
4
+ data.tar.gz: 794ffb15bcdac0433bdc6a881a25c89ba7b60a7c30234d43b0cb08e479c1f94b
5
5
  SHA512:
6
- metadata.gz: 7dab877d377c83d22a08dffceb223c3a7c502b353bd89756829c7fc39341c57758276731623e3e013879c0a329f9bb00de19eb5daa869a8653cd2d48f3987115
7
- data.tar.gz: ea50ab5f75131fc5474fb21adb8aaf7692dd48da61e453c754ac762fb76dde78948c0bbe9588f5f9750347d370189c56683481daa0c94fe57c77f10838c548a4
6
+ metadata.gz: 7fa30f27168e5ff50c602d297e4f3a3f7eafde2eb1eca3c8006a719fef499350f2ce8901b04d6eebd9e0bf8b0156ef91b7a3477ccf120f16d66aad93f17f48d8
7
+ data.tar.gz: 4fc47c6bedae4215005a7c47102b13a8185fdaaa2378847cd729d1d29f7b56ebf325fdaa95cddbcf0c93b668a79e6ea1025989828e3611bd0ddf06d34a139c5a
@@ -5,12 +5,41 @@ module Stepmod
5
5
  module Converters
6
6
  class Em < ReverseAdoc::Converters::Base
7
7
  def convert(node, state = {})
8
- content = treat_children(node, state.merge(already_italic: true))
9
- if content.strip.empty? || state[:already_italic]
8
+ italic_converted(node, state)
9
+ end
10
+
11
+ private
12
+
13
+ def italic_converted(node, state)
14
+ cloned_node = node.clone
15
+ equations = extract_equations(cloned_node)
16
+ content = treat_children(cloned_node, state.merge(already_italic: true))
17
+ equation_content = equations.map do |equation|
18
+ treat(equation, state.merge(equation: true, already_italic: true))
19
+ end
20
+
21
+ content = if state[:equation] && !content.strip.empty?
22
+ "ii(#{content.strip})"
23
+ elsif content.strip.empty? || state[:already_italic]
10
24
  content
11
25
  else
12
26
  "#{content[/^\s*/]}_#{content.strip}_#{content[/\s*$/]}"
13
27
  end
28
+
29
+ [content, equation_content].compact.join("")
30
+ end
31
+
32
+ def extract_equations(node)
33
+ equations = []
34
+
35
+ node.children.each do |n|
36
+ next if n.name != "eqn"
37
+
38
+ equations << n
39
+ n.unlink
40
+ end
41
+
42
+ equations
14
43
  end
15
44
  end
16
45
 
@@ -46,12 +46,13 @@ module Stepmod
46
46
  term = first_strong_node.text.strip
47
47
  first_strong_node.remove
48
48
  "\n\n#{term}:: #{remove_trash_symbols(treat_children(cloned_node,
49
- state))}\n"
49
+ state.merge(equation: true)))}\n"
50
50
  end
51
51
 
52
52
  def stem_converted(cloned_node, state)
53
- remove_tags_not_in_context(cloned_node)
54
- internal_content = treat_children(cloned_node, state)
53
+ # We are now adding bb() or ii() for bold and italic respectively
54
+ # remove_tags_not_in_context(cloned_node)
55
+ internal_content = treat_children(cloned_node, state.merge(equation: true))
55
56
  content = Stepmod::Utils::HtmlToAsciimath.new.call(internal_content)
56
57
  res = <<~TEMPLATE
57
58
 
@@ -7,19 +7,46 @@ module Stepmod
7
7
  BLANK_CHARS = "{blank}"
8
8
 
9
9
  def convert(node, state = {})
10
- content = treat_children(node, state.merge(already_strong: true))
11
- strong_tag = state[:non_flanking_whitesapce] ? '**' : '*'
12
- if content.strip.empty? || state[:already_strong] || content_is_equation?(content)
10
+ bold_converted(node, state)
11
+ end
12
+
13
+ private
14
+
15
+ def bold_converted(node, state)
16
+ cloned_node = node.clone
17
+ equations = extract_equations(cloned_node)
18
+ content = treat_children(cloned_node, state.merge(already_strong: true))
19
+ equation_content = equations.map do |equation|
20
+ treat(equation, state.merge(equation: true, already_strong: true))
21
+ end
22
+
23
+ content = if state[:equation]
24
+ "bb(#{content.strip})"
25
+ elsif content.strip.empty? || state[:already_strong]
13
26
  content
14
27
  else
28
+ strong_tag = state[:non_flanking_whitesapce] ? '**' : '*'
15
29
  handle_express_escape_seq(
16
30
  node,
17
31
  "#{content[/^\s*/]}#{strong_tag}#{content.strip}#{strong_tag}#{content[/\s*$/]}"
18
32
  )
19
33
  end
34
+
35
+ [content, equation_content].compact.join("")
20
36
  end
21
37
 
22
- private
38
+ def extract_equations(node)
39
+ equations = []
40
+
41
+ node.children.each do |n|
42
+ next if n.name != "eqn"
43
+
44
+ equations << n
45
+ n.unlink
46
+ end
47
+
48
+ equations
49
+ end
23
50
 
24
51
  def handle_express_escape_seq(node, content)
25
52
  res = content
@@ -36,10 +63,6 @@ module Stepmod
36
63
  match = end_of_text ? /\($/ : /^\)/
37
64
  sibling&.text? && sibling.text =~ match
38
65
  end
39
-
40
- def content_is_equation?(content)
41
- content.match(/^\s*\[\[[^\]]*\]\]/) || content.match(/^\s*\[stem\]/)
42
- end
43
66
  end
44
67
 
45
68
  ReverseAdoc::Converters.register :strong, Strong.new
@@ -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 == "eqn"
9
+ return stem_notation(content) if state[:equation]
10
10
 
11
11
  "#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}"
12
12
  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 == "eqn"
9
+ return stem_notation(content) if state[:equation]
10
10
 
11
11
  "#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}"
12
12
  end
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.3.34".freeze
3
+ VERSION = "0.3.36".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepmod-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.34
4
+ version: 0.3.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-06 00:00:00.000000000 Z
11
+ date: 2023-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby