Skip to content

Instantly share code, notes, and snippets.

@patdavid
Last active April 6, 2017 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patdavid/9bbc92be38248e119ade3be34b338f26 to your computer and use it in GitHub Desktop.
Save patdavid/9bbc92be38248e119ade3be34b338f26 to your computer and use it in GitHub Desktop.
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