Module: MdToNotion::Parser
- Defined in:
- lib/md_to_notion/parser.rb
Class Method Summary collapse
- .ast_to_notion_blocks(ast) ⇒ Object
- .markdown_to_ast(markdown) ⇒ Object
- .markdown_to_notion_blocks(markdown) ⇒ Object
Class Method Details
.ast_to_notion_blocks(ast) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/md_to_notion/parser.rb', line 18 def self.ast_to_notion_blocks(ast) ast.map do |token| case token[:type] when :heading_1 Block.heading_1(token[:rich_texts]) when :heading_2 Block.heading_2(token[:rich_texts]) when :heading_3 Block.heading_3(token[:rich_texts]) when :paragraph Block.paragraph(token[:rich_texts]) when :code_block Block.code(token[:text], lang: token[:lang]) when :bullet_list Block.bulleted_list_item(token[:rich_texts]) when :numbered_list Block.numbered_list(token[:rich_texts]) when :image Block.file(token[:url], type: "image") when :embeded_file # @TODO support more file types Block.file(token[:url], type: "video") when :quote Block.quote(token[:rich_texts]) end end end |
.markdown_to_ast(markdown) ⇒ Object
8 9 10 11 |
# File 'lib/md_to_notion/parser.rb', line 8 def self.markdown_to_ast(markdown) lexer = Lexer.new(markdown) lexer.tokenize end |
.markdown_to_notion_blocks(markdown) ⇒ Object
13 14 15 16 |
# File 'lib/md_to_notion/parser.rb', line 13 def self.markdown_to_notion_blocks(markdown) ast = markdown_to_ast(markdown) ast_to_notion_blocks(ast) end |