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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ba23c23006d361a3ac96773bce7d991f3f88650
4
- data.tar.gz: 2aec7cc849fb5186259a1eaadc8f0e57d28a6ee0
3
+ metadata.gz: 28d015849054d2a590b378c0cc9b2f264a512f2a
4
+ data.tar.gz: f8ee2819fc70e399307cb661714f361368eef24f
5
5
  SHA512:
6
- metadata.gz: 9dfa23a5c9ae95fb088d4ef0f59d7227875c92fa5b28411fa2c7fa05ce9500971e680f500c9b9b7d50c86fc75f6f4d42d8929d194a200496763e96ea7afd5099
7
- data.tar.gz: 1814b9ef6726259e240cdd0c8757c928fa9515d245ecac74559bfd1bf819e4fbe94842c2099b2bddff56e5b7fdab3c898d8b7b58c5b4c079a551fed029aa7f13
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
@@ -36,8 +36,6 @@ You can separate slides with `---` just for readability.
36
36
 
37
37
  ### Insert image
38
38
 
39
- <img src='https://i.gyazo.com/c9870e72ddf35a9dbd487fad4e6968bd.png' width='60%'>
40
-
41
39
  ```markdown
42
40
  # image slide
43
41
 
@@ -25,9 +25,9 @@ module Md2key
25
25
  end
26
26
 
27
27
  def generate_contents
28
- Keynote.update_cover(@markdown.cover.title, @markdown.cover.lines.join("\n"))
28
+ Keynote.update_cover(@markdown.cover)
29
29
  @markdown.slides.each_with_index do |slide, index|
30
- Keynote.create_slide(slide.title, slide.lines.join("\n"))
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
@@ -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
- def update_cover(title, content)
10
- execute_applescript('update_slide', title, content, COVER_SLIDE_INDEX)
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('" "')}"`
@@ -0,0 +1,12 @@
1
+ module Md2key
2
+ class Line < Struct.new(:text, :indent)
3
+ def initialize(*)
4
+ super
5
+ self.indent ||= 0
6
+ end
7
+
8
+ def indented?
9
+ indent > 0
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,7 @@
1
- require 'redcarpet'
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
- # FIXME: support nested list
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
- def li_texts(ul_node)
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
- texts = []
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
- texts << text unless text.empty?
89
+ lines << Line.new(text, indent) unless text.empty?
86
90
  when Oga::XML::Element
87
91
  next if node.name != 'ul'
88
- texts << li_texts(node)
92
+ lines.concat(li_lines(node, indent: indent + 1))
89
93
  end
90
94
  end
91
95
  end
92
- texts
96
+ lines
93
97
  end
94
98
 
95
99
  def to_xhtml(markdown)
@@ -0,0 +1,10 @@
1
+ module Md2key
2
+ class Pbcopy
3
+ def self.copy(str)
4
+ IO.popen('pbcopy', 'w') do |io|
5
+ io.write(str)
6
+ io.close_write
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Md2key
2
- VERSION = "0.4.4"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/md2key.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'md2key/code'
2
- require 'md2key/slide'
3
2
  require 'md2key/markdown'
4
3
  require 'md2key/highlight'
5
4
  require 'md2key/keynote'
@@ -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
@@ -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.4
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: 2015-08-25 00:00:00.000000000 Z
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/create_slide.scpt
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: