md2key 0.5.2 → 0.6.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: ee2b4a206c2e364066144e6078e33d3568249fb7
4
- data.tar.gz: db51f92d93466e01e6de76feffb63648351a96a5
3
+ metadata.gz: 3c7595398a53c91167545a3c662be59191368ce2
4
+ data.tar.gz: 3cd48b2fd10db287d216cc66763f42fbea4a6f74
5
5
  SHA512:
6
- metadata.gz: 1d7ca73cc1e3179ad8c2aa68a89cb50b8efd9c78d9ca2dc514559122398909b55647d301292dcb487097864a8631fc554d8e099e537c0f0ebf4dcc1b614af6e1
7
- data.tar.gz: 42da1d21e7f0583186b65f431cbf0ff11b25139b5b8f721a43ee8209d3d7af5b0e981ba29e86aa870290def24aa0981b5ee95c34201801392495a4cafe9af6d3
6
+ metadata.gz: c17ea6fe7f45fc60317e86686aa8045177df35c5ca1010581a8a1afd7dbcacd1d4a390a088da9ac8892bf73258c35229bc72507e2c391406e48eac23ed1814e1
7
+ data.tar.gz: 07ea02c224a2c633acc4b4c34e9bdc4e256f23bc6fe34d92ace3f9ee846f76babf7951d52dfa92dbfc513b210dc994d515150e66a2e3c7d56a1ee76bcca2e57c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v0.6.0
2
+
3
+ - Add table support
4
+ - https://github.com/k0kubun/md2key/pull/25
5
+ - Thanks to @codeant
6
+
1
7
  # v0.5.2
2
8
 
3
9
  - Use delay before paste to prevent pasting wrong text
@@ -27,9 +27,14 @@ module Md2key
27
27
  def generate_contents
28
28
  Keynote.update_cover(@markdown.cover)
29
29
  @markdown.slides.each_with_index do |slide, index|
30
- Keynote.create_slide(slide)
31
- Keynote.insert_image(slide.image) if slide.image
32
- Keynote.insert_code(slide.code) if slide.code
30
+ if slide.table
31
+ Keynote.create_slide_with_table(slide, slide.table.rows, slide.table.columns)
32
+ Keynote.insert_table(slide.table.data)
33
+ else
34
+ Keynote.create_slide(slide)
35
+ Keynote.insert_image(slide.image) if slide.image
36
+ Keynote.insert_code(slide.code) if slide.code
37
+ end
33
38
  end
34
39
  end
35
40
  end
@@ -7,17 +7,10 @@ module Md2key
7
7
 
8
8
  extension = code.extension || DEFAULT_EXTENSION
9
9
 
10
- file = Tempfile.new(["code", ".#{extension}"])
11
- file.write(code.source)
12
- file.close
13
-
14
- IO.popen(['highlight', '-O', 'rtf', '-K', '28', '-s', 'rdark', '-k', 'Monaco', file.path], 'r+') do |highlight|
15
- IO.popen('pbcopy', 'w+') do |pbcopy|
16
- pbcopy.write(highlight.read)
17
- end
10
+ IO.popen("highlight -O rtf -K 28 -s rdark -k Monaco -S #{extension} | pbcopy", 'w+') do |highlight|
11
+ highlight.write(code.source)
12
+ highlight.close
18
13
  end
19
- ensure
20
- file.delete
21
14
  end
22
15
 
23
16
  private
@@ -23,6 +23,11 @@ module Md2key
23
23
  end
24
24
  end
25
25
 
26
+ # @param [Md2key::Slide] slide
27
+ def create_slide_with_table(slide, rows, columns)
28
+ execute_applescript('create_slide_and_insert_table', slide.title, TEMPLATE_SLIDE_INDEX, rows, columns)
29
+ end
30
+
26
31
  def ensure_template_slide_availability
27
32
  return if slides_count >= 2
28
33
  execute_applescript('create_empty_slide')
@@ -49,6 +54,18 @@ module Md2key
49
54
  paste_clipboard
50
55
  end
51
56
 
57
+ def insert_table(data)
58
+ row_index = 1
59
+ data.each do |row|
60
+ param = [slides_count, row_index]
61
+ row.each do |cell|
62
+ param << cell
63
+ end
64
+ execute_applescript('update_table', *param)
65
+ row_index += 1
66
+ end
67
+ end
68
+
52
69
  private
53
70
 
54
71
  def insert_code_background
@@ -1,5 +1,6 @@
1
1
  require 'md2key/line'
2
2
  require 'md2key/slide'
3
+ require 'md2key/table'
3
4
  require 'oga'
4
5
  require 'redcarpet'
5
6
 
@@ -51,6 +52,34 @@ module Md2key
51
52
  slide.title = node.text
52
53
  when 'ul'
53
54
  slide.lines.concat(li_lines(node))
55
+ when 'ol'
56
+ slide.lines.concat(li_lines(node))
57
+ when 'table'
58
+ row_data = []
59
+ rows = 0
60
+ columns = 0
61
+ row_text = []
62
+ node.children[0].children.each do |child|
63
+ next if !child.is_a?(Oga::XML::Element) || child.name != 'tr'
64
+ rows += 1
65
+ child.children.each do |td|
66
+ next if !td.is_a?(Oga::XML::Element) || td.name != 'th'
67
+ columns += 1
68
+ row_text << td.text
69
+ end
70
+ end
71
+ row_data << row_text
72
+ node.children[1].children.each do |child|
73
+ next if !child.is_a?(Oga::XML::Element) || child.name != 'tr'
74
+ row_text = []
75
+ child.children.each do |td|
76
+ next if !td.is_a?(Oga::XML::Element) || td.name != 'td'
77
+ row_text << td.text
78
+ end
79
+ row_data << row_text
80
+ rows += 1
81
+ end
82
+ slide.table = Table.new(rows, columns, row_data)
54
83
  when 'p'
55
84
  node.children.each do |child|
56
85
  if child.is_a?(Oga::XML::Element) && child.name == 'img'
@@ -75,7 +104,7 @@ module Md2key
75
104
  # @return [Array<Md2Key::Line>]
76
105
  def li_lines(ul_node, indent: 0)
77
106
  return [] unless ul_node.is_a?(Oga::XML::Element)
78
- return [] if ul_node.name != 'ul'
107
+ return [] if ul_node.name != 'ul' && ul_node.name != 'ol'
79
108
 
80
109
  lines = []
81
110
  ul_node.children.each do |li_node|
@@ -101,7 +130,7 @@ module Md2key
101
130
  Redcarpet::Render::XHTML.new(
102
131
  escape_html: true,
103
132
  ),
104
- fenced_code_blocks: true,
133
+ fenced_code_blocks: true, :tables => true
105
134
  )
106
135
  redcarpet.render(markdown)
107
136
  end
data/lib/md2key/slide.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Md2key
2
- class Slide < Struct.new(:title, :lines, :image, :code)
2
+ class Slide < Struct.new(:title, :lines, :image, :code, :table)
3
3
  def initialize(*)
4
4
  super
5
5
  self.lines ||= []
@@ -0,0 +1,4 @@
1
+ module Md2key
2
+ class Table < Struct.new(:rows, :columns, :data)
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module Md2key
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -0,0 +1,29 @@
1
+ on run argv
2
+ set slideTitle to item 1 of argv
3
+ set templateIndex to item 2 of argv as number
4
+ set rowCount to item 3 of argv as number
5
+ set columnCount to item 4 of argv as number
6
+
7
+ set headerRowCount to 1
8
+ set headerColumnCount to 0
9
+ set footerRowCount to 0
10
+
11
+ tell application "Keynote"
12
+ set thisDocument to the front document
13
+ tell thisDocument
14
+ -- Workaround to select correct master slide. In spite of master slide can be selected by name,
15
+ -- name property is not limited to be unique.
16
+ -- So move the focus to second slide and force "make new slide" to use the exact master slide.
17
+ move slide templateIndex to before slide templateIndex
18
+
19
+ set newSlide to make new slide
20
+ tell newSlide
21
+ try
22
+ set base slide to master slide "Title - Top" of thisDocument
23
+ end try
24
+ set object text of default title item to slideTitle
25
+ set newTable to make new table with properties {column count:columnCount, row count:rowCount, footer row count:footerRowCount,header column count:headerColumnCount,header row count:headerRowCount}
26
+ end tell
27
+ end tell
28
+ end tell
29
+ end run
@@ -0,0 +1,22 @@
1
+ on run argv
2
+ set slideIndex to item 1 of argv as number
3
+ set rowIndex to item 2 of argv as number
4
+
5
+ tell application "Keynote"
6
+ tell the front document
7
+ tell slide slideIndex
8
+ set thisTable to the first table
9
+ tell thisTable
10
+ set idx to 1
11
+ repeat with i in items 3 thru end of argv
12
+ tell cell rowIndex of column idx
13
+ set value to i
14
+ set the font size to 12
15
+ end tell
16
+ set idx to idx + 1
17
+ end repeat
18
+ end tell
19
+ end tell
20
+ end tell
21
+ end tell
22
+ 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.5.2
4
+ version: 0.6.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: 2016-05-10 00:00:00.000000000 Z
11
+ date: 2016-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -119,10 +119,12 @@ files:
119
119
  - lib/md2key/markdown.rb
120
120
  - lib/md2key/pbcopy.rb
121
121
  - lib/md2key/slide.rb
122
+ - lib/md2key/table.rb
122
123
  - lib/md2key/version.rb
123
124
  - md2key.gemspec
124
125
  - scripts/activate_slide.scpt
125
126
  - scripts/create_empty_slide.scpt
127
+ - scripts/create_slide_and_insert_table.scpt
126
128
  - scripts/create_slide_and_select_body.scpt
127
129
  - scripts/create_slide_and_write_body.scpt
128
130
  - scripts/delete_extra_slides.scpt
@@ -133,6 +135,7 @@ files:
133
135
  - scripts/paste_clipboard.scpt
134
136
  - scripts/slides_count.scpt
135
137
  - scripts/update_slide.scpt
138
+ - scripts/update_table.scpt
136
139
  homepage: https://github.com/k0kubun/md2key
137
140
  licenses: []
138
141
  metadata: {}
@@ -157,4 +160,3 @@ signing_key:
157
160
  specification_version: 4
158
161
  summary: Convert markdown to keynote
159
162
  test_files: []
160
- has_rdoc: