md_to_notion 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f7e3d6a39e5a9e69c12981ce364dafa09c0b64907e686ec7c047a7ddb2a16ab
4
- data.tar.gz: 8e28782aee8e0f65f953908fe43aad2cf5abea155df40f132525e7b4983510c8
3
+ metadata.gz: 3bb3261937841eeceb6f7c5ac2554f580fc30722941f787886357fe26d891835
4
+ data.tar.gz: 7732a1c06dc5e157bba946050ca97be414bc25f382059fc0457f65057a058de7
5
5
  SHA512:
6
- metadata.gz: 1ad09b039f56f690516d210a1caf6824ede4a7bc1c4fcc56dd1b77ecf3dcce77c0995f22dba376e74f5389d7a0313e208d9e91942acd4677bc5e2cc54a474d3a
7
- data.tar.gz: ab007563cadfc0d1ef3971b05c2458342cb17ca3b58946aada8f12a37db633185cc75e5afaac22b7d403e4058d24a133e65b78b98806f5a6323e9448fceeb2eb
6
+ metadata.gz: 2166f971bef23960488d13491ea3ddc6bc6913c12764491a501c0c6950115a3e8269a1a9fa5b57f7da8d4dfc3888daa9e03617e24ca311594a6e35168c902a19
7
+ data.tar.gz: cbd4ef195a6527ab8671bbd3b1bed5b56332e9d82ca71afdff0c5bc8311364bcacd3a1a1c27dd5be6003428921fd52d90cf7d42dabce9e14757ee5d59ed5e03f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- md-to-notion (0.1.0)
4
+ md_to_notion (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -54,7 +54,7 @@ PLATFORMS
54
54
  x86_64-linux
55
55
 
56
56
  DEPENDENCIES
57
- md-to-notion!
57
+ md_to_notion!
58
58
  pry
59
59
  rake (~> 13.0)
60
60
  rspec (~> 3.0)
@@ -87,13 +87,13 @@ module MdToNotion
87
87
  block
88
88
  end
89
89
 
90
- def self.image
90
+ def self.file(url, type:)
91
91
  {
92
- type: "image",
93
- image: {
92
+ type: type,
93
+ "#{type}": {
94
94
  type: "external",
95
95
  external: {
96
- url: link
96
+ url: url
97
97
  }
98
98
  }
99
99
  }
@@ -6,6 +6,10 @@ module MdToNotion
6
6
  class Lexer
7
7
  include Tokens
8
8
 
9
+ ALLOWED_VIDEO_EMBED_URLS = [
10
+ "https://user-images.githubusercontent.com/"
11
+ ]
12
+
9
13
  class InvalidTokenSyntaxError < StandardError; end
10
14
 
11
15
  def initialize(markdown)
@@ -29,6 +33,8 @@ module MdToNotion
29
33
  tokenize_link
30
34
  elsif next_char == "!"
31
35
  tokenize_image
36
+ elsif ALLOWED_VIDEO_EMBED_URLS.join("").include?(peek(41))
37
+ tokenize_embeded_file
32
38
  elsif next_char == ">"
33
39
  tokenize_quote
34
40
  elsif next_char == "-"
@@ -111,6 +117,22 @@ module MdToNotion
111
117
  @index += ::Regexp.last_match(0).length
112
118
  end
113
119
 
120
+ def tokenize_embeded_file
121
+ line = @markdown[@index..].split("\n").first
122
+ match = nil
123
+ EMBED_FILE_REGEXES.each do |regex|
124
+ if line =~ regex
125
+ match = ::Regexp.last_match(0)
126
+ break
127
+ end
128
+ end
129
+
130
+ raise InvalidTokenSyntaxError, "Invalid embed file syntax: #{line}" unless match
131
+
132
+ @tokens << embeded_file(match)
133
+ @index += match.length
134
+ end
135
+
114
136
  def tokenize_quote
115
137
  line = @markdown[@index..].split("\n").first
116
138
  raise InvalidTokenSyntaxError, "Invalid quote syntax: #{line}" \
@@ -33,7 +33,10 @@ module MdToNotion
33
33
  when :numbered_list
34
34
  Block.numbered_list(token[:rich_texts])
35
35
  when :image
36
- Block.image(token[:text], token[:rich_texts])
36
+ Block.file(token[:url], type: "image")
37
+ when :embeded_file
38
+ # @TODO support more file types
39
+ Block.file(token[:url], type: "video")
37
40
  when :quote
38
41
  Block.quote(token[:rich_texts])
39
42
  end
@@ -10,6 +10,8 @@ module MdToNotion
10
10
  NUMBERED_LIST = /^([0-9]+)\. (.+)/.freeze
11
11
  IMAGE = /!\[([^\]]+)\]\(([^)]+)\)/.freeze
12
12
  QUOTE = /^> (.+)/.freeze
13
+ GH_EMBED_FILE = %r{https://user-images\.githubusercontent\.com/.+\.[a-zA-Z]+}.freeze
14
+ EMBED_FILE_REGEXES = [GH_EMBED_FILE].freeze
13
15
 
14
16
  def heading_1(match)
15
17
  { type: :heading_1, rich_texts: tokenize_rich_text(match.gsub(/^# /, "")) }
@@ -51,8 +53,7 @@ module MdToNotion
51
53
  def image(match)
52
54
  {
53
55
  type: :image,
54
- rich_texts: tokenize_rich_text(match.gsub(/!\[([^\]]+)\]\(([^)]+)\)/, '\1')),
55
- link: match.gsub(/!\[([^\]]+)\]\(([^)]+)\)/, '\2')
56
+ url: match.gsub(/!\[([^\]]+)\]\(([^)]+)\)/, '\2')
56
57
  }
57
58
  end
58
59
 
@@ -64,6 +65,13 @@ module MdToNotion
64
65
  { type: :quote, rich_texts: tokenize_rich_text(match.gsub(/^> /, "")) }
65
66
  end
66
67
 
68
+ def embeded_file(match)
69
+ {
70
+ type: :embeded_file,
71
+ url: match
72
+ }
73
+ end
74
+
67
75
  ## rich text objects
68
76
 
69
77
  def tokenize_rich_text(text)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MdToNotion
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md_to_notion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - rieg-ec