Last active
April 6, 2017 18:01
-
-
Save patdavid/9bbc92be38248e119ade3be34b338f26 to your computer and use it in GitHub Desktop.
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
function! ImgAttr() | |
" echo @" | |
" "normal "kyi' | |
" let tmp = @" | |
" let p = expand("%:p:h") | |
" let fullp = p .'/'. tmp | |
" "echo fullp | |
" let theWH=substitute(system('magick identify -format %wx%h "'.fullp.'"'),'\n','','') | |
" "let theData=substitute(theWH,'\([0-9]*\)x\([0-9]*\)', ' width="\1" height="\2" ','') | |
" let @y=substitute(theWH,'\([0-9]*\)x\([0-9]*\)', 'width="\1" height="\2" ','') | |
" "echo theWH | |
" "echo theData | |
" normal f "yp | |
" "startinsert | |
" "normal "yp | |
" Put cursor inside <img> tag somewhere, :call ImgAttr() | |
" yank everything inside bracket (hopefully <img ....>) | |
normal yi< | |
"echo @" | |
let filename=substitute(@",'.*src=[''"]\(.\{-}\)[''"] .*', '\1','') | |
"echo filename | |
let fullp = expand("%:p:h") .'/'. filename | |
"echo fullp | |
if @" !~ 'width' | |
"echo 'got no width' | |
let theWH=substitute(system('magick identify -format %wx%h "'.fullp.'"'),'\n','','') | |
let @y=substitute(theWH,'\([0-9]*\)x\([0-9]*\)', 'width="\1" height="\2" ','') | |
let @k=substitute(@", '\(src=[''"].\{-}[''"] \)', '\1' . @y,'') | |
"echo @k | |
normal vi<"kp | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment