notion_to_md 2.4.0 → 2.4.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: fb94bccdf9dca4374bfaeb42164cce77f3a1963048a96b83a53e238ff9768163
4
- data.tar.gz: '039b7d197fc03a6a04ffaf1cb90f3f758dd597a7381a2002da677065d48f2d76'
3
+ metadata.gz: d2c563b14bee2d927bd6f37cbbc18f59f52545bdc02bcb74e865657231a8d926
4
+ data.tar.gz: e99d9b5e01e3c042e26818ea5eb8b7652701fca9d3a1d94f1c4b5cc41efdca8b
5
5
  SHA512:
6
- metadata.gz: ce0dd31c6a1eb871468b151e2374311799b802b0f58e6e450bcc24aaa76f586f9755ad63953f3b61b45e0102d1440fa3d8f66538c014dbc921fc8ecf01a69a6f
7
- data.tar.gz: 1a008da641c3c449b401ede3e2d65608a47192cae908888bcebd96eba7162e70f7640e549a881c459e9010cd1703248c49fa8d65d3a516489601a80c48e0e87d
6
+ metadata.gz: 0f523319dad22eeae015ab2e52bbd24f04d34acf9f654e4d92a9dcebed1e3a0255f08d8492af371347d2fc81d3acf24d0ef0e51d3a0708a2d143485056e783b9
7
+ data.tar.gz: 8d01b8e6d570da473aa38eb32391f26841ec49e75809ea5733f94974a37a495d731200f3c24a2e3909579ee9ffc1d7d3fcb8b1523fb3070a9d87a711af2be8d9
@@ -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:)
@@ -93,7 +95,7 @@ module NotionToMd
93
95
  def default_props
94
96
  @default_props ||= {
95
97
  'id' => id,
96
- 'title' => title.dump,
98
+ 'title' => escape_frontmatter_value(title),
97
99
  'created_time' => created_time,
98
100
  'cover' => cover,
99
101
  'icon' => icon,
@@ -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).dump
33
+ escape_frontmatter_value(prop.dig(:select, :name))
32
34
  rescue NoMethodError
33
35
  nil
34
36
  end
@@ -95,7 +97,7 @@ module NotionToMd
95
97
 
96
98
  def rich_text(prop)
97
99
  text = prop[:rich_text].map { |text| text[:plain_text] }.join
98
- text.blank? ? nil : text.dump
100
+ text.blank? ? nil : escape_frontmatter_value(text)
99
101
  rescue NoMethodError
100
102
  nil
101
103
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionToMd
4
- VERSION = '2.4.0'
4
+ VERSION = '2.4.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.4.0
4
+ version: 2.4.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-12-14 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