md2key 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +0 -2
- data/lib/md2key/converter.rb +2 -2
- data/lib/md2key/keynote.rb +33 -6
- data/lib/md2key/line.rb +12 -0
- data/lib/md2key/markdown.rb +13 -9
- data/lib/md2key/pbcopy.rb +10 -0
- data/lib/md2key/version.rb +1 -1
- data/lib/md2key.rb +0 -1
- data/scripts/create_slide_and_select_body.scpt +25 -0
- data/scripts/{create_slide.scpt → create_slide_and_write_body.scpt} +0 -0
- data/scripts/paste_and_indent.scpt +24 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28d015849054d2a590b378c0cc9b2f264a512f2a
|
4
|
+
data.tar.gz: f8ee2819fc70e399307cb661714f361368eef24f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cbc3372b60e6a90b6aa78b35864429361e7e62c4a2417990bca2cc4d02ce90e79da403d2df4fe8ba70358caffe93fdfd090e3978e58d0e9dcd363eb156d80e5
|
7
|
+
data.tar.gz: 113be3fa091632a54984f0eb2b18216f75b0af9a2829881d338ddef29284f453ecfb4736163597015557036397c114c6c1eabdeb35e52d0b5233e9d53c0d55e3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# v0.5.0
|
2
|
+
|
3
|
+
- Support nested list
|
4
|
+
- https://github.com/k0kubun/md2key/pull/23
|
5
|
+
|
6
|
+
# v0.4.4
|
7
|
+
|
8
|
+
- Bugfix for code listing without extension
|
9
|
+
- https://github.com/k0kubun/md2key/pull/17
|
10
|
+
- Thanks to @ainoya
|
11
|
+
|
1
12
|
# v0.4.3
|
2
13
|
|
3
14
|
- Support relative path for images
|
data/README.md
CHANGED
data/lib/md2key/converter.rb
CHANGED
@@ -25,9 +25,9 @@ module Md2key
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def generate_contents
|
28
|
-
Keynote.update_cover(@markdown.cover
|
28
|
+
Keynote.update_cover(@markdown.cover)
|
29
29
|
@markdown.slides.each_with_index do |slide, index|
|
30
|
-
Keynote.create_slide(slide
|
30
|
+
Keynote.create_slide(slide)
|
31
31
|
Keynote.insert_image(slide.image) if slide.image
|
32
32
|
Keynote.insert_code(slide.code) if slide.code
|
33
33
|
end
|
data/lib/md2key/keynote.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'md2key/pbcopy'
|
2
|
+
|
1
3
|
module Md2key
|
2
4
|
class Keynote
|
3
5
|
COVER_SLIDE_INDEX = 1
|
@@ -6,8 +8,19 @@ module Md2key
|
|
6
8
|
|
7
9
|
class << self
|
8
10
|
# You must provide a first slide as a cover slide.
|
9
|
-
|
10
|
-
|
11
|
+
# @param [Md2key::Slide] slide
|
12
|
+
def update_cover(slide)
|
13
|
+
execute_applescript('update_slide', slide.title, slide.lines.map(&:text).join("\n"), COVER_SLIDE_INDEX)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [Md2key::Slide] slide
|
17
|
+
def create_slide(slide)
|
18
|
+
if slide.lines.any?(&:indented?)
|
19
|
+
create_indented_slide(slide)
|
20
|
+
else
|
21
|
+
# Not using `create_indented_slide` because this is faster.
|
22
|
+
execute_applescript('create_slide_and_write_body', slide.title, slide.lines.map(&:text).join("\n"), TEMPLATE_SLIDE_INDEX)
|
23
|
+
end
|
11
24
|
end
|
12
25
|
|
13
26
|
def ensure_template_slide_availability
|
@@ -24,10 +37,6 @@ module Md2key
|
|
24
37
|
execute_applescript('delete_slide', TEMPLATE_SLIDE_INDEX)
|
25
38
|
end
|
26
39
|
|
27
|
-
def create_slide(title, content)
|
28
|
-
execute_applescript('create_slide', title, content, TEMPLATE_SLIDE_INDEX)
|
29
|
-
end
|
30
|
-
|
31
40
|
# Insert image to the last slide
|
32
41
|
def insert_image(path)
|
33
42
|
execute_applescript('insert_image', slides_count, File.absolute_path(path), TEMPLATE_SLIDE_INDEX)
|
@@ -58,6 +67,24 @@ module Md2key
|
|
58
67
|
execute_applescript('slides_count').to_i
|
59
68
|
end
|
60
69
|
|
70
|
+
# @param [Md2key::Slide] slide
|
71
|
+
def create_indented_slide(slide)
|
72
|
+
execute_applescript('create_slide_and_select_body', slide.title, TEMPLATE_SLIDE_INDEX)
|
73
|
+
|
74
|
+
last_index = slide.lines.size - 1
|
75
|
+
current_indent = 0
|
76
|
+
slide.lines.each_with_index do |line, index|
|
77
|
+
# Using copy and paste to input multibyte chars
|
78
|
+
Pbcopy.copy(line.text)
|
79
|
+
paste_and_indent(line.indent - current_indent, insert_newline: index < last_index)
|
80
|
+
current_indent = line.indent
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def paste_and_indent(indent, insert_newline: true)
|
85
|
+
execute_applescript('paste_and_indent', indent, insert_newline)
|
86
|
+
end
|
87
|
+
|
61
88
|
def execute_applescript(script_name, *args)
|
62
89
|
path = script_path(script_name)
|
63
90
|
`osascript #{path} "#{args.join('" "')}"`
|
data/lib/md2key/line.rb
ADDED
data/lib/md2key/markdown.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'md2key/line'
|
2
|
+
require 'md2key/slide'
|
2
3
|
require 'oga'
|
4
|
+
require 'redcarpet'
|
3
5
|
|
4
6
|
# Parse markdown, generate AST and convert it to slides.
|
5
7
|
# This is created to be compatible with Deckset.
|
@@ -12,10 +14,12 @@ module Md2key
|
|
12
14
|
@ast = Oga.parse_xml(xhtml)
|
13
15
|
end
|
14
16
|
|
17
|
+
# @return [Md2key::Slide]
|
15
18
|
def cover
|
16
19
|
cached_slides.first
|
17
20
|
end
|
18
21
|
|
22
|
+
# @return [Array<Md2key::Slide>]
|
19
23
|
def slides
|
20
24
|
cached_slides[1..-1]
|
21
25
|
end
|
@@ -46,15 +50,14 @@ module Md2key
|
|
46
50
|
slides << slide
|
47
51
|
slide.title = node.text
|
48
52
|
when 'ul'
|
49
|
-
|
50
|
-
slide.lines += li_texts(node).flatten
|
53
|
+
slide.lines.concat(li_lines(node))
|
51
54
|
when 'p'
|
52
55
|
node.children.each do |child|
|
53
56
|
if child.is_a?(Oga::XML::Element) && child.name == 'img'
|
54
57
|
slide.image = child.attribute('src').value
|
55
58
|
next
|
56
59
|
end
|
57
|
-
slide.lines << child.text
|
60
|
+
slide.lines << Line.new(child.text)
|
58
61
|
end
|
59
62
|
when 'pre'
|
60
63
|
node.children.each do |child|
|
@@ -69,11 +72,12 @@ module Md2key
|
|
69
72
|
slides
|
70
73
|
end
|
71
74
|
|
72
|
-
|
75
|
+
# @return [Array<Md2Key::Line>]
|
76
|
+
def li_lines(ul_node, indent: 0)
|
73
77
|
return [] unless ul_node.is_a?(Oga::XML::Element)
|
74
78
|
return [] if ul_node.name != 'ul'
|
75
79
|
|
76
|
-
|
80
|
+
lines = []
|
77
81
|
ul_node.children.each do |li_node|
|
78
82
|
next unless li_node.is_a?(Oga::XML::Element)
|
79
83
|
next if li_node.name != 'li'
|
@@ -82,14 +86,14 @@ module Md2key
|
|
82
86
|
case node
|
83
87
|
when Oga::XML::Text
|
84
88
|
text = node.text.strip
|
85
|
-
|
89
|
+
lines << Line.new(text, indent) unless text.empty?
|
86
90
|
when Oga::XML::Element
|
87
91
|
next if node.name != 'ul'
|
88
|
-
|
92
|
+
lines.concat(li_lines(node, indent: indent + 1))
|
89
93
|
end
|
90
94
|
end
|
91
95
|
end
|
92
|
-
|
96
|
+
lines
|
93
97
|
end
|
94
98
|
|
95
99
|
def to_xhtml(markdown)
|
data/lib/md2key/version.rb
CHANGED
data/lib/md2key.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
on run argv
|
2
|
+
set slideTitle to item 1 of argv
|
3
|
+
set templateIndex to item 2 of argv as number
|
4
|
+
|
5
|
+
tell application "Keynote"
|
6
|
+
activate
|
7
|
+
|
8
|
+
tell the front document
|
9
|
+
-- Workaround to select correct master slide. In spite of master slide can be selected by name,
|
10
|
+
-- name property is not limited to be unique.
|
11
|
+
-- So move the focus to second slide and force "make new slide" to use the exact master slide.
|
12
|
+
move slide templateIndex to before slide templateIndex
|
13
|
+
|
14
|
+
set newSlide to make new slide
|
15
|
+
tell newSlide
|
16
|
+
set object text of default title item to slideTitle
|
17
|
+
|
18
|
+
-- select the default body item
|
19
|
+
set position of default body item to position of default body item
|
20
|
+
-- press the Enter key
|
21
|
+
tell application "System Events" to key code 76
|
22
|
+
end tell
|
23
|
+
end tell
|
24
|
+
end tell
|
25
|
+
end run
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
on run argv
|
2
|
+
set indent to item 1 of argv as number
|
3
|
+
set insertNewline to item 2 of argv as boolean
|
4
|
+
|
5
|
+
tell application "System Events"
|
6
|
+
keystroke "v" using { command down }
|
7
|
+
|
8
|
+
if indent is greater than 0 then
|
9
|
+
repeat indent times
|
10
|
+
key code 48 -- tab
|
11
|
+
end repeat
|
12
|
+
else
|
13
|
+
if indent is less than 0 then
|
14
|
+
repeat indent * -1 times
|
15
|
+
key code 48 using { shift down } -- tab
|
16
|
+
end repeat
|
17
|
+
end if
|
18
|
+
end if
|
19
|
+
|
20
|
+
if insertNewline is true then
|
21
|
+
key code 36 -- return
|
22
|
+
end if
|
23
|
+
end tell
|
24
|
+
end run
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: md2key
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -115,17 +115,21 @@ files:
|
|
115
115
|
- lib/md2key/converter.rb
|
116
116
|
- lib/md2key/highlight.rb
|
117
117
|
- lib/md2key/keynote.rb
|
118
|
+
- lib/md2key/line.rb
|
118
119
|
- lib/md2key/markdown.rb
|
120
|
+
- lib/md2key/pbcopy.rb
|
119
121
|
- lib/md2key/slide.rb
|
120
122
|
- lib/md2key/version.rb
|
121
123
|
- md2key.gemspec
|
122
124
|
- scripts/activate_slide.scpt
|
123
125
|
- scripts/create_empty_slide.scpt
|
124
|
-
- scripts/
|
126
|
+
- scripts/create_slide_and_select_body.scpt
|
127
|
+
- scripts/create_slide_and_write_body.scpt
|
125
128
|
- scripts/delete_extra_slides.scpt
|
126
129
|
- scripts/delete_slide.scpt
|
127
130
|
- scripts/insert_code_background.scpt
|
128
131
|
- scripts/insert_image.scpt
|
132
|
+
- scripts/paste_and_indent.scpt
|
129
133
|
- scripts/paste_clipboard.scpt
|
130
134
|
- scripts/slides_count.scpt
|
131
135
|
- scripts/update_slide.scpt
|
@@ -148,8 +152,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
152
|
version: '0'
|
149
153
|
requirements: []
|
150
154
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.4.5
|
155
|
+
rubygems_version: 2.4.5.1
|
152
156
|
signing_key:
|
153
157
|
specification_version: 4
|
154
158
|
summary: Convert markdown to keynote
|
155
159
|
test_files: []
|
160
|
+
has_rdoc:
|