Module: MdToNotion::Block
- Defined in:
- lib/md_to_notion/blocks.rb
Class Method Summary collapse
- .bulleted_list_item(texts, children: nil) ⇒ Object
- .code(text, lang: nil) ⇒ Object
- .file(url, type:) ⇒ Object
- .heading_1(texts) ⇒ Object
- .heading_2(texts) ⇒ Object
- .heading_3(texts) ⇒ Object
- .numbered_list(texts, children: nil) ⇒ Object
- .paragraph(texts, children: nil) ⇒ Object
- .quote(texts, children: nil) ⇒ Object
- .rich_text(token, annotations: {}, href: nil, link: nil) ⇒ Object
Class Method Details
.bulleted_list_item(texts, children: nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/md_to_notion/blocks.rb', line 66 def self.bulleted_list_item(texts, children: nil) block = { type: "bulleted_list_item", bulleted_list_item: { rich_text: texts.map { |t| rich_text(t) } } } block[:bulleted_list_item][:children] = children if children block end |
.code(text, lang: nil) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/md_to_notion/blocks.rb', line 56 def self.code(text, lang: nil) { type: "code", code: { rich_text: [rich_text({ text: text })], language: lang } } end |
.file(url, type:) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/md_to_notion/blocks.rb', line 90 def self.file(url, type:) { type: type, "#{type}": { type: "external", external: { url: url } } } end |
.heading_1(texts) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/md_to_notion/blocks.rb', line 5 def self.heading_1(texts) { type: "heading_1", heading_1: { rich_text: texts.map { |t| rich_text(t) } } } end |
.heading_2(texts) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/md_to_notion/blocks.rb', line 14 def self.heading_2(texts) { type: "heading_2", heading_2: { rich_text: texts.map { |t| rich_text(t) } } } end |
.heading_3(texts) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/md_to_notion/blocks.rb', line 23 def self.heading_3(texts) { type: "heading_3", heading_3: { rich_text: texts.map { |t| rich_text(t) } } } end |
.numbered_list(texts, children: nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/md_to_notion/blocks.rb', line 78 def self.numbered_list(texts, children: nil) block = { type: "numbered_list_item", numbered_list_item: { rich_text: texts.map { |t| rich_text(t) } } } block[:numbered_list_item][:children] = children if children block end |
.paragraph(texts, children: nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/md_to_notion/blocks.rb', line 32 def self.paragraph(texts, children: nil) block = { type: "paragraph", paragraph: { rich_text: texts.map { |t| rich_text(t) } } } block[:paragraph][:children] = children if children block end |
.quote(texts, children: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/md_to_notion/blocks.rb', line 44 def self.quote(texts, children: nil) block = { type: "quote", quote: { rich_text: texts.map { |t| rich_text(t) } } } block[:quote][:children] = children if children block end |
.rich_text(token, annotations: {}, href: nil, link: nil) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/md_to_notion/blocks.rb', line 102 def self.rich_text(token, annotations: {}, href: nil, link: nil) default_annotations = { bold: token[:type] == :bold, italic: token[:type] == :italic, strikethrough: token[:type] == :strikethrough, underline: token[:type] == :underline, code: token[:type] == :code } { type: "text", text: { content: token[:text], link: link }, annotations: default_annotations.merge(annotations), href: href } end |