notion_to_md 2.0.0 → 2.2.0

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: 7b301a14c22e1790633fc88c179d3882521f9c9632655b6fd9fc883cf128e9dc
4
- data.tar.gz: 528414ba605c3e03bb3599ea70b7e998768cba3ba56429aaa23523f203b8de19
3
+ metadata.gz: fed0fc0d3030e3c31473dec2d1082831156f52327e3afb4864732030365195f5
4
+ data.tar.gz: 917cccf40edfb7355717bf855f3681baa57353ccd1390c34b96133c01524dd74
5
5
  SHA512:
6
- metadata.gz: df30fc42ab07586e39a73f6ca8ddd6742e8672c5701c78c67eb4059515403090f71466fe550c3f54617edd110b395843a366f647492da687a43cc3aedf61b27c
7
- data.tar.gz: c102997be2946fab86cd2ba837119ec34cb51da23e9104662f8cb4006930ad9aa916067fa02a26c9de066c7ceb34dc33878c01e64f800c0160aeffb172efe5f2
6
+ metadata.gz: 2c2498e638e6e80f8dcda4e888bb34e2572fd448f3ced78e2b5f00d33478466ac1322c223196388219fc68170cff832f61ad5a63e834c595e492ba64b6d9c797
7
+ data.tar.gz: 8ee37c94729d2140b0d85520648855fe2139875aa77b2bf8def9e631071bd08212fcaf7c911f9665fdd14862043234b6f0a967031522e04c031c684efad17856
data/README.md CHANGED
@@ -56,8 +56,18 @@ Everything in a notion page body is a [block object](https://developers.notion.c
56
56
  * `callout`
57
57
  * `quote`
58
58
  * `divider`
59
+ * `table`
60
+ * `embed`
61
+ * `code`
59
62
 
60
- **Note: children nested blocks are not supported.**
63
+ ### Nested blocks
64
+
65
+ Starting with v2, nested blocks are supported. The permitted blocks to have children are:
66
+
67
+ * `paragraph`
68
+ * `bulleted_list_item`
69
+ * `numbered_list_item`
70
+ * `to_do`
61
71
 
62
72
  ## Front matter
63
73
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionToMd
4
+ module Blocks
5
+ class Factory
6
+ def self.build(block:, children: [])
7
+ case block.type.to_sym
8
+ when :table
9
+ TableBlock.new(block: block, children: children)
10
+ else
11
+ Blocks::Block.new(block: block, children: children)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionToMd
4
+ module Blocks
5
+ class TableBlock < Block
6
+ def to_md
7
+ table = markdownify_children(0)
8
+
9
+ table_header = table[0]
10
+ table_aligment = markdownify_aligment
11
+ table_body = table[1..table.size]
12
+
13
+ [table_header, table_aligment, table_body.join("\n")].compact.join("\n")
14
+ end
15
+
16
+ private
17
+
18
+ def row_size
19
+ @row_size ||= children.first.block.table_row.cells.size
20
+ end
21
+
22
+ def markdownify_aligment
23
+ "|#{row_size.times.map { '---' }.join('|')}|" if block.table.has_column_header
24
+ end
25
+ end
26
+ end
27
+ end
@@ -84,8 +84,20 @@ module NotionToMd
84
84
  '<br />'
85
85
  end
86
86
 
87
+ def table_row(block)
88
+ "|#{block[:cells].map(&method(:convert_table_row)).join('|')}|"
89
+ end
90
+
87
91
  private
88
92
 
93
+ def convert_table_row(cells)
94
+ cells.map(&method(:convert_table_cell))
95
+ end
96
+
97
+ def convert_table_cell(text)
98
+ convert_text({ rich_text: [text] })
99
+ end
100
+
89
101
  def convert_text(block)
90
102
  block[:rich_text].map do |text|
91
103
  content = Text.send(text[:type], text)
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative './blocks/block'
4
+ require_relative './blocks/factory'
5
+ require_relative './blocks/table_block'
4
6
  require_relative './blocks/types'
5
7
 
6
8
  module NotionToMd
@@ -9,7 +11,10 @@ module NotionToMd
9
11
  # Array containing the block types allowed to have nested blocks (children).
10
12
  PERMITTED_CHILDREN = [
11
13
  Types.method(:bulleted_list_item).name,
12
- Types.method(:numbered_list_item).name
14
+ Types.method(:numbered_list_item).name,
15
+ Types.method(:paragraph).name,
16
+ Types.method(:to_do).name,
17
+ :table
13
18
  ].freeze
14
19
 
15
20
  # === Parameters
@@ -39,7 +44,7 @@ module NotionToMd
39
44
  else
40
45
  []
41
46
  end
42
- Blocks::Block.new(block: block, children: children)
47
+ Factory.build(block: block, children: children)
43
48
  end
44
49
  end
45
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionToMd
4
- VERSION = '2.0.0'
4
+ VERSION = '2.2.0'
5
5
  end
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.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrique Arias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-09 00:00:00.000000000 Z
11
+ date: 2022-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -104,6 +104,8 @@ files:
104
104
  - lib/notion_to_md.rb
105
105
  - lib/notion_to_md/blocks.rb
106
106
  - lib/notion_to_md/blocks/block.rb
107
+ - lib/notion_to_md/blocks/factory.rb
108
+ - lib/notion_to_md/blocks/table_block.rb
107
109
  - lib/notion_to_md/blocks/types.rb
108
110
  - lib/notion_to_md/converter.rb
109
111
  - lib/notion_to_md/logger.rb