Created
August 7, 2014 12:53
-
-
Save hail2u/231ae6d3c7e87acccba6 to your computer and use it in GitHub Desktop.
カーソル下のパスをData URIに変換するVimスクリプト。通常はbase64だが、SVGだけSVGOを使ってURLエンコードする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var fs = require('fs'); | |
var mime = require('mime'); | |
var file = process.argv.slice(2)[0]; | |
fs.readFile(file, function (error, data) { | |
if (error) { | |
throw error; | |
} | |
var datauri = 'data:' + mime.lookup(file) + ';base64,' + new Buffer(data).toString('base64'); | |
process.stdout.write(datauri); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Convert a file under a cursor to Data URI | |
function! s:ConvertCFileToDataURI() | |
let cfile = expand('<cfile>') | |
let command = '' | |
if matchend(cfile, '\.svg') == strlen(cfile) | |
let command = 'svgo --datauri=enc -o - -i ' | |
else | |
let command = 'datauri ' | |
endif | |
let @d = substitute(getline('.'), cfile, system(command . cfile), '') | |
normal! V"dp | |
endfunction | |
command! DataURI call <SID>ConvertCFileToDataURI() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment