md2key 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/LICENSE.txt +21 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/{bin → exe}/md2key +0 -0
- data/lib/md2key/cli.rb +4 -3
- data/lib/md2key/converter.rb +11 -8
- data/lib/md2key/keynote.rb +19 -8
- data/lib/md2key/nodes/code.rb +6 -0
- data/lib/md2key/nodes/line.rb +14 -0
- data/lib/md2key/nodes/presentation.rb +6 -0
- data/lib/md2key/nodes/slide.rb +10 -0
- data/lib/md2key/nodes/table.rb +6 -0
- data/lib/md2key/nodes.rb +5 -0
- data/lib/md2key/{markdown.rb → parser.rb} +21 -34
- data/lib/md2key/version.rb +1 -1
- data/lib/md2key.rb +0 -4
- data/md2key.gemspec +19 -15
- metadata +19 -14
- data/lib/md2key/code.rb +0 -4
- data/lib/md2key/line.rb +0 -12
- data/lib/md2key/pbcopy.rb +0 -10
- data/lib/md2key/slide.rb +0 -8
- data/lib/md2key/table.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b9ec20ac32a06499a88da4a9f83bacd72e7bcf2
|
4
|
+
data.tar.gz: 7b580eb3962a9ca8bdfc7ff33a0290e5cf87c71a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0de8ca21415763465fe9b649e7820dbf4b102ea3f15867c8e79133e8ff371d4ed9c7c648cc7ae1120e78c1e083ddef4c5db6ca24f21a3b48f592ed9a9d3c3aa3
|
7
|
+
data.tar.gz: 6f0a3144ed5e84f142045707c4cd653bb034de04fc975acdbb294e8253a2058463c806cb52bcc81122fd70aa6ff4eda9c72384a8d4c5791c6d3c66b28351c4fc
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Takashi Kokubun
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "md2key"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
data/{bin → exe}/md2key
RENAMED
File without changes
|
data/lib/md2key/cli.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'md2key/config_builder'
|
2
|
-
require 'md2key/configuration'
|
3
2
|
require 'md2key/converter'
|
3
|
+
require 'md2key/parser'
|
4
4
|
require 'thor'
|
5
5
|
require 'yaml'
|
6
6
|
|
@@ -10,8 +10,9 @@ module Md2key
|
|
10
10
|
def convert(path)
|
11
11
|
abort "md2key: `#{path}` does not exist" unless File.exist?(path)
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
markdown = File.read(path)
|
14
|
+
ast = Parser.new.parse(markdown)
|
15
|
+
Converter.new.convert!(ast)
|
15
16
|
end
|
16
17
|
|
17
18
|
desc 'init', 'Put .md2key template to current directory'
|
data/lib/md2key/converter.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
+
require 'md2key/configuration'
|
2
|
+
require 'md2key/keynote'
|
3
|
+
|
1
4
|
module Md2key
|
2
5
|
class Converter
|
3
6
|
attr_reader :config
|
4
7
|
|
5
|
-
def initialize
|
6
|
-
@config =
|
8
|
+
def initialize
|
9
|
+
@config = Configuration.load
|
7
10
|
end
|
8
11
|
|
9
|
-
|
12
|
+
# @param [Md2key::Nodes::Presentation] ast
|
13
|
+
def convert!(ast)
|
10
14
|
prepare_document_base
|
11
|
-
|
12
|
-
generate_contents(markdown)
|
15
|
+
generate_contents(ast)
|
13
16
|
ensure
|
14
17
|
Keynote.delete_template_slide
|
15
18
|
end
|
@@ -21,12 +24,12 @@ module Md2key
|
|
21
24
|
Keynote.delete_extra_slides
|
22
25
|
end
|
23
26
|
|
24
|
-
def generate_contents(
|
27
|
+
def generate_contents(ast)
|
25
28
|
cover_master = Keynote.fetch_master_slide_name(1)
|
26
29
|
main_master = Keynote.fetch_master_slide_name(2)
|
27
30
|
|
28
|
-
Keynote.update_cover(
|
29
|
-
|
31
|
+
Keynote.update_cover(ast.cover, config.cover_master || cover_master)
|
32
|
+
ast.slides.each do |slide|
|
30
33
|
master = config.slide_master(slide.level) || main_master
|
31
34
|
if slide.table
|
32
35
|
Keynote.create_slide_with_table(slide, slide.table.rows, slide.table.columns, master)
|
data/lib/md2key/keynote.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'md2key/pbcopy'
|
2
|
-
require 'md2key/diagram'
|
3
1
|
require 'erb'
|
2
|
+
require 'md2key/diagram'
|
3
|
+
require 'md2key/highlight'
|
4
4
|
|
5
5
|
module Md2key
|
6
6
|
class Keynote
|
@@ -10,12 +10,12 @@ module Md2key
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
# You must provide a first slide as a cover slide.
|
13
|
-
# @param [Md2key::Slide] slide
|
13
|
+
# @param [Md2key::Nodes::Slide] slide
|
14
14
|
def update_cover(slide, master_name)
|
15
15
|
execute_applescript('update_slide', slide.title, slide.lines.map(&:text).join("\n"), master_name, COVER_SLIDE_INDEX)
|
16
16
|
end
|
17
17
|
|
18
|
-
# @param [Md2key::Slide] slide
|
18
|
+
# @param [Md2key::Nodes::Slide] slide
|
19
19
|
# @param [String] master_name
|
20
20
|
def create_slide(slide, master_name)
|
21
21
|
if slide.lines.any?(&:indented?)
|
@@ -26,7 +26,7 @@ module Md2key
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
# @param [Md2key::Slide] slide
|
29
|
+
# @param [Md2key::Nodes::Slide] slide
|
30
30
|
def create_slide_with_table(slide, rows, columns, master_name)
|
31
31
|
execute_applescript('create_slide_and_insert_table', slide.title, TEMPLATE_SLIDE_INDEX, rows, columns, master_name)
|
32
32
|
end
|
@@ -117,7 +117,7 @@ module Md2key
|
|
117
117
|
execute_applescript('slides_count').to_i
|
118
118
|
end
|
119
119
|
|
120
|
-
# @param [Md2key::Slide] slide
|
120
|
+
# @param [Md2key::Nodes::Slide] slide
|
121
121
|
# @param [String] master_name
|
122
122
|
def create_indented_slide(slide, master_name)
|
123
123
|
execute_applescript('create_slide_and_select_body', slide.title, master_name, TEMPLATE_SLIDE_INDEX)
|
@@ -126,12 +126,19 @@ module Md2key
|
|
126
126
|
current_indent = 0
|
127
127
|
slide.lines.each_with_index do |line, index|
|
128
128
|
# Using copy and paste to input multibyte chars
|
129
|
-
|
129
|
+
pbcopy(line.text)
|
130
130
|
paste_and_indent(line.indent - current_indent, insert_newline: index < last_index)
|
131
131
|
current_indent = line.indent
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
def pbcopy(str)
|
136
|
+
IO.popen('pbcopy', 'w') do |io|
|
137
|
+
io.write(str)
|
138
|
+
io.close_write
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
135
142
|
def paste_and_indent(indent, insert_newline: true)
|
136
143
|
execute_applescript('paste_and_indent', indent, insert_newline)
|
137
144
|
end
|
@@ -140,7 +147,11 @@ module Md2key
|
|
140
147
|
def execute_applescript(script_name, *args)
|
141
148
|
path = script_path(script_name)
|
142
149
|
script = ERB.new(File.read(path)).result
|
143
|
-
IO.popen(['osascript', '-
|
150
|
+
IO.popen(['osascript', '-', *args.map(&:to_s)], 'r+') do |io|
|
151
|
+
io.write(script)
|
152
|
+
io.close_write
|
153
|
+
io.read
|
154
|
+
end
|
144
155
|
end
|
145
156
|
|
146
157
|
def script_path(script_name)
|
data/lib/md2key/nodes.rb
ADDED
@@ -1,41 +1,28 @@
|
|
1
|
-
require 'md2key/
|
2
|
-
require 'md2key/slide'
|
3
|
-
require 'md2key/table'
|
1
|
+
require 'md2key/nodes'
|
4
2
|
require 'oga'
|
5
3
|
require 'redcarpet'
|
6
4
|
|
7
|
-
# Parse markdown
|
8
|
-
# This is created to be compatible with Deckset.
|
5
|
+
# Parse markdown and generate AST.
|
6
|
+
# This is created to be compatible with Deckset as far as possible.
|
9
7
|
# See: http://www.decksetapp.com/cheatsheet/
|
10
8
|
module Md2key
|
11
|
-
class
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# @return [Md2key::Slide]
|
19
|
-
def cover
|
20
|
-
cached_slides.first
|
21
|
-
end
|
22
|
-
|
23
|
-
# @return [Array<Md2key::Slide>]
|
24
|
-
def slides
|
25
|
-
cached_slides[1..-1]
|
9
|
+
class Parser
|
10
|
+
# @param [String] markdown
|
11
|
+
# @return [Md2key::Nodes::Presentation] ast
|
12
|
+
def parse(markdown)
|
13
|
+
slides = parse_slides(markdown)
|
14
|
+
cover = slides.delete_at(0)
|
15
|
+
Nodes::Presentation.new(cover, slides)
|
26
16
|
end
|
27
17
|
|
28
18
|
private
|
29
19
|
|
30
|
-
def
|
31
|
-
@cached_slides ||= generate_slides
|
32
|
-
end
|
33
|
-
|
34
|
-
def generate_slides
|
20
|
+
def parse_slides(markdown)
|
35
21
|
slides = []
|
36
|
-
slide = Slide.new
|
22
|
+
slide = Nodes::Slide.new
|
37
23
|
|
38
|
-
|
24
|
+
html_nodes = Oga.parse_xml(to_xhtml(markdown))
|
25
|
+
html_nodes.children.each do |node|
|
39
26
|
next unless node.is_a?(Oga::XML::Element)
|
40
27
|
|
41
28
|
case node.name
|
@@ -45,7 +32,7 @@ module Md2key
|
|
45
32
|
# more compatibility with Deckset.
|
46
33
|
# See: https://github.com/k0kubun/md2key/pull/2
|
47
34
|
if slides.any?
|
48
|
-
slide = Slide.new
|
35
|
+
slide = Nodes::Slide.new
|
49
36
|
end
|
50
37
|
|
51
38
|
slides << slide
|
@@ -80,7 +67,7 @@ module Md2key
|
|
80
67
|
row_data << row_text
|
81
68
|
rows += 1
|
82
69
|
end
|
83
|
-
slide.table = Table.new(rows, columns, row_data)
|
70
|
+
slide.table = Nodes::Table.new(rows, columns, row_data)
|
84
71
|
when 'p'
|
85
72
|
node.children.each do |child|
|
86
73
|
if child.is_a?(Oga::XML::Element) && child.name == 'img'
|
@@ -90,13 +77,13 @@ module Md2key
|
|
90
77
|
slide.note = child.text.sub(/^\^ /, '')
|
91
78
|
next
|
92
79
|
end
|
93
|
-
slide.lines << Line.new(child.text)
|
80
|
+
slide.lines << Nodes::Line.new(child.text)
|
94
81
|
end
|
95
82
|
when 'pre'
|
96
83
|
node.children.each do |child|
|
97
84
|
next if !child.is_a?(Oga::XML::Element) || child.name != 'code'
|
98
85
|
extension = child.attribute('class') ? child.attribute('class').value : nil
|
99
|
-
slide.code = Code.new(child.text, extension)
|
86
|
+
slide.code = Nodes::Code.new(child.text, extension)
|
100
87
|
end
|
101
88
|
when 'hr'
|
102
89
|
# noop
|
@@ -105,7 +92,7 @@ module Md2key
|
|
105
92
|
slides
|
106
93
|
end
|
107
94
|
|
108
|
-
# @return [Array<
|
95
|
+
# @return [Array<Md2key::Nodes::Line>]
|
109
96
|
def li_lines(ul_node, indent: 0)
|
110
97
|
return [] unless ul_node.is_a?(Oga::XML::Element)
|
111
98
|
return [] if ul_node.name != 'ul' && ul_node.name != 'ol'
|
@@ -119,7 +106,7 @@ module Md2key
|
|
119
106
|
case node
|
120
107
|
when Oga::XML::Text
|
121
108
|
text = node.text.strip
|
122
|
-
lines << Line.new(text, indent) unless text.empty?
|
109
|
+
lines << Nodes::Line.new(text, indent) unless text.empty?
|
123
110
|
when Oga::XML::Element
|
124
111
|
next if node.name != 'ul'
|
125
112
|
lines.concat(li_lines(node, indent: indent + 1))
|
@@ -134,7 +121,7 @@ module Md2key
|
|
134
121
|
Redcarpet::Render::XHTML.new(
|
135
122
|
escape_html: true,
|
136
123
|
),
|
137
|
-
fenced_code_blocks: true, :
|
124
|
+
fenced_code_blocks: true, tables: true
|
138
125
|
)
|
139
126
|
redcarpet.render(markdown)
|
140
127
|
end
|
data/lib/md2key/version.rb
CHANGED
data/lib/md2key.rb
CHANGED
data/md2key.gemspec
CHANGED
@@ -4,23 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'md2key/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'md2key'
|
8
8
|
spec.version = Md2key::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Takashi Kokubun']
|
10
|
+
spec.email = ['takashikkbn@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
12
|
+
spec.summary = 'Convert markdown to keynote'
|
13
|
+
spec.description = 'Convert markdown to keynote'
|
14
|
+
spec.homepage = 'https://github.com/k0kubun/md2key'
|
15
|
+
spec.license = 'MIT'
|
15
16
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject
|
17
|
-
|
18
|
-
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
19
23
|
|
20
|
-
spec.add_dependency
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
24
|
+
spec.add_dependency 'thor', '~> 0.19'
|
25
|
+
spec.add_dependency 'redcarpet', '~> 3.3'
|
26
|
+
spec.add_dependency 'oga', '~> 1.2'
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'pry'
|
26
30
|
end
|
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.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
61
|
+
version: '1.12'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
68
|
+
version: '1.12'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,7 +96,7 @@ dependencies:
|
|
96
96
|
version: '0'
|
97
97
|
description: Convert markdown to keynote
|
98
98
|
email:
|
99
|
-
-
|
99
|
+
- takashikkbn@gmail.com
|
100
100
|
executables:
|
101
101
|
- md2key
|
102
102
|
extensions: []
|
@@ -105,24 +105,28 @@ files:
|
|
105
105
|
- ".gitignore"
|
106
106
|
- CHANGELOG.md
|
107
107
|
- Gemfile
|
108
|
+
- LICENSE.txt
|
108
109
|
- README.md
|
109
110
|
- Rakefile
|
110
111
|
- assets/background.png
|
111
|
-
- bin/
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- exe/md2key
|
112
115
|
- lib/md2key.rb
|
113
116
|
- lib/md2key/cli.rb
|
114
|
-
- lib/md2key/code.rb
|
115
117
|
- lib/md2key/config_builder.rb
|
116
118
|
- lib/md2key/configuration.rb
|
117
119
|
- lib/md2key/converter.rb
|
118
120
|
- lib/md2key/diagram.rb
|
119
121
|
- lib/md2key/highlight.rb
|
120
122
|
- lib/md2key/keynote.rb
|
121
|
-
- lib/md2key/
|
122
|
-
- lib/md2key/
|
123
|
-
- lib/md2key/
|
124
|
-
- lib/md2key/
|
125
|
-
- lib/md2key/
|
123
|
+
- lib/md2key/nodes.rb
|
124
|
+
- lib/md2key/nodes/code.rb
|
125
|
+
- lib/md2key/nodes/line.rb
|
126
|
+
- lib/md2key/nodes/presentation.rb
|
127
|
+
- lib/md2key/nodes/slide.rb
|
128
|
+
- lib/md2key/nodes/table.rb
|
129
|
+
- lib/md2key/parser.rb
|
126
130
|
- lib/md2key/version.rb
|
127
131
|
- md2key.gemspec
|
128
132
|
- scripts/activate_slide.scpt.erb
|
@@ -143,7 +147,8 @@ files:
|
|
143
147
|
- scripts/update_slide.scpt.erb
|
144
148
|
- scripts/update_table.scpt.erb
|
145
149
|
homepage: https://github.com/k0kubun/md2key
|
146
|
-
licenses:
|
150
|
+
licenses:
|
151
|
+
- MIT
|
147
152
|
metadata: {}
|
148
153
|
post_install_message:
|
149
154
|
rdoc_options: []
|
data/lib/md2key/code.rb
DELETED
data/lib/md2key/line.rb
DELETED
data/lib/md2key/pbcopy.rb
DELETED
data/lib/md2key/slide.rb
DELETED
data/lib/md2key/table.rb
DELETED