jupyter_to_scrapbox 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/jupyter_to_scrapbox +2 -0
- data/lib/jupyter_to_scrapbox/version.rb +1 -1
- data/lib/jupyter_to_scrapbox.rb +31 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6440292ab6d8a4baef46db1db99a9c1929f505aa
|
4
|
+
data.tar.gz: 700b0fe22a7b4ee0025f6d4846310e4b4acab625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b0a86f60698038fcce4632445ad5ed77b5b41dcee5aae8be77359b4ce204fca90a2a08616167a6f2561cb3dc20063c864597a72989b5ff2a46baaea01b2deb9
|
7
|
+
data.tar.gz: 8431644eaff652863c7e6bc3cc0ff413a1aa6105894e10e56212d4f3adf7f00e9b9f2f2aa8a9da190977e5b5e0fec7abefd58ccfd6b8da07a64d08a61b287a87
|
data/exe/jupyter_to_scrapbox
CHANGED
@@ -11,10 +11,12 @@ module JupyterToScrapbox
|
|
11
11
|
default_task :help
|
12
12
|
|
13
13
|
method_option :verbose, type: :boolean, aliases: '-v', desc: 'verbose message'
|
14
|
+
method_option :moderate, type: :boolean, aliases: '-m', desc: 'moderate mode: do not convert markdown notations'
|
14
15
|
desc 'converts FILES [options]', 'Convert jupyter-notebook files to scrapbox-json'
|
15
16
|
|
16
17
|
def convert(*paths)
|
17
18
|
JupyterToScrapbox::Converter.set_verbose() if options[:verbose]
|
19
|
+
JupyterToScrapbox::Converter.set_moderate() if options[:moderate]
|
18
20
|
paths.each do |path|
|
19
21
|
JupyterToScrapbox::Converter.add(path)
|
20
22
|
end
|
data/lib/jupyter_to_scrapbox.rb
CHANGED
@@ -7,11 +7,16 @@ module JupyterToScrapbox
|
|
7
7
|
class Converter
|
8
8
|
@@verbose=false
|
9
9
|
@@converters=[]
|
10
|
+
@@parse_markdown_notations=true
|
10
11
|
|
11
12
|
def Converter.set_verbose()
|
12
13
|
@@verbose=true
|
13
14
|
end
|
14
15
|
|
16
|
+
def Converter.set_moderate()
|
17
|
+
@@parse_markdown_notations=false
|
18
|
+
end
|
19
|
+
|
15
20
|
def Converter.add(path)
|
16
21
|
@@converters.push Converter.new(path)
|
17
22
|
end
|
@@ -48,19 +53,13 @@ module JupyterToScrapbox
|
|
48
53
|
puts(s) if @@verbose
|
49
54
|
end
|
50
55
|
|
51
|
-
def push_text(s)
|
52
|
-
s.split("\n").each do |s1|
|
53
|
-
@sb_json << s1
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
56
|
def push_empty_text()
|
58
57
|
@sb_json << ""
|
59
58
|
end
|
60
59
|
|
61
|
-
def
|
60
|
+
def push_text(s)
|
62
61
|
s.split("\n").each do |s1|
|
63
|
-
@sb_json <<
|
62
|
+
@sb_json << s1
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
@@ -70,16 +69,37 @@ module JupyterToScrapbox
|
|
70
69
|
end
|
71
70
|
end
|
72
71
|
|
73
|
-
def
|
72
|
+
def push_markdown_text(s)
|
73
|
+
s.split("\n").each do |s1|
|
74
|
+
if @@parse_markdown_notations
|
75
|
+
s1.sub!(%r!^\$\$(.+)\$\$!, '[$\1 ]' ) || s1.gsub!(%r!\$(.+)\$!, '[$\1 ]' )
|
76
|
+
end
|
77
|
+
@sb_json << s1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def push_markdown_texts(ww)
|
74
82
|
ww.each do |s|
|
75
|
-
|
83
|
+
push_markdown_text(s)
|
76
84
|
end
|
77
85
|
end
|
78
86
|
|
79
87
|
def parse_cell_markdown(md)
|
80
88
|
vputs "-- source"
|
81
89
|
vputs md["source"]
|
82
|
-
|
90
|
+
push_markdown_texts(md["source"])
|
91
|
+
end
|
92
|
+
|
93
|
+
def push_code(s)
|
94
|
+
s.split("\n").each do |s1|
|
95
|
+
@sb_json << "\t"+s1
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def push_codes(ww)
|
100
|
+
ww.each do |s|
|
101
|
+
push_code(s)
|
102
|
+
end
|
83
103
|
end
|
84
104
|
|
85
105
|
def parse_cell_code(code)
|