stepmod-utils 0.3.34 → 0.3.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d4cd3a24127e1903a040a5edaa734ccef3adb17b65cce4c213fdcbf3d13ea5a
4
- data.tar.gz: fe17db00fa97f748853ed5c0de867222a5d5ba16b3c2256a498abe20814d7694
3
+ metadata.gz: d49969e2f3e60a1f5c56132b91a492f695aa1339bb9312b5264d72d54a4d4163
4
+ data.tar.gz: 8cc9498d0a6bdd52e4b387b32ebf90ec4735d3be3a009a92dfad35cd0a30c21c
5
5
  SHA512:
6
- metadata.gz: 7dab877d377c83d22a08dffceb223c3a7c502b353bd89756829c7fc39341c57758276731623e3e013879c0a329f9bb00de19eb5daa869a8653cd2d48f3987115
7
- data.tar.gz: ea50ab5f75131fc5474fb21adb8aaf7692dd48da61e453c754ac762fb76dde78948c0bbe9588f5f9750347d370189c56683481daa0c94fe57c77f10838c548a4
6
+ metadata.gz: c95c28d9b783137773da3bfc003dfdda5488368f48c3eb49a5494b62a47a60f2aa55ed218f3f0042ab558d386ea2d47445a1a44573078365725b5ac04b1246f6
7
+ data.tar.gz: c9a1d29d6d777f4914596724b5fad8fb256a6ce15ffcc857cbe8a233c37c01db5eebea9dbc7104537037a273d3080cbafc8f9db11d545fecdb5bd3293a970026
@@ -6,7 +6,9 @@ module Stepmod
6
6
  class Em < ReverseAdoc::Converters::Base
7
7
  def convert(node, state = {})
8
8
  content = treat_children(node, state.merge(already_italic: true))
9
- if content.strip.empty? || state[:already_italic]
9
+ if state[:equation]
10
+ "ii(#{content.strip})"
11
+ elsif content.strip.empty? || state[:already_italic]
10
12
  content
11
13
  else
12
14
  "#{content[/^\s*/]}_#{content.strip}_#{content[/\s*$/]}"
@@ -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.35".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.35
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-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby