vimdeck 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'artii'
4
4
  gem 'asciiart'
5
+ gem 'redcarpet'
data/Gemfile.lock CHANGED
@@ -6,6 +6,7 @@ GEM
6
6
  rainbow
7
7
  rmagick
8
8
  rainbow (1.1.4)
9
+ redcarpet (2.2.2)
9
10
  rmagick (2.13.2)
10
11
 
11
12
  PLATFORMS
@@ -14,3 +15,4 @@ PLATFORMS
14
15
  DEPENDENCIES
15
16
  artii
16
17
  asciiart
18
+ redcarpet
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) [year] [fullname]
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,16 @@
1
- # vimdeck
1
+ # Vimdeck
2
2
 
3
3
  VIM as a presentation tool
4
4
 
5
5
 
6
+ ## News
7
+
8
+ Vimdeck now uses [redcarpet](http://github.com/vmg/redcarpet) to parse and render markdown!
9
+
10
+ I've cleaned up the code significantly. So those of you who like more features in Vimdeck
11
+ can fork and pull-request your buns off.
12
+
13
+
6
14
  ## Installation
7
15
 
8
16
  Install the vim plugin [SyntaxRange](https://github.com/vim-scripts/SyntaxRange).
@@ -25,6 +33,7 @@ Vimdeck will also provide a script file that will set up keybindings for you.
25
33
 
26
34
  - PageUp/Left go backwards
27
35
  - PageDown/Right go forward
36
+ - Q closes presentation
28
37
 
29
38
 
30
39
  ## A Note about VIM
@@ -56,8 +65,8 @@ Example:
56
65
  Is less important
57
66
  ```
58
67
 
59
- Vimdeck does not compile markdown into something else.
60
- It uses a very small subset of markdown. List of items supported:
68
+ Vimdeck uses redcarpet to parse its markdown and implements a custom renderer
69
+ for things like ascii art. It uses a very small subset of markdown. List of items supported:
61
70
 
62
71
  - h1s
63
72
  - h2s
@@ -73,7 +82,22 @@ Fenced code blocks look like this:
73
82
  this.is = 'code'
74
83
  ```
75
84
 
76
- # Why Ruby?
85
+ ## Highlighting Syntax
86
+
87
+ Vimdeck also supports "highlighting" parts of a slide. This is an experimental feature and needs more testing.
88
+
89
+ Use `{~ unimportant_text_here ~}` to "unhighlight" portions of a slide:
90
+
91
+ # Slide Title
92
+
93
+ {~- Unimportant bullet~}
94
+ - Important bullet
95
+ {~- Really unimportant bullet~}
96
+
97
+ This allows you to create multiple versions of the same slide but with different parts highlighted.
98
+ Which is something I like to use often when presenting code snippets.
99
+
100
+ ## Why Ruby?
77
101
 
78
102
  Additionally, I want to point out that I realize that it's odd to have a VIM-based tool
79
103
  and not write it as a VIM script. Ruby was my language of choice only because the ascii art dependencies
@@ -97,3 +121,10 @@ Vimdeck will also augment its vimscript to provide syntax highlighting
97
121
 
98
122
  Images are even converted to ascii art!
99
123
  ![](img/demo4.png)
124
+
125
+
126
+
127
+
128
+ ---------------------
129
+
130
+ Made by [tybenz](http://github.com/tybenz): [tybenz.com](http://tybenz.com) // [@tybenz](http://twitter.com/tybenz)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.1.0
data/bin/vimdeck CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'vimdeck'
4
4
 
5
- Vimdeck.slideshow(ARGV[0])
5
+ Vimdeck::Slideshow.start(ARGV[0])
@@ -1,7 +1,9 @@
1
+ set nonumber
1
2
  noremap <PageUp> :bp<CR>
2
3
  noremap <Left> :bp<CR>
3
4
  noremap <PageDown> :bn<CR>
4
5
  noremap <Right> :bn<CR>
6
+ noremap Q :q<CR>
5
7
 
6
8
  <% @buffers.each do |buffer| %>
7
9
  b <%= buffer[:num] %>
data/lib/vimdeck.rb CHANGED
@@ -1,120 +1,168 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'artii'
2
4
  require 'asciiart'
3
5
  require 'erb'
6
+ require 'redcarpet'
4
7
 
5
8
  module Vimdeck
6
- @slide_delimiter = "\n\n\n"
9
+ # Helper methods for ascii art conversion
10
+ class Ascii
11
+ def self.header(text, type)
12
+ if type == "large"
13
+ font = Artii::Base.new :font => 'slant'
14
+ else
15
+ font = Artii::Base.new :font => 'smslant'
16
+ end
7
17
 
8
- def self.artii(text, type)
9
- if type == "large"
10
- font = Artii::Base.new :font => 'slant'
11
- else
12
- font = Artii::Base.new :font => 'smslant'
18
+ font.asciify(text)
13
19
  end
14
20
 
15
- font.asciify(text)
21
+ def self.image(img)
22
+ a = AsciiArt.new(img)
23
+ a.to_ascii_art width: 30
24
+ end
16
25
  end
17
26
 
18
- def self.ascii_art(img)
19
- a = AsciiArt.new(img)
20
- a.to_ascii_art width: 30
21
- end
27
+ # Custom Redcarpet renderer handles headers and images
28
+ # Code blocks are ignored by the renderer because they have to be
29
+ # measured for the vimscript, so parsing of the fenced code blocks
30
+ # happens in the slideshow generator itself
31
+ class Render < Redcarpet::Render::Base
32
+ # Methods where the first argument is the text content
33
+ [
34
+ # block-level calls
35
+ :block_quote,
36
+ :block_html, :list, :list_item,
37
+
38
+ # span-level calls
39
+ :autolink, :codespan, :double_emphasis,
40
+ :emphasis, :underline, :raw_html,
41
+ :triple_emphasis, :strikethrough,
42
+ :superscript,
43
+
44
+ # footnotes
45
+ :footnotes, :footnote_def, :footnote_ref,
46
+
47
+ # low level rendering
48
+ :entity, :normal_text
49
+ ].each do |method|
50
+ define_method method do |*args|
51
+ args.first
52
+ end
53
+ end
54
+
55
+ def header(title, level)
56
+ case level
57
+ when 1
58
+ Vimdeck::Ascii.header(title, "large") + "\n"
59
+
60
+ when 2
61
+ Vimdeck::Ascii.header(title, "small") + "\n"
62
+ end
63
+ end
64
+
65
+ def link(link, title, content)
66
+ content
67
+ end
68
+
69
+ def paragraph(text)
70
+ text + "\n"
71
+ end
72
+
73
+ def block_code(code, language)
74
+ "```#{language}\n#{code}\n```"
75
+ end
22
76
 
23
- def self.script_template
24
- @template.result(binding)
77
+ def image(image, title, alt_text)
78
+ Vimdeck::Ascii.image(image)
79
+ end
25
80
  end
26
81
 
27
- def self.create_slides(file)
28
- slides = File.read(file).split(@slide_delimiter)
29
-
30
- @template = ERB.new(File.read(File.dirname(__FILE__) + "/templates/script.vim.erb"))
31
- @buffers = []
32
-
33
- Dir.mkdir("presentation") unless File.exists?("presentation")
34
-
35
- slides.each_with_index do |slide, i|
36
- code_block = false
37
-
38
- slide.each_line do |line|
39
- match = line.match( /```(.*)$/ )
40
- if !code_block && match && match[1]
41
- code_block = true
42
- elsif code_block && line.match( /```/ )
43
- code_block=false
44
- elsif !code_block
45
- match = line.match( /##\s*(.*)/ )
46
- if match && match[1]
47
- slide.sub!( match[0], artii(match[1], "small") )
48
- else
49
- match = line.match( /#\s*(.*)/ )
50
- if match && match[1]
51
- slide.sub!( match[0], artii(match[1], "large") )
52
- else
53
- match = line.match( /\!\[\]\(([^\(\)]*)\)/ )
54
- if match && match[1]
55
- slide.sub!(match[0], self.ascii_art(match[1]))
56
- end
57
- end
82
+ class Slideshow
83
+ def self.slide_padding
84
+ " "
85
+ end
86
+
87
+ def self.script_template
88
+ template = ERB.new(File.read(File.dirname(__FILE__) + "/templates/script.vim.erb"))
89
+ template.result(binding)
90
+ end
91
+
92
+ def self.generate(filename)
93
+ slides = File.read(filename)
94
+
95
+ renderer = Redcarpet::Markdown.new(Vimdeck::Render, :fenced_code_blocks => true)
96
+ Dir.mkdir("presentation") unless File.exists?("presentation")
97
+ @buffers = []
98
+
99
+ # Slide separator is 3 newlines
100
+ slides = slides.split("\n\n\n")
101
+ i = 0
102
+ slides.each do |slide|
103
+ # Pad file names with zeros. e.g. slide001.md, slide023.md, etc.
104
+ slide_num = "%03d" % (i+1)
105
+ slide = renderer.render(slide)
106
+
107
+ # buffer gets stashed into @buffers array for script template
108
+ # needs to track things like the buffer number, code highlighting
109
+ # and focus/unfocus stuff
110
+ buffer = {:num => i + 1}
111
+ code_height = 0
112
+ code = nil
113
+ code = slide.match( /```([^\n]*)\n.*\n```/m )
114
+ if code
115
+ buffer[:code] = { :language => code[1] }
116
+ code_height = code[0].split("\n").length - 2
117
+ code = code[0].gsub( /```[^\n]*\n/, '' ).gsub( /\n```/, '' )
118
+ slide = slide.gsub( /```[^\n]*\n/, '' ).gsub( /\n```/, '' )
119
+
120
+ if code_height > 0
121
+ start = slide.index(code)
122
+ start = slide[0..start].split("\n").length
123
+ buffer[:code][:end] = code_height + start - 1
124
+ buffer[:code][:start] = start
58
125
  end
59
126
  end
60
- end
61
127
 
62
- buffer = {:num => i + 1}
63
- code_height = 0
64
- code = nil
65
- code = slide.match( /```([^\n]*)\n.*\n```/m )
66
- if code
67
- buffer[:code] = { :language => code[1] }
68
- code_height = code[0].split("\n").length - 2
69
- code = code[0].gsub( /```[^\n]*\n/, '' ).gsub( /\n```/, '' )
70
- slide = slide.gsub( /```[^\n]*\n/, '' ).gsub( /\n```/, '' )
71
-
72
- if code_height > 0
73
- start = slide.index(code)
74
- start = slide[0..start].split("\n").length
75
- buffer[:code][:end] = code_height + start - 1
76
- buffer[:code][:start] = start
128
+ # Prepending each line with slide_padding
129
+ # Removing trailing spaces
130
+ # Add newlines at end of the file to hide the slide identifier
131
+ slide = slide_padding + slide.gsub( /\n/, "\n#{slide_padding}" ).gsub( / *$/, "" ) + ("\n" * 80) + "slide #{i+1}"
132
+
133
+ # Buffers comments refers to items that need to be less focused/"unhighlighted"
134
+ # We add a regex to the vimscript for each slide with "comments"
135
+ # We use the hidden slide identifier to differentiate between slides
136
+ regex = /\{\~(.*?)\~\}/m
137
+ match = slide.match(regex)
138
+ buffer[:comments] = []
139
+ while match && match[1] && match.post_match do
140
+ slide.sub!(regex, match[1])
141
+ pattern = match[1] + "||(||_.*slide #{i+1}||)||@="
142
+ buffer[:comments] << pattern.gsub(/\n/, "||n").gsub(/\[/, "||[").gsub(/\]/, "||]").gsub(/\|/, "\\").gsub(/\"/, "\\\"")
143
+ match = match.post_match.match(regex)
77
144
  end
78
- end
79
145
 
80
- slide += "\n" * 80
81
- slide += "slide #{i+1}"
82
-
83
- spaces = " "
84
- slide = slide.gsub( /\n/, "\n#{spaces}" )
85
- slide = spaces + slide
86
- slide = slide.gsub( / *\n/, "\n" ).gsub( / *$/, '' )
87
-
88
- regex = /\{\~(.*?)\~\}/m
89
- match = slide.match(regex)
90
- buffer[:comments] = []
91
- while match && match[1] && match.post_match do
92
- slide.sub!(regex, match[1])
93
- pattern = match[1] + "||(||_.*slide #{i+1}||)||@="
94
- buffer[:comments] << pattern.gsub(/\n/, "||n").gsub(/\[/, "||[").gsub(/\]/, "||]").gsub(/\|/, "\\").gsub(/\"/, "\\\"")
95
- match = match.post_match.match(regex)
96
- end
97
-
98
- filenum = "%03d" % (i+1)
146
+ File.open("presentation/slide#{slide_num}.md", "w") do |file|
147
+ file.write slide
148
+ end
99
149
 
100
- File.open("presentation/slide#{filenum}.md", "w") do |file|
101
- file.write slide
150
+ @buffers << buffer
151
+ i += 1
102
152
  end
103
153
 
104
- @buffers << buffer
154
+ File.open("presentation/script.vim", "w") do |file|
155
+ file.write script_template
156
+ end
105
157
  end
106
158
 
107
- File.open("presentation/script.vim", "w") do |file|
108
- file.write script_template
159
+ def self.open
160
+ exec 'vim presentation/*.md -S presentation/script.vim'
109
161
  end
110
- end
111
162
 
112
- def self.open_vim
113
- exec 'vim presentation/*.md -S presentation/script.vim'
114
- end
115
-
116
- def self.slideshow(file)
117
- create_slides(file)
118
- open_vim
163
+ def self.start(filename)
164
+ generate(filename)
165
+ open
166
+ end
119
167
  end
120
168
  end
@@ -0,0 +1,111 @@
1
+ set nonumber
2
+ noremap <PageUp> :bp<CR>
3
+ noremap <Left> :bp<CR>
4
+ noremap <PageDown> :bn<CR>
5
+ noremap <Right> :bn<CR>
6
+ noremap Q :q<CR>
7
+
8
+
9
+ b 1
10
+
11
+
12
+
13
+ b 2
14
+
15
+
16
+
17
+ b 3
18
+
19
+
20
+
21
+ b 4
22
+
23
+
24
+ call matchadd("Comment", "• Second\\n • Third\\(\\_.*slide 4\\)\\@=")
25
+
26
+
27
+ b 5
28
+
29
+
30
+ call matchadd("Comment", "• First\\(\\_.*slide 5\\)\\@=")
31
+
32
+ call matchadd("Comment", "• Third\\(\\_.*slide 5\\)\\@=")
33
+
34
+
35
+ b 6
36
+
37
+
38
+ call matchadd("Comment", "• First\\n • Second\\(\\_.*slide 6\\)\\@=")
39
+
40
+
41
+ b 7
42
+
43
+ 6,17SyntaxInclude ruby
44
+
45
+
46
+
47
+ b 8
48
+
49
+ 6,17SyntaxInclude ruby
50
+
51
+
52
+ call matchadd("Comment", "module Parts\\n class foo\\n def slide\\n \"of a\"\\n end\\n\\n def can\\n highlight = \\(\\_.*slide 8\\)\\@=")
53
+
54
+ call matchadd("Comment", "\\n end\\n end\\n end\\(\\_.*slide 8\\)\\@=")
55
+
56
+
57
+ b 9
58
+
59
+ 6,17SyntaxInclude ruby
60
+
61
+
62
+ call matchadd("Comment", "module Parts\\n class foo\\n def slide\\n \"of a\"\\n end\\n\\n def\\(\\_.*slide 9\\)\\@=")
63
+
64
+ call matchadd("Comment", "highlight = \"vimdeck\"\\n end\\n end\\n end\\(\\_.*slide 9\\)\\@=")
65
+
66
+
67
+ b 10
68
+
69
+ 6,17SyntaxInclude ruby
70
+
71
+
72
+ call matchadd("Comment", "module Parts\\n class foo\\n def slide\\n \"of a\"\\n end\\n\\n def can\\(\\_.*slide 10\\)\\@=")
73
+
74
+ call matchadd("Comment", "= \"vimdeck\"\\n end\\n end\\n end\\(\\_.*slide 10\\)\\@=")
75
+
76
+
77
+ b 11
78
+
79
+ 6,17SyntaxInclude ruby
80
+
81
+
82
+ call matchadd("Comment", "module\\(\\_.*slide 11\\)\\@=")
83
+
84
+ call matchadd("Comment", "class foo\\n def slide\\n \"of a\"\\n end\\n\\n def can\\n highlight = \"vimdeck\"\\n end\\n end\\n end\\(\\_.*slide 11\\)\\@=")
85
+
86
+
87
+ b 12
88
+
89
+ 6,17SyntaxInclude ruby
90
+
91
+
92
+ call matchadd("Comment", "module Parts\\n class foo\\n def slide\\(\\_.*slide 12\\)\\@=")
93
+
94
+ call matchadd("Comment", "end\\n\\n def can\\n highlight = \"vimdeck\"\\n end\\n end\\n end\\(\\_.*slide 12\\)\\@=")
95
+
96
+
97
+ b 13
98
+
99
+ 6,17SyntaxInclude ruby
100
+
101
+
102
+ call matchadd("Comment", "module Parts\\n class foo\\n def\\(\\_.*slide 13\\)\\@=")
103
+
104
+ call matchadd("Comment", "\"of a\"\\n end\\n\\n def can\\n highlight = \"vimdeck\"\\n end\\n end\\n end\\(\\_.*slide 13\\)\\@=")
105
+
106
+
107
+ b 14
108
+
109
+
110
+
111
+ b 1
@@ -0,0 +1,92 @@
1
+ _ ________ _______ ______________ __
2
+ | | / / _/ |/ / __ \/ ____/ ____/ //_/
3
+ | | / // // /|_/ / / / / __/ / / / ,<
4
+ | |/ // // / / / /_/ / /___/ /___/ /| |
5
+ |___/___/_/ /_/_____/_____/\____/_/ |_|
6
+
7
+ ___ __ _____ ____ ___ _ ______________ __ _______
8
+ / _ \/ / / / _ \/ __/ / _ | | /| / / __/ __/ __ \/ |/ / __/
9
+ / ___/ /_/ / , _/ _/ / __ | |/ |/ / _/_\ \/ /_/ / /|_/ / _/
10
+ /_/ \____/_/|_/___/ /_/ |_|__/|__/___/___/\____/_/ /_/___/
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+ slide 1