ipynbdiff 0.4.3 → 0.4.6

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: 4439ffa7f5fb1abc1243c5ab32d1196bb9bb37130c2a1eebe8461a4b0d1bf1bb
4
- data.tar.gz: 1767b4eccbc36b2644cc2c5c4b50589b0b967dff46e50b4898c328e171adc1f4
3
+ metadata.gz: ff3a6405d5c4034108fee997d678bee634a516f1d773b0aa9e8c7e4f50b7f28e
4
+ data.tar.gz: 3a80027ec239810e6b3daaa637fc338c5a34e3ae75c2f33043303eb6e16f6980
5
5
  SHA512:
6
- metadata.gz: 86fd17c557336d668abfd4677e1883b20d7af02c75afcfe2d4357149953c54520578afd1c7b902591746a3b1ba113778e1794026b57fe44fcf53fc66ace4ddb0
7
- data.tar.gz: 85b800b3776a519c471be72979a9a0ea186ad4a3251ff4276e2e732c9aed906fd8327ce9797ade66ada6734e248116e1b8338b6b035c607615b0fc21c602a136
6
+ metadata.gz: 6d126961600c8073f2ead97b26d2879f987f15d6e3c74f0c9e2bd64c020bc8fd7963f4b50a69fd28c98728c645b595dbdda5883f4f56e18aa949df589e3787d0
7
+ data.tar.gz: 30e2c855b51de45ad2147419a455a4adc8f4f3cd30445f32a9667e3f17a072c3e59bcc8e603e34be2c7216e0b9671e2ed283e827780b4da25bff4be03f733ed6
@@ -7,8 +7,8 @@ module IpynbDiff
7
7
  # Creates a symbol map for a ipynb file (JSON format)
8
8
  class IpynbSymbolMap
9
9
  class << self
10
- def parse(notebook)
11
- IpynbSymbolMap.new(notebook).parse('')
10
+ def parse(notebook, objects_to_ignore = [])
11
+ IpynbSymbolMap.new(notebook, objects_to_ignore).parse('')
12
12
  end
13
13
  end
14
14
 
@@ -18,14 +18,17 @@ module IpynbDiff
18
18
 
19
19
  VALUE_STOPPERS = [',', '[', ']', '{', '}', *WHITESPACE_CHARS].freeze
20
20
 
21
- def initialize(notebook)
21
+ def initialize(notebook, objects_to_ignore = [])
22
22
  @chars = notebook.chars
23
23
  @current_line = 0
24
24
  @char_idx = 0
25
25
  @results = {}
26
+ @objects_to_ignore = objects_to_ignore
26
27
  end
27
28
 
28
29
  def parse(prefix = '.')
30
+ raise_if_file_ended
31
+
29
32
  skip_whitespaces
30
33
 
31
34
  if (c = current_char) == '"'
@@ -49,6 +52,8 @@ module IpynbDiff
49
52
  current_should_be '['
50
53
 
51
54
  loop do
55
+ raise_if_file_ended
56
+
52
57
  break if skip_beginning(']')
53
58
 
54
59
  new_prefix = "#{prefix}.#{i}"
@@ -67,13 +72,11 @@ module IpynbDiff
67
72
  current_should_be '{'
68
73
 
69
74
  loop do
70
- break if skip_beginning('}')
75
+ raise_if_file_ended
71
76
 
72
- prop_name = parse_string
73
-
74
- new_prefix = "#{prefix}.#{prop_name}"
77
+ break if skip_beginning('}')
75
78
 
76
- add_result(new_prefix, current_line)
79
+ prop_name = parse_string(return_value: true)
77
80
 
78
81
  next_and_skip_whitespaces
79
82
 
@@ -81,26 +84,34 @@ module IpynbDiff
81
84
 
82
85
  next_and_skip_whitespaces
83
86
 
84
- parse(new_prefix)
87
+ if @objects_to_ignore.include? prop_name
88
+ skip
89
+ else
90
+ new_prefix = "#{prefix}.#{prop_name}"
91
+
92
+ add_result(new_prefix, current_line)
93
+
94
+ parse(new_prefix)
95
+ end
85
96
  end
86
97
  end
87
98
 
88
- def parse_string
99
+ def parse_string(return_value: false)
89
100
  current_should_be '"'
90
101
  init_idx = @char_idx
91
102
 
92
103
  loop do
93
104
  increment_char_index
94
105
 
95
- break if @char_idx > @chars.length
106
+ raise_if_file_ended
96
107
 
97
- if current_char == '"' && prev_char != '\\'
108
+ if current_char == '"' && !prev_backslash?
98
109
  init_idx += 1
99
110
  break
100
111
  end
101
112
  end
102
113
 
103
- @chars[init_idx...@char_idx].join
114
+ @chars[init_idx...@char_idx].join if return_value
104
115
  end
105
116
 
106
117
  def add_result(key, line_number)
@@ -108,11 +119,12 @@ module IpynbDiff
108
119
  end
109
120
 
110
121
  def parse_value
111
- increment_char_index until VALUE_STOPPERS.include?(current_char)
122
+ increment_char_index until raise_if_file_ended || VALUE_STOPPERS.include?(current_char)
112
123
  end
113
124
 
114
125
  def skip_whitespaces
115
126
  while WHITESPACE_CHARS.include?(current_char)
127
+ raise_if_file_ended
116
128
  check_for_new_line
117
129
  increment_char_index
118
130
  end
@@ -128,11 +140,13 @@ module IpynbDiff
128
140
  end
129
141
 
130
142
  def current_char
143
+ raise_if_file_ended
144
+
131
145
  @chars[@char_idx]
132
146
  end
133
147
 
134
- def prev_char
135
- @chars[@char_idx - 1]
148
+ def prev_backslash?
149
+ @chars[@char_idx - 1] == '\\' && @chars[@char_idx - 2] != '\\'
136
150
  end
137
151
 
138
152
  def current_should_be(another_char)
@@ -143,6 +157,55 @@ module IpynbDiff
143
157
  @current_line += 1 if current_char == "\n"
144
158
  end
145
159
 
160
+ def raise_if_file_ended
161
+ @char_idx >= @chars.size && raise(InvalidTokenError)
162
+ end
163
+
164
+ def skip
165
+ raise_if_file_ended
166
+
167
+ skip_whitespaces
168
+
169
+ if (c = current_char) == '"'
170
+ parse_string
171
+ elsif c == '['
172
+ skip_array
173
+ elsif c == '{'
174
+ skip_object
175
+ else
176
+ parse_value
177
+ end
178
+ end
179
+
180
+ def skip_array
181
+ loop do
182
+ raise_if_file_ended
183
+
184
+ break if skip_beginning(']')
185
+
186
+ skip
187
+ end
188
+ end
189
+
190
+ def skip_object
191
+
192
+ loop do
193
+ raise_if_file_ended
194
+
195
+ break if skip_beginning('}')
196
+
197
+ parse_string
198
+
199
+ next_and_skip_whitespaces
200
+
201
+ current_should_be ':'
202
+
203
+ next_and_skip_whitespaces
204
+
205
+ skip
206
+ end
207
+ end
208
+
146
209
  def skip_beginning(closing_char)
147
210
 
148
211
  check_for_new_line
@@ -52,24 +52,20 @@ module IpynbDiff
52
52
  new_symbol = symbol_prefix / output_type
53
53
  case output_type
54
54
  when 'image/png', 'image/jpeg'
55
- transform_image(output_type, output_element, new_symbol)
55
+ transform_image(output_type + ';base64', output_element, new_symbol)
56
56
  when 'image/svg+xml'
57
- transform_svg(output_element, new_symbol)
57
+ transform_image(output_type + ';utf8', output_element, new_symbol)
58
58
  when 'text/markdown', 'text/latex', 'text/plain', 'text'
59
59
  transform_text(output_element, new_symbol)
60
60
  end
61
61
  end
62
62
 
63
63
  def transform_image(image_type, image_content, symbol)
64
- _(symbol, " ![](data:#{image_type};base64,#{image_content.gsub("\n", '')})")
65
- end
66
-
67
- def transform_svg(image_content, symbol)
68
64
  lines = image_content.is_a?(Array) ? image_content : [image_content]
69
65
 
70
66
  single_line = lines.map(&:strip).join.gsub(/\s+/, ' ')
71
67
 
72
- _(symbol, " ![](data:image/svg+xml;utf8,#{single_line})")
68
+ _(symbol, " ![](data:#{image_type},#{single_line})")
73
69
  end
74
70
 
75
71
  def transform_text(text_content, symbol)
data/lib/transformer.rb CHANGED
@@ -15,6 +15,7 @@ module IpynbDiff
15
15
  include SymbolizedMarkdownHelper
16
16
 
17
17
  @include_frontmatter = true
18
+ @objects_to_ignore = ['application/javascript', 'application/vnd.holoviews_load.v0+json']
18
19
 
19
20
  def initialize(include_frontmatter: true)
20
21
  @include_frontmatter = include_frontmatter
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # lib/emoticon/version.rb
2
2
 
3
3
  module IpynbDiff
4
- VERSION = "0.4.3"
4
+ VERSION = "0.4.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipynbdiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Bonet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-04 00:00:00.000000000 Z
11
+ date: 2022-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy