Skip to content

Instantly share code, notes, and snippets.

@tobijibu
Last active March 29, 2017 04:18
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 tobijibu/4bf4d4cedff42a22ff78b779d3c6afe1 to your computer and use it in GitHub Desktop.
Save tobijibu/4bf4d4cedff42a22ff78b779d3c6afe1 to your computer and use it in GitHub Desktop.
" 変換対象文字指定
let s:replaceEntity = [
\ ['\(\(&\(#*\w\+;\)\@!\)\|&\|&\)', '\&'],
\ ['\(\"\|"\|"\)', '\"'],
\ ["\\('\\|'\\)", '\''],
\ ['\(<\|&lt;\|&#60;\)', '\&#x3C;'],
\ ['\(>\|&gt;\|&#62;\)', '\&#x3E;'],
\]
function! s:htmlesc() range
for l:line in range(a:firstline, a:lastline)
let l:_line = getline(l:line)
for l:replace in s:replaceEntity
let l:_line = substitute(l:_line, l:replace[0], l:replace[1], 'g')
endfor
call setline(l:line, l:_line)
endfor
endfunction
command! -range HtmlEsc <line1>, <line2> call s:htmlesc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment