Sha256: ecc78b5bcc189b535e20b9f80985f03b6b1e346e1bb62a9ed827c27f0f854666
Contents?: true
Size: 1.11 KB
Versions: 4
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true require_relative "./lexer" require_relative "./blocks" module MdToNotion module Parser def self.markdown_to_ast(markdown) lexer = Lexer.new(markdown) lexer.tokenize end def self.markdown_to_notion_blocks(markdown) ast = markdown_to_ast(markdown) ast_to_notion_blocks(ast) end 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.image(token[:text], token[:rich_texts]) when :quote Block.quote(token[:rich_texts]) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
md_to_notion-0.1.3 | lib/md_to_notion/parser.rb |
md_to_notion-0.1.2 | lib/md_to_notion/parser.rb |
md_to_notion-0.1.1 | lib/md_to_notion/parser.rb |
md_to_notion-0.1.0 | lib/md_to_notion/parser.rb |