Class: NotionToMd::Blocks::Types

Inherits:
Object
  • Object
show all
Defined in:
lib/notion_to_md/blocks/types.rb

Class Method Summary collapse

Class Method Details

.blankObject



84
85
86
# File 'lib/notion_to_md/blocks/types.rb', line 84

def blank
  '<br />'
end

.bookmark(block) ⇒ Object



75
76
77
78
# File 'lib/notion_to_md/blocks/types.rb', line 75

def bookmark(block)
  url = block[:url]
  "[#{url}](#{url})"
end

.bulleted_list_item(block) ⇒ Object



35
36
37
# File 'lib/notion_to_md/blocks/types.rb', line 35

def bulleted_list_item(block)
  "- #{convert_text(block)}"
end

.callout(block) ⇒ Object



25
26
27
28
29
# File 'lib/notion_to_md/blocks/types.rb', line 25

def callout(block)
  icon = get_icon(block[:icon])
  text = convert_text(block)
  "> #{icon} #{text}"
end

.code(block) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/notion_to_md/blocks/types.rb', line 52

def code(block)
  language = block[:language]
  text = convert_text(block)

  language = 'text' if language == 'plain text'

  "```#{language}\n#{text}\n```"
end

.divider(_block) ⇒ Object



80
81
82
# File 'lib/notion_to_md/blocks/types.rb', line 80

def divider(_block)
  '---'
end

.embed(block) ⇒ Object



61
62
63
64
65
# File 'lib/notion_to_md/blocks/types.rb', line 61

def embed(block)
  url = block[:url]

  "[#{url}](#{url})"
end

.file(block) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/notion_to_md/blocks/types.rb', line 98

def file(block)
  type = block[:type].to_sym
  url = block.dig(type, :url)
  caption = convert_caption(block)

  "[#{url}](#{url})\n\n#{caption}"
end

.heading_1(block) ⇒ Object



13
14
15
# File 'lib/notion_to_md/blocks/types.rb', line 13

def heading_1(block)
  "# #{convert_text(block)}"
end

.heading_2(block) ⇒ Object



17
18
19
# File 'lib/notion_to_md/blocks/types.rb', line 17

def heading_2(block)
  "## #{convert_text(block)}"
end

.heading_3(block) ⇒ Object



21
22
23
# File 'lib/notion_to_md/blocks/types.rb', line 21

def heading_3(block)
  "### #{convert_text(block)}"
end

.image(block) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/notion_to_md/blocks/types.rb', line 67

def image(block)
  type = block[:type].to_sym
  url = block.dig(type, :url)
  caption = convert_caption(block)

  "![](#{url})\n\n#{caption}"
end


92
93
94
95
96
# File 'lib/notion_to_md/blocks/types.rb', line 92

def link_preview(block)
  url = block[:url]

  "[#{url}](#{url})"
end

.numbered_list_item(block, index = nil) ⇒ Object



39
40
41
42
43
# File 'lib/notion_to_md/blocks/types.rb', line 39

def numbered_list_item(block, index = nil)
  return bulleted_list_item(block) if index.nil?

  "#{index}. #{convert_text(block)}"
end

.paragraph(block) ⇒ Object



7
8
9
10
11
# File 'lib/notion_to_md/blocks/types.rb', line 7

def paragraph(block)
  return blank if block[:rich_text].empty?

  convert_text(block)
end

.pdf(block) ⇒ Object



106
107
108
# File 'lib/notion_to_md/blocks/types.rb', line 106

def pdf(block)
  file(block)
end

.quote(block) ⇒ Object



31
32
33
# File 'lib/notion_to_md/blocks/types.rb', line 31

def quote(block)
  "> #{convert_text(block)}"
end

.table_row(block) ⇒ Object



88
89
90
# File 'lib/notion_to_md/blocks/types.rb', line 88

def table_row(block)
  "|#{block[:cells].map(&method(:convert_table_row)).join('|')}|"
end

.to_do(block) ⇒ Object



45
46
47
48
49
50
# File 'lib/notion_to_md/blocks/types.rb', line 45

def to_do(block)
  checked = block[:checked]
  text = convert_text(block)

  "- #{checked ? '[x]' : '[ ]'} #{text}"
end

.video(block) ⇒ Object



110
111
112
# File 'lib/notion_to_md/blocks/types.rb', line 110

def video(block)
  file(block)
end