notion_to_md 2.0.0 → 2.1.0
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 +4 -4
- data/README.md +4 -1
- data/lib/notion_to_md/blocks/factory.rb +16 -0
- data/lib/notion_to_md/blocks/table_block.rb +27 -0
- data/lib/notion_to_md/blocks/types.rb +12 -0
- data/lib/notion_to_md/blocks.rb +5 -2
- data/lib/notion_to_md/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6cff35e8c8b88f99117499abcc24c89fc98ec723aa4d3380b7b36699e8886e3
|
4
|
+
data.tar.gz: 280543cfe9aae2d20d74336f992c26ab5e83dabe738a6f1b6f5bf9742fb41e36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8808bdd505c6df869f5c06f71d1d763e6f008bc68379528af997b546ff0c6ba1312107b328c3b60b4708949e49a8e03ae8a764acc1e3789fdaf7a5e68b7da2d4
|
7
|
+
data.tar.gz: 5bb5daa841ada70a0ded345fdbf3bbda55aac0e078413f6723ced019029f6ea9a990625f0ee22533766f54b7453e77c40a2b6e59e622dc12f9a3180366fa71bc
|
data/README.md
CHANGED
@@ -56,8 +56,11 @@ Everything in a notion page body is a [block object](https://developers.notion.c
|
|
56
56
|
* `callout`
|
57
57
|
* `quote`
|
58
58
|
* `divider`
|
59
|
+
* `tables`
|
59
60
|
|
60
|
-
|
61
|
+
### Nested blocks
|
62
|
+
|
63
|
+
Starting with v2, nested blocks are supported. For now, only lists are supported, but more elements will be added.
|
61
64
|
|
62
65
|
## Front matter
|
63
66
|
|
@@ -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)
|
data/lib/notion_to_md/blocks.rb
CHANGED
@@ -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,8 @@ 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
|
+
:table
|
13
16
|
].freeze
|
14
17
|
|
15
18
|
# === Parameters
|
@@ -39,7 +42,7 @@ module NotionToMd
|
|
39
42
|
else
|
40
43
|
[]
|
41
44
|
end
|
42
|
-
|
45
|
+
Factory.build(block: block, children: children)
|
43
46
|
end
|
44
47
|
end
|
45
48
|
end
|
data/lib/notion_to_md/version.rb
CHANGED
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
|
+
version: 2.1.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-
|
11
|
+
date: 2022-09-23 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
|