Skip to content

Instantly share code, notes, and snippets.

@gpanders
Last active August 30, 2024 10:23
Show Gist options
  • Save gpanders/1df5cbfa8ae600cad306a086f6ae6d70 to your computer and use it in GitHub Desktop.
Save gpanders/1df5cbfa8ae600cad306a086f6ae6d70 to your computer and use it in GitHub Desktop.
Un-wrap Markdown links after processing with pandoc
setlocal formatprg=pandoc\ -f\ markdown\ -t\ markdown
setlocal formatexpr=ft#markdown#format()
function! ft#markdown#format()
" Only use this in normal mode to prevent automatic formatting being
" messed up in insert mode
if mode() !=# 'n'
return 1
endif
let lastsearch = @/
let start = v:lnum
let end = start + v:count - 1
let range = start . ',' . end
exe range . '!' . &l:formatprg
" Join wrapped links
exe range . 'g/\[[^]]*$/.,/\[\@<!]/j'
let @/ = lastsearch
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment