notion_to_md 2.3.0 → 2.3.1

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: bba453442621ce806b36625a5febfd14a2f75d8051c49923d845435535e11574
4
- data.tar.gz: bc8a6b8a8ba768728cbb88b88a5d4c4069aa173ac9275d5c6a9cb95a37827a43
3
+ metadata.gz: 26fb275bacfb3f94bc62bf1f15de2de6636f043a2a7d11b66ecba0f5df2a39ec
4
+ data.tar.gz: 53308f1bc92d17a1125969e030f6a070cc82384808b34787f6ed0c853fdbaca9
5
5
  SHA512:
6
- metadata.gz: d7005a6bdfd26d3322a92ee49274ec8006549e90f850cc0d4fbc5907a0e0a9ecc526578b7c8964462563395e7980269a87d43d705fd6a2ccd8aaf26b240b6006
7
- data.tar.gz: 9c52fe4feff24a090c19c6b736d1af5daaefc8dd5ce0fbe994acf6b41c2c1bbf8631846d71c59b5757219dc72583d50d6c316fc73bb81a453e8e3a02270407d6
6
+ metadata.gz: b0522c546ae98279d0a20aff3a8bf5d225dc74eea6c5504a0f35bdf6bb692e870c6719ea088251556fb49ad3318031f200754ac2691254fa3d0d4287035e4045
7
+ data.tar.gz: 2430ca47d1fe39e9f73cc9aad187d6457440edb94cd60dea9d1d82d562a057339acdef9c85ac8b1db79d34acd9db754493a62876643deab50af310472e125b06
@@ -11,11 +11,10 @@ module NotionToMd
11
11
  new(blocks: blocks).normalize
12
12
  end
13
13
 
14
- attr_reader :blocks, :normalized_blocks
14
+ attr_reader :normalized_blocks
15
15
 
16
16
  def initialize(blocks:)
17
- @blocks = blocks
18
- @normalized_blocks = blocks
17
+ @normalized_blocks = blocks.dup
19
18
  end
20
19
 
21
20
  def normalize
@@ -35,23 +34,23 @@ module NotionToMd
35
34
  # we need to normalize the blocks we've collected so far.
36
35
  # Then we add the current block to the new blocks array.
37
36
  # This is because we want to keep the order of the blocks.
38
- new_blocks << new_block_and_reset(type, blocks_to_normalize) unless blocks_to_normalize.empty?
37
+ new_blocks << new_block_and_reset_blocks_to_normalize(type) unless blocks_to_normalize.empty?
39
38
  new_blocks << block
40
39
  end
41
40
  end
42
41
 
43
- # If the last block is of the provided type, it won't be added to the new blocks array.
42
+ # If the last block is the provided type, it won't be added to the new blocks array.
44
43
  # So, we need to normalize the blocks we've collected so far.
45
- new_blocks << new_block_and_reset(type, blocks_to_normalize) unless blocks_to_normalize.empty?
44
+ new_blocks << new_block_and_reset_blocks_to_normalize(type) unless blocks_to_normalize.empty?
46
45
 
47
46
  normalized_blocks.replace(new_blocks)
48
47
  end
49
48
 
50
49
  private
51
50
 
52
- def new_block_and_reset(type, children)
53
- new_block = new_block_for(type, children)
54
- reset_blocks_to_normalize
51
+ def new_block_and_reset_blocks_to_normalize(type)
52
+ new_block = new_block_for(type, blocks_to_normalize)
53
+ @blocks_to_normalize = []
55
54
  new_block
56
55
  end
57
56
 
@@ -59,10 +58,6 @@ module NotionToMd
59
58
  @blocks_to_normalize ||= []
60
59
  end
61
60
 
62
- def reset_blocks_to_normalize
63
- @blocks_to_normalize = []
64
- end
65
-
66
61
  def new_block_for(type, children)
67
62
  case type
68
63
  when :bulleted_list_item
@@ -0,0 +1,17 @@
1
+ module NotionToMd
2
+ module Helpers
3
+ module YamlSanitizer
4
+ # Escape the frontmatter value if it contains a colon or a dash followed by a space
5
+ # @param value [String] the value to escape
6
+ # @return [String] the escaped value
7
+ def escape_frontmatter_value(value)
8
+ if value.match?(/: |-\s/)
9
+ # Escape the double quotes inside the string
10
+ "\"#{value.gsub('"', '\"')}\""
11
+ else
12
+ value
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ require_relative './helpers/yaml_sanitizer'
@@ -2,6 +2,8 @@
2
2
 
3
3
  module NotionToMd
4
4
  class Page
5
+ include Helpers::YamlSanitizer
6
+
5
7
  attr_reader :page, :blocks
6
8
 
7
9
  def initialize(page:, blocks:)
@@ -77,11 +79,11 @@ module NotionToMd
77
79
  def default_props
78
80
  @default_props ||= {
79
81
  'id' => id,
80
- 'title' => title,
82
+ 'title' => escape_frontmatter_value(title),
81
83
  'created_time' => created_time,
82
84
  'cover' => cover,
83
85
  'icon' => icon,
84
- 'last_edited_time' => last_edited_time,
86
+ 'last_edited_time' => last_edited_time.to_s.dump,
85
87
  'archived' => archived
86
88
  }
87
89
  end
@@ -3,6 +3,8 @@
3
3
  module NotionToMd
4
4
  class PageProperty
5
5
  class << self
6
+ include Helpers::YamlSanitizer
7
+
6
8
  def file(prop)
7
9
  prop.dig(:file, :url)
8
10
  rescue NoMethodError
@@ -28,7 +30,7 @@ module NotionToMd
28
30
  end
29
31
 
30
32
  def select(prop)
31
- prop.dig(:select, :name)
33
+ escape_frontmatter_value(prop.dig(:select, :name))
32
34
  rescue NoMethodError
33
35
  nil
34
36
  end
@@ -85,7 +87,8 @@ module NotionToMd
85
87
  end
86
88
 
87
89
  def rich_text(prop)
88
- prop[:rich_text].map { |text| text[:plain_text] }.join
90
+ text = prop[:rich_text].map { |text| text[:plain_text] }.join
91
+ text.blank? ? nil : escape_frontmatter_value(text)
89
92
  rescue NoMethodError
90
93
  nil
91
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionToMd
4
- VERSION = '2.3.0'
4
+ VERSION = '2.3.1'
5
5
  end
data/lib/notion_to_md.rb CHANGED
@@ -4,6 +4,7 @@ require 'notion'
4
4
  require 'logger'
5
5
  require 'active_support/inflector'
6
6
  require 'active_support/core_ext/object/blank'
7
+ require_relative './notion_to_md/helpers'
7
8
  require_relative './notion_to_md/version'
8
9
  require_relative './notion_to_md/converter'
9
10
  require_relative './notion_to_md/logger'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_to_md
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrique Arias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-22 00:00:00.000000000 Z
11
+ date: 2023-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -145,6 +145,8 @@ files:
145
145
  - lib/notion_to_md/blocks/to_do_list_item_block.rb
146
146
  - lib/notion_to_md/blocks/types.rb
147
147
  - lib/notion_to_md/converter.rb
148
+ - lib/notion_to_md/helpers.rb
149
+ - lib/notion_to_md/helpers/yaml_sanitizer.rb
148
150
  - lib/notion_to_md/logger.rb
149
151
  - lib/notion_to_md/page.rb
150
152
  - lib/notion_to_md/page_property.rb