Skip to content

Instantly share code, notes, and snippets.

@lachie
Created May 24, 2010 23:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lachie/412549 to your computer and use it in GitHub Desktop.
Save lachie/412549 to your computer and use it in GitHub Desktop.
" http://gist.github.com/gists/412549
"
" Paste syntax highlighted code into Keynote for presentational yum.
" by Lachie Cox
"
" put all this into your .vimrc
" (I might wrap it into a plugin one day)
"
" You could probably do the whole thing from vim, but I wanted to tweak to HTML
" a bit before pasting, so I pass the HTML to a ruby script (Gisted below)
"
" To paste the whole file
" :PasteKeynote
"
" or use a range or visual selection
" :5,10PasteKeynote
"
" Please note that I'm an utter vimscript newb. Tips and improvements are most welcome.
let g:paste_keynote_tmp = $HOME."/tmp/convert_from_vim.html"
let g:paste_keynote_rb = $HOME."/bin/paste_vim_to_keynote.rb"
command! -range=% PasteKeynote :call PasteToKeynote(<line1>, <line2>)
func! PasteToKeynote(line1, line2)
if a:line2 >= a:line1
let g:html_start_line = a:line1
let g:html_end_line = a:line2
else
let g:html_start_line = a:line2
let g:html_end_line = a:line1
endif
let g:html_use_css = 1
let x=&number
se nonumber
runtime syntax/2html.vim
unlet g:html_start_line
unlet g:html_end_line
unlet g:html_use_css
exe "wq!" g:paste_keynote_tmp
let ignorey = system(g:paste_keynote_rb . " " . g:paste_keynote_tmp)
let &number=x
endfunc
#!/usr/bin/env ruby
# http://gist.github.com/gists/412549
#
# Paste syntax highlighted code into Keynote for presentational yum.
# by Lachie Cox
#
# This is the companion ruby script to the vimscript part.
#
# put this somewhere and make it +x
# needs nokogiri
require 'pathname'
file = Pathname(ARGV[0]).expand_path
output = file.dirname + "#{file.basename('.html').to_s}_out.html"
applescript = %{
tell application "Safari"
activate
make new document at end of documents
set URL of document 1 to "#{output}"
tell application "System Events"
tell process "Safari"
click menu item "Select All" of menu "Edit" of menu bar 1
click menu item "Copy" of menu "Edit" of menu bar 1
end tell
end tell
close document 1
end tell
tell application "Keynote"
activate
tell application "System Events"
tell process "Keynote"
click menu item "New Slide" of menu "Slide" of menu bar 1
click menu item "Paste" of menu "Edit" of menu bar 1
end tell
end tell
end tell
}
require 'rubygems'
require 'nokogiri'
require 'pp'
doc = Nokogiri::HTML(file.read)
# tweak this for your preso
doc.css('html head style').first.content += "\nbody { font-family: Inconsolata; font-size: 18pt }"
output.open('w') {|f| doc.write_to(f)}
IO.popen("osascript -",'w') {|f| f << applescript}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment