md_to_notion 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/md_to_notion/blocks.rb +4 -4
- data/lib/md_to_notion/lexer.rb +22 -0
- data/lib/md_to_notion/parser.rb +4 -1
- data/lib/md_to_notion/tokens.rb +10 -2
- data/lib/md_to_notion/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bb3261937841eeceb6f7c5ac2554f580fc30722941f787886357fe26d891835
|
4
|
+
data.tar.gz: 7732a1c06dc5e157bba946050ca97be414bc25f382059fc0457f65057a058de7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
57
|
+
md_to_notion!
|
58
58
|
pry
|
59
59
|
rake (~> 13.0)
|
60
60
|
rspec (~> 3.0)
|
data/lib/md_to_notion/blocks.rb
CHANGED
data/lib/md_to_notion/lexer.rb
CHANGED
@@ -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}" \
|
data/lib/md_to_notion/parser.rb
CHANGED
@@ -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.
|
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
|
data/lib/md_to_notion/tokens.rb
CHANGED
@@ -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
|
-
|
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)
|
data/lib/md_to_notion/version.rb
CHANGED