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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 410568f3152ab6dcd1869b85bcfb8f2d9e68e1fd
4
- data.tar.gz: 2b4c816530181bd706316b94025ffbc1a2830eb5
3
+ metadata.gz: 9b9ec20ac32a06499a88da4a9f83bacd72e7bcf2
4
+ data.tar.gz: 7b580eb3962a9ca8bdfc7ff33a0290e5cf87c71a
5
5
  SHA512:
6
- metadata.gz: 5d5fa52861b324fd7653ad7144c7b76384efddd26a007fba6bcb33be197efb1c461de3dd595e747221f19a406b1206c9d840d7d7aa18693dda49ebc8358922ca
7
- data.tar.gz: e99f5e622a77540a4114045e231fea43c023241d631d06e698e3ae93d6f934221b10b9e462171d14089db0b9bfa3bfb702f5bb9eb334bce01374f953677fd8c0
6
+ metadata.gz: 0de8ca21415763465fe9b649e7820dbf4b102ea3f15867c8e79133e8ff371d4ed9c7c648cc7ae1120e78c1e083ddef4c5db6ca24f21a3b48f592ed9a9d3c3aa3
7
+ data.tar.gz: 6f0a3144ed5e84f142045707c4cd653bb034de04fc975acdbb294e8253a2058463c806cb52bcc81122fd70aa6ff4eda9c72384a8d4c5791c6d3c66b28351c4fc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.8.1
2
+
3
+ - Fix bug in converting nested list
4
+
1
5
  # v0.8.0
2
6
 
3
7
  - Add `md2key init` subcommand to generate .md2key
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
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
- config = Configuration.load
14
- Converter.new(config).convert!(path)
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'
@@ -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(config)
6
- @config = config
8
+ def initialize
9
+ @config = Configuration.load
7
10
  end
8
11
 
9
- def convert!(path)
12
+ # @param [Md2key::Nodes::Presentation] ast
13
+ def convert!(ast)
10
14
  prepare_document_base
11
- markdown = Markdown.new(path)
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(markdown)
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(markdown.cover, config.cover_master || cover_master)
29
- markdown.slides.each do |slide|
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)
@@ -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
- Pbcopy.copy(line.text)
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', '-e', script, *args.map(&:to_s)], &:read)
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)
@@ -0,0 +1,6 @@
1
+ module Md2key
2
+ module Nodes
3
+ class Code < Struct.new(:source, :extension)
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ module Md2key
2
+ module Nodes
3
+ class Line < Struct.new(:text, :indent)
4
+ def initialize(*)
5
+ super
6
+ self.indent ||= 0
7
+ end
8
+
9
+ def indented?
10
+ indent > 0
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ module Md2key
2
+ module Nodes
3
+ class Presentation < Struct.new(:cover, :slides)
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ module Md2key
2
+ module Nodes
3
+ class Slide < Struct.new(:title, :lines, :image, :code, :table, :note, :level)
4
+ def initialize(*)
5
+ super
6
+ self.lines ||= []
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module Md2key
2
+ module Nodes
3
+ class Table < Struct.new(:rows, :columns, :data)
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ require 'md2key/nodes/code'
2
+ require 'md2key/nodes/line'
3
+ require 'md2key/nodes/presentation'
4
+ require 'md2key/nodes/slide'
5
+ require 'md2key/nodes/table'
@@ -1,41 +1,28 @@
1
- require 'md2key/line'
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, generate AST and convert it to slides.
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 Markdown
12
- def initialize(path)
13
- markdown = File.read(path)
14
- xhtml = to_xhtml(markdown)
15
- @ast = Oga.parse_xml(xhtml)
16
- end
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 cached_slides
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
- @ast.children.each do |node|
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<Md2Key::Line>]
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, :tables => true
124
+ fenced_code_blocks: true, tables: true
138
125
  )
139
126
  redcarpet.render(markdown)
140
127
  end
@@ -1,3 +1,3 @@
1
1
  module Md2key
2
- VERSION = "0.8.0"
2
+ VERSION = '0.8.1'
3
3
  end
data/lib/md2key.rb CHANGED
@@ -1,5 +1 @@
1
- require 'md2key/code'
2
- require 'md2key/markdown'
3
- require 'md2key/highlight'
4
- require 'md2key/keynote'
5
1
  require 'md2key/cli'
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 = "md2key"
7
+ spec.name = 'md2key'
8
8
  spec.version = Md2key::VERSION
9
- spec.authors = ["Takashi Kokubun"]
10
- spec.email = ["takashi-kokubun@cookpad.com"]
9
+ spec.authors = ['Takashi Kokubun']
10
+ spec.email = ['takashikkbn@gmail.com']
11
11
 
12
- spec.summary = %q{Convert markdown to keynote}
13
- spec.description = %q{Convert markdown to keynote}
14
- spec.homepage = "https://github.com/k0kubun/md2key"
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 { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
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 "thor", "~> 0.19"
21
- spec.add_dependency "redcarpet", "~> 3.3"
22
- spec.add_dependency "oga", "~> 1.2"
23
- spec.add_development_dependency "bundler", "~> 1.10"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "pry"
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.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-04 00:00:00.000000000 Z
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.10'
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.10'
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
- - takashi-kokubun@cookpad.com
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/md2key
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/line.rb
122
- - lib/md2key/markdown.rb
123
- - lib/md2key/pbcopy.rb
124
- - lib/md2key/slide.rb
125
- - lib/md2key/table.rb
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
@@ -1,4 +0,0 @@
1
- module Md2key
2
- class Code < Struct.new(:source, :extension)
3
- end
4
- end
data/lib/md2key/line.rb DELETED
@@ -1,12 +0,0 @@
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
data/lib/md2key/pbcopy.rb DELETED
@@ -1,10 +0,0 @@
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
data/lib/md2key/slide.rb DELETED
@@ -1,8 +0,0 @@
1
- module Md2key
2
- class Slide < Struct.new(:title, :lines, :image, :code, :table, :note, :level)
3
- def initialize(*)
4
- super
5
- self.lines ||= []
6
- end
7
- end
8
- end
data/lib/md2key/table.rb DELETED
@@ -1,4 +0,0 @@
1
- module Md2key
2
- class Table < Struct.new(:rows, :columns, :data)
3
- end
4
- end